summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:34 +0000
committerBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:34 +0000
commit195ea8d1af2745228c8d4a5c893ae0c8e27ba96c (patch)
tree2d1db8aba809dd155462413d4edde4fb565dbbf4
parentmake SPI work by correcting register typo ;-) (diff)
fix CHP_RDY check, waiting and so on
git-svn-id: https://svn.spreadspace.org/mur.sat@421 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r--software/hhd70dongle/c1101lib.c23
-rw-r--r--software/hhd70dongle/c1101lib.h2
-rw-r--r--software/hhd70dongle/hhd70dongle.c1
-rw-r--r--software/hhd70dongle/spi.c13
4 files changed, 22 insertions, 17 deletions
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<<CS);
}
+#include "usb_rawhid.h"
+#include "util.h"
+
void spi_c1101_wait_chip_rdy(void)
{
//c1101 will set MISO to low if ready
- for (unsigned int c=0; c < 0xFFFFFF && (SPI_PINB_REG & (1<<MISO)); c++);
+ while (SPI_PINB_REG & (1<<MISO));
+ //~ unsigned int c;
+ //~ for (c=0; c < 0xFFFFFFFF && (SPI_PINB_REG & (1<<MISO)); c++);
+ //~ uint8_t debug_buff[6];
+ //~ usb_rawhid_send((uint8_t*)"spi waited for:",255);
+ //~ debug_sprint_int16hex(debug_buff, c);
+ //~ usb_rawhid_send(debug_buff,255);
}
void spi_write_byte(char byte)
@@ -89,5 +98,5 @@ char spi_exchange_byte(char byte)
char spi_read_byte(void)
{
//transmit something so SCLK runs for 8 bits, so that slave can transfer 1 byte
- return spi_exchange_byte(0xFF);
+ return spi_exchange_byte(0);
} \ No newline at end of file