diff options
author | Bernhard Tittelbach <xro@realraum.at> | 2012-05-17 06:14:36 +0000 |
---|---|---|
committer | Bernhard Tittelbach <xro@realraum.at> | 2012-05-17 06:14:36 +0000 |
commit | d6c77acf4842495eca2bbd8efb167a4ebf52fa81 (patch) | |
tree | c350e6570a614d5d2c05352baf88780fd7742a94 /software/hhd70dongle/c1101lib.c | |
parent | fix CHP_RDY check, waiting and so on (diff) |
freshen code and play around a bit
git-svn-id: https://svn.spreadspace.org/mur.sat@422 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software/hhd70dongle/c1101lib.c')
-rw-r--r-- | software/hhd70dongle/c1101lib.c | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index 2376e91..e5e3edb 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -102,6 +102,24 @@ int16_t spi_c1101_strobe_command(char address) return 1; } +void spi_c1101_dump_registers_to_usb(void) +{ + int c = 0; + uint8_t debug_sb[6]; + spi_cs_enable(); + spi_c1101_wait_chip_rdy(); + if (spi_c1101_write_byte_ok_get_status(SPIC1101_ADDR_IOCFG2 | 0x40) < 0) + return; + usb_rawhid_send((uint8_t*)"dump all 46 registers:",255); + for (c=0; c<47; c++) + { + debug_sprint_int16hex(debug_sb, spi_read_byte()); + usb_rawhid_send(debug_sb,255); + } + spi_cs_disable(); +} + +//note: currently this function reads at most 15 bytes int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen) { int16_t sb; @@ -125,6 +143,7 @@ int spi_c1101_read_rxfifo(int leave_num_bytes, char *buffer, int maxlen) } //note: always check if num_written returned == len given +//note: currently this function writes at most 15 bytes int spi_c1101_write_txfifo(char *buffer, int len) { char sb; @@ -161,7 +180,38 @@ void c1101_init(void) //flush FIFOs spi_c1101_strobe_command(SPIC1101_ADDR_SFRX); spi_c1101_strobe_command(SPIC1101_ADDR_SFTX); - c1101_getStatus(); + //dump current default values to usb + spi_c1101_dump_registers_to_usb(); + //enable analog temperature sensor on GDO0 + spi_c1101_write_register(SPIC1101_ADDR_IOCFG0, 0x80); + // note: for now: assume f_xosc to be 26 Mhz + // for ~433.125 Mhz -> freq = 1091741, freq_offset = 0 + c1101_setFrequency(1091741,0,15); +} + +// freq: desired_carrier_freq [Hz] *2^16 / f_XOSC +// freq_offset: desired frequency offset [Hz] *2^14 / f_XOSC +// if_freq: desired intermidiate rx frequency [Hz] *2^10 / f_XOSC +void c1101_setFrequency(uint32_t freq, uint8_t freq_offset, uint8_t if_freq) +{ + //make sure we are in idle mode + char sb=0; + do + { + sb = c1101_getStatus(); + } while (! (SPIC1101_SB_IDLE(sb))); + //programm frequency + usb_rawhid_send((uint8_t*)"setting frequency",255); + spi_c1101_write_register(SPIC1101_ADDR_FREQ0, freq & 0xFF); + spi_c1101_write_register(SPIC1101_ADDR_FREQ1, (freq >> 8) & 0xFF); + spi_c1101_write_register(SPIC1101_ADDR_FREQ2, (freq >> 16) & 0x3F); + + //set frequency offset + spi_c1101_write_register(SPIC1101_ADDR_FSCTRL0, freq_offset); + //spi_c1101_write_register(SPIC1101_ADDR_FSCTRL1, if_freq & 0x1F); + + //set channel 0 + spi_c1101_write_register(SPIC1101_ADDR_CHANNR, 0); } char c1101_getVersion(void) @@ -174,6 +224,18 @@ char c1101_getPartNum(void) return spi_c1101_read_register(SPIC1101_ADDR_PARTNUM); } +uint16_t c1101_measureTemp(void) +{ + uint16_t temp; + char ptest_value=0x7F; + ptest_value = spi_c1101_read_register(SPIC1101_ADDR_PTEST); + spi_c1101_write_register(SPIC1101_ADDR_PTEST, 0xBF); + _delay_ms(5); + temp = adc_read(ADCMUX_INTERNALTEMP); + spi_c1101_write_register(SPIC1101_ADDR_PTEST, ptest_value); + return temp; +} + void c1101_handleStatusByte(char sb) { //on RXFifo Overflow, Flush RX Fifo |