From a72fc32daf434dc7ad59e4065c18332ddd7f67b0 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 19 May 2012 20:12:42 +0000 Subject: first attempt at RX/TX w/ 2 dongles git-svn-id: https://svn.spreadspace.org/mur.sat@440 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/hhd70dongle/c1101lib.c | 37 +++++++++++++++++++++++++------------ software/hhd70dongle/c1101lib.h | 3 +-- software/hhd70dongle/hhd70dongle.c | 18 ++++++++++-------- software/hhd70dongle/spi.c | 7 ++++++- software/hhd70dongle/spi.h | 3 +-- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index 30bb94c..61780d5 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -134,6 +134,8 @@ int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen) if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_RXBYTES) < 0) return -1; num_available = spi_read_byte(); + if (num_available == 0) + return 0; if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_FIFO_READ_BURST) < 0) return -1; while (maxlen-- > 0 && num_available - num_read > leave_num_bytes) @@ -202,8 +204,8 @@ void c1101_init(void) spi_c1101_dump_registers_to_usb(); //enable analog temperature sensor on GDO0 spi_c1101_write_register(SPIC1101_ADDR_IOCFG0, 0x80); - //enable RX FIFO interrupt (i.e. GPO1 pulls high if >= FIFOTHR bytes are in RX FIFO) - spi_c1101_write_register(SPIC1101_ADDR_IOCFG1, 0); + //enable RX FIFO interrupt (i.e. GPO2 pulls high if >= FIFOTHR bytes are in RX FIFO) + spi_c1101_write_register(SPIC1101_ADDR_IOCFG2, 0); // FIFOTHR RX FIFO and TX FIFO Thresholds // pull GPO high (interrupt) if more than 12 bytes in rx buffer (or less than 53 in tx) spi_c1101_write_register(SPIC1101_ADDR_FIFOTHR, 2); @@ -268,16 +270,6 @@ void c1101_setFrequency(uint32_t freq, uint8_t freq_offset, uint8_t if_freq) spi_c1101_write_register(SPIC1101_ADDR_CHANNR, 0); } -char c1101_getVersion(void) -{ - return spi_c1101_read_register(SPIC1101_ADDR_VERSION); -} - -char c1101_getPartNum(void) -{ - return spi_c1101_read_register(SPIC1101_ADDR_PARTNUM); -} - char c1101_putToSleep(void) { return spi_c1101_strobe_command(SPIC1101_ADDR_SPWD); @@ -425,7 +417,28 @@ void c1101_transmitData(char *buffer, unsigned int len) //disable Power Amplifier hhd70_pa_disable(); + hhd70_lna_enable(); +} +void c1101_recieveData(void) +{ + uint8_t const max_len=255; + char recv_data[256]; + uint8_t num_recv = 0; + uint8_t num_recv_total = 0; + uint8_t num_leave_in_fifo = 1; + do + { + num_recv = spi_c1101_read_rxfifo( num_leave_in_fifo, recv_data+num_recv_total, max_len - num_recv_total); + num_recv_total += num_recv; + + //variable packet length: + //don't read last byte in fifo unless packet has finished receiving + num_leave_in_fifo = (recv_data[0] - num_recv_total < 64)? 0 : 1; + } while (num_recv > 0); + recv_data[num_recv_total]=0; + usb_rawhid_send((uint8_t*)"RX: Data Recieved:",255); + usb_rawhid_send((uint8_t*)recv_data,255); } //max returned: 64 bytes diff --git a/software/hhd70dongle/c1101lib.h b/software/hhd70dongle/c1101lib.h index 9ecbadb..09f0ca4 100644 --- a/software/hhd70dongle/c1101lib.h +++ b/software/hhd70dongle/c1101lib.h @@ -135,8 +135,6 @@ int16_t spi_c1101_write_register(char address, char byte); int16_t spi_c1101_strobe_command(char address); void c1101_init(void); -char c1101_getVersion(void); -char c1101_getPartNum(void); void c1101_handleStatusByte(char sb); char c1101_getStatus(void); uint16_t c1101_measureTemp(void); @@ -144,6 +142,7 @@ void spi_c1101_dump_registers_to_usb(void); void c1101_setFrequency(uint32_t freq, uint8_t freq_offset, uint8_t if_freq); void c1101_transmitData(char *buffer, unsigned int len); +void c1101_recieveData(void); //max returned: 64 bytes int c1101_readRXFifo(char *buffer); diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c index 9c19398..da1c882 100644 --- a/software/hhd70dongle/hhd70dongle.c +++ b/software/hhd70dongle/hhd70dongle.c @@ -71,6 +71,7 @@ int main(void) _delay_ms(500); c1101_init(); + hhd70_lna_enable(); for(;;) { @@ -78,14 +79,15 @@ int main(void) usb_rawhid_recv(read_buffer,20); if (read_buffer[0] == 'r') reset(); - //~ usb_rawhid_send((uint8_t*)"c1101 partnum:",255); - //~ debug_sprint_int16hex(write_buffer, c1101_getPartNum()); - //~ usb_rawhid_send(write_buffer,255); - //~ _delay_ms(250); - //~ usb_rawhid_send((uint8_t*)"c1101 version:",255); - //~ debug_sprint_int16hex(write_buffer, c1101_getVersion()); - //~ usb_rawhid_send(write_buffer,255); - //~ _delay_ms(250); + + if (hhd70_rx_data_available()) + { + led_on(); + usb_rawhid_send((uint8_t*)"RX: GDO2 pin HIGH",100); + c1101_recieveData(); + led_off(); + } + usb_rawhid_send((uint8_t*)"c1101 rssi:",255); debug_sprint_int16hex(write_buffer, spi_c1101_read_register(SPIC1101_ADDR_RSSI)); usb_rawhid_send(write_buffer,255); diff --git a/software/hhd70dongle/spi.c b/software/hhd70dongle/spi.c index 426684a..ec0397b 100644 --- a/software/hhd70dongle/spi.c +++ b/software/hhd70dongle/spi.c @@ -37,7 +37,7 @@ void spi_init(void) { //configure Direction of SS / PB0 , MOSI and SCLK as Output to drive CS of CC1101 SPI_PORT = (1<