From 195ea8d1af2745228c8d4a5c893ae0c8e27ba96c Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Thu, 17 May 2012 06:14:34 +0000 Subject: fix CHP_RDY check, waiting and so on git-svn-id: https://svn.spreadspace.org/mur.sat@421 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/hhd70dongle/c1101lib.c | 23 +++++++++-------------- software/hhd70dongle/c1101lib.h | 2 +- software/hhd70dongle/hhd70dongle.c | 1 + software/hhd70dongle/spi.c | 13 +++++++++++-- 4 files changed, 22 insertions(+), 17 deletions(-) (limited to 'software') diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index 57ee7eb..2376e91 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -43,18 +43,22 @@ int16_t spi_c1101_write_byte_ok_get_status(char data) { - uint8_t debug_sb[6]; + //~ uint8_t debug_sb[6]; char sb; unsigned int attempts = 0; do { sb = spi_exchange_byte(data); - usb_rawhid_send((uint8_t*)"spi byte exchanged ",255); - debug_sprint_int16hex(debug_sb, sb); - usb_rawhid_send(debug_sb,255); + //Note: content of returned StatusByte is actually context depenedant on sent command + // i.e. we won't get Fifo Byte count or overflow status on normal command and so on + // e.g. we only get TX Fifo Free Byte count while writing to TX Fifo + // thus it makes sense to only check for CHIP_RDY here + //~ usb_rawhid_send((uint8_t*)"spi byte exchanged ",255); + //~ debug_sprint_int16hex(debug_sb, sb); + //~ usb_rawhid_send(debug_sb,255); if (attempts++ > SPIC1101_MAX_WAIT) return -1; - } while ( SPIC1101_SB_CHIPRDY(sb) == 0 ); + } while ( SPIC1101_SB_CHIP_NOT_RDY(sb) ); return sb; } @@ -72,15 +76,6 @@ int16_t spi_c1101_read_register(char address) return -1; _delay_ms(10); //FIXME: propably don't need this rbyte = spi_read_byte(); - uint8_t debug_sb[6]; - debug_sprint_int16hex(debug_sb, rbyte); - usb_rawhid_send(debug_sb,255); - rbyte = spi_read_byte(); - debug_sprint_int16hex(debug_sb, rbyte); - usb_rawhid_send(debug_sb,255); - rbyte = spi_read_byte(); - debug_sprint_int16hex(debug_sb, rbyte); - usb_rawhid_send(debug_sb,255); spi_cs_disable(); return rbyte; } diff --git a/software/hhd70dongle/c1101lib.h b/software/hhd70dongle/c1101lib.h index 43cfc2b..7740494 100644 --- a/software/hhd70dongle/c1101lib.h +++ b/software/hhd70dongle/c1101lib.h @@ -119,7 +119,7 @@ #define SPIC1101_ADDR_FIFO_WRITE 0x3F #define SPIC1101_ADDR_FIFO_WRITE_BURST (0x3F | 0x40) -#define SPIC1101_SB_CHIPRDY(x) (x & 0b10000000) +#define SPIC1101_SB_CHIP_NOT_RDY(x) (x & 0b10000000) #define SPIC1101_SB_IDLE(x) (x & 0b01110000) == 0 #define SPIC1101_SB_RXMODE(x) (x & 0b01110000) == 0b0010000 #define SPIC1101_SB_TXMODE(x) (x & 0b01110000) == 0b0100000 diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c index c221ffc..c130658 100644 --- a/software/hhd70dongle/hhd70dongle.c +++ b/software/hhd70dongle/hhd70dongle.c @@ -69,6 +69,7 @@ int main(void) usb_rawhid_send((uint8_t*)"hhd70dongle ready",17); + _delay_ms(500); c1101_init(); for(;;) diff --git a/software/hhd70dongle/spi.c b/software/hhd70dongle/spi.c index a2d9c55..39d3cd8 100644 --- a/software/hhd70dongle/spi.c +++ b/software/hhd70dongle/spi.c @@ -68,10 +68,19 @@ void spi_cs_disable(void) SPI_PORT |= (1<