diff options
Diffstat (limited to 'software/hhd70dongle')
-rw-r--r-- | software/hhd70dongle/c1101lib.c | 88 | ||||
-rw-r--r-- | software/hhd70dongle/c1101lib.h | 10 | ||||
-rw-r--r-- | software/hhd70dongle/hhd70.c | 10 | ||||
-rw-r--r-- | software/hhd70dongle/hhd70.h | 2 | ||||
-rw-r--r-- | software/hhd70dongle/hhd70dongle.c | 38 |
5 files changed, 121 insertions, 27 deletions
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c index d7c78ee..c24c398 100644 --- a/software/hhd70dongle/c1101lib.c +++ b/software/hhd70dongle/c1101lib.c @@ -12,6 +12,7 @@ * * * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at> + * 2015 Christian Pointner <equinox@mur.at> * * This file is part of mur.sat. * @@ -203,7 +204,7 @@ int c1101_spi_write_txfifo(char *buffer, int len) } //patable muste be char array of length 8 -int c1101_spi_write_patable(char const patable[]) +int c1101_spi_write_patable(uint8_t const patable[]) { int16_t sb; int8_t len = 8; @@ -222,6 +223,21 @@ int c1101_spi_write_patable(char const patable[]) } +static uint8_t const pa_table_values_[] = { 0x00, 0x30, 0x20, 0x10, 0x01, 0x02, 0x11, 0x03, + 0x12, 0x04, 0x05, 0x13, 0x06, 0x07, 0x21, 0x14, 0x08, 0x09, 0x0A, 0x15, + 0x0B, 0x31, 0x16, 0x0C, 0x0D, 0x0E, 0x17, 0x0F, 0x22, 0x18, 0x19, 0x1A, + 0x1B, 0x32, 0x23, 0x1C, 0x6F, 0x1D, 0x1E, 0x1F, 0x24, 0x33, 0x25, 0x34, + 0x26, 0x6E, 0x27, 0x35, 0x28, 0x6D, 0x6C, 0x29, 0x36, 0x6B, 0x2A, 0x6A, + 0x37, 0x69, 0x2B, 0x68, 0x38, 0x2C, 0x8F, 0x67, 0x2D, 0x57, 0x39, 0x66, + 0x2E, 0x56, 0x3A, 0x2F, 0x65, 0x55, 0x3B, 0x64, 0x54, 0x3C, 0x63, 0x3D, + 0x53, 0x3E, 0x62, 0x3F, 0x52, 0x40, 0x61, 0x51, 0x60, 0x50, 0x8E, 0x8D, + 0x8C, 0xCF, 0x8B, 0x8A, 0x89, 0x88, 0x87, 0x86, 0x85, 0xCE, 0x84, 0x83, + 0xCD, 0x82, 0xCC, 0x81, 0xCB, 0x80, 0xCA, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, + 0xC4, 0xC3, 0xC2, 0xC1, 0xC0 }; + +#define PA_TABLE_VALUES_MAX ((sizeof(pa_table_values_)/sizeof(uint8_t))-1) +static uint8_t ook_power_ = 83; // ==> 3F + /**** External Functions ****/ uint16_t c1101_setFSKDeviationFromCarrier(int8_t m, int8_t e) @@ -292,7 +308,7 @@ void c1101_init(void) //AFU Satellite Band: 435.000 - 438.000 kHz //AFU Salellite Band Max Bandwith: 20 kHz - + hhd70_config_GDO0_OOK_output(false); } @@ -320,7 +336,7 @@ void c1101_init_w_rfstudiosettings1(void) // Modulated = true // Channel number = 0 // PA table - char const pa_table[8] = {0x00,0x12,0x0e,0x34,0x60,0xc5,0xc1,0xc0}; + uint8_t const pa_table[8] = {0x00,0x12,0x0e,0x34,0x60,0xc5,0xc1,0xc0}; // // Rf settings for CC1101 // @@ -337,7 +353,7 @@ void c1101_init_w_rfstudiosettings1(void) //Values from SmartRFStudio: c1101_spi_write_patable(pa_table); - + hhd70_config_GDO0_OOK_output(false); } @@ -354,21 +370,16 @@ void c1101_init_ook_beacon(void) // Preamble count = 2 // Address config = No address check // Whitening = false - // Carrier frequency = 435.199677 + // Carrier frequency = 437.524902 MHz // Device address = 0 // TX power = 10 // Manchester enable = false // CRC enable = false // Deviation = 2.975464 // Modulation format = ASK/OOK - // Base frequency = 435.199677 + // Base frequency = 437.524902 MHz // Channel number = 0 // PA table by TI - //char const pa_table[8] = {0x00,0x12,0x0e,0x34,0x60,0xc5,0xc1,0xc0}; - // not recommended for OOK even with PA ramping set to false - //char const pa_table[8] = {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - // correct PA table for OOK (only first two values matter) - char const pa_table[8] = {0x00,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5,0xc5}; //reset C1101 c1101_spi_strobe_command(SPIC1101_ADDR_SRES); @@ -388,11 +399,11 @@ void c1101_init_ook_beacon(void) c1101_spi_write_register(SPIC1101_ADDR_FIFOTHR, 0); //assert at 4 bytes in RX Fifo and 61 in TX Fifo //c1101_spi_write_register(SPIC1101_ADDR_PKTCTRL0,0x12);//Packet Automation Control //c1101_spi_write_register(SPIC1101_ADDR_PKTCTRL0, 0b0000000001); //crc disabled; use FIFOs; variable packet length mode (first TX FIFO byte must be length) - c1101_spi_write_register(SPIC1101_ADDR_PKTCTRL0, 0b0000110001); //crc disabled; asynchronous serial input on GDO0 + c1101_spi_write_register(SPIC1101_ADDR_PKTCTRL0, 0b0000110001); //crc disabled; asynchronous serial input on GDO0 c1101_spi_write_register(SPIC1101_ADDR_FSCTRL1,0x06); //Frequency Synthesizer Control c1101_spi_write_register(SPIC1101_ADDR_FREQ2,0x10); //Frequency Control Word, High Byte - c1101_spi_write_register(SPIC1101_ADDR_FREQ1,0xBD); //Frequency Control Word, Middle Byte - c1101_spi_write_register(SPIC1101_ADDR_FREQ0,0x0B); //Frequency Control Word, Low Byte + c1101_spi_write_register(SPIC1101_ADDR_FREQ1,0xD3); //Frequency Control Word, Middle Byte + c1101_spi_write_register(SPIC1101_ADDR_FREQ0,0xF0); //Frequency Control Word, Low Byte c1101_spi_write_register(SPIC1101_ADDR_MDMCFG4,0xF5); //Modem Configuration c1101_spi_write_register(SPIC1101_ADDR_MDMCFG3,0x43); //Modem Configuration c1101_spi_write_register(SPIC1101_ADDR_MDMCFG2,0x30); //Modem Configuration @@ -406,11 +417,42 @@ void c1101_init_ook_beacon(void) c1101_spi_write_register(SPIC1101_ADDR_FSCAL2,0x2A); //Frequency Synthesizer Calibration c1101_spi_write_register(SPIC1101_ADDR_FSCAL1,0x00); //Frequency Synthesizer Calibration c1101_spi_write_register(SPIC1101_ADDR_FSCAL0,0x1F); //Frequency Synthesizer Calibration - c1101_spi_write_patable(pa_table); - + + c1101_ook_power_set(ook_power_); hhd70_config_GDO0_OOK_output(true); } +uint8_t c1101_ook_power_get() +{ + return ook_power_; +} + +uint8_t c1101_ook_power_get_raw() +{ + return pa_table_values_[ook_power_]; +} + +void c1101_ook_power_set(uint8_t power) +{ + uint8_t val = pa_table_values_[(power <= PA_TABLE_VALUES_MAX) ? power : PA_TABLE_VALUES_MAX]; + uint8_t const pa_table[8] = {0x00, val ,0x00,0x00,0x00,0x00,0x00,0x00}; + c1101_spi_write_patable(pa_table); +} + +void c1101_ook_power_inc() +{ + ook_power_ = (ook_power_ < PA_TABLE_VALUES_MAX) ? ook_power_ + 1 : PA_TABLE_VALUES_MAX; + uint8_t const pa_table[8] = {0x00, pa_table_values_[ook_power_] ,0x00,0x00,0x00,0x00,0x00,0x00}; + c1101_spi_write_patable(pa_table); +} + +void c1101_ook_power_dec() +{ + ook_power_ = (ook_power_ > 0) ? ook_power_ - 1 : 0; + uint8_t const pa_table[8] = {0x00, pa_table_values_[ook_power_] ,0x00,0x00,0x00,0x00,0x00,0x00}; + c1101_spi_write_patable(pa_table); +} + // see Datasheet Chapter 14.1 Frequency Offset Compensation // freq_offset: desired frequency offset [Hz] *2^14 / f_XTAL //f_XTAL = 26Mhz @@ -554,7 +596,7 @@ bool c1101_writeFrequencyRegisters(uint32_t freq) { if (! c1101_waitUntilIDLEState(2000)) //wait 2sec max return false; - //programm frequency + //programm frequency c1101_spi_write_register(SPIC1101_ADDR_FREQ0, freq & 0xFF); c1101_spi_write_register(SPIC1101_ADDR_FREQ1, (freq >> 8) & 0xFF); c1101_spi_write_register(SPIC1101_ADDR_FREQ2, (freq >> 16) & 0x3F); @@ -570,7 +612,7 @@ uint32_t c1101_readFrequencyRegisters(void) freq = ((uint8_t) c1101_spi_read_register(SPIC1101_ADDR_FREQ2)) & 0x3F; freq = freq << 8; freq |= ((uint8_t) c1101_spi_read_register(SPIC1101_ADDR_FREQ1)); - freq = freq << 8; + freq = freq << 8; freq |= ((uint8_t) c1101_spi_read_register(SPIC1101_ADDR_FREQ0)); return freq; } @@ -579,7 +621,7 @@ uint32_t c1101_readFrequencyRegisters(void) // freq: desired_carrier_freq [Hz] *2^16 / f_XOSC bool c1101_setFrequency(uint32_t freq_hz) { - uint32_t freq = freq_hz / 397; + uint32_t freq = (uint32_t)((float)freq_hz / C1101_FREQ_TO_HZ); if ( freq <= 0x3FFFFF) return c1101_writeFrequencyRegisters(freq); else @@ -590,11 +632,11 @@ bool c1101_setFrequency(uint32_t freq_hz) // freq: desired_carrier_freq [Hz] *2^16 / f_XOSC bool c1101_changeFrequencyByRelativeValue(int32_t freq_change_hz) { - int32_t freq_change = freq_change_hz / 397; + int32_t freq_change = (int32_t)((float)freq_change_hz / C1101_FREQ_TO_HZ); int32_t freq = (int32_t) c1101_readFrequencyRegisters(); - + freq += freq_change; - + if ( freq >= 0 && freq <= 0x3FFFFF ) return c1101_writeFrequencyRegisters((uint32_t) freq); else @@ -603,7 +645,7 @@ bool c1101_changeFrequencyByRelativeValue(int32_t freq_change_hz) uint32_t c1101_getCurrentCarrierFrequencyHz(void) { - return c1101_readFrequencyRegisters() * 397; + return (uint32_t)((float)c1101_readFrequencyRegisters() * C1101_FREQ_TO_HZ); } // if_freq: desired intermidiate rx frequency [Hz] *2^10 / f_XOSC diff --git a/software/hhd70dongle/c1101lib.h b/software/hhd70dongle/c1101lib.h index 6c3943c..e653a4b 100644 --- a/software/hhd70dongle/c1101lib.h +++ b/software/hhd70dongle/c1101lib.h @@ -12,6 +12,7 @@ * * * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at> + * 2015 Christian Pointner <equinox@mur.at> * * This file is part of mur.sat. * @@ -34,7 +35,7 @@ #define C1101_FIFO_MAX_LEN 64 -#include <stdbool.h> +#include <stdbool.h> //read/write config registers: #define SPIC1101_ADDR_IOCFG2 0x00 @@ -138,6 +139,8 @@ #define SPIC1101_SB_TXFIFO_OVERFLOW(x) (x & 0b01110000) == 0b1110000 #define SPIC1101_SB_FIFO_BYTES_AVAILABLE(x) (x & 0b00001111) +#define C1101_FREQ_TO_HZ 396.728515 // = Fosc/65536 = 26000000/65536 + int16_t c1101_spi_read_register(char address); int16_t c1101_spi_write_register(char address, char byte); int16_t c1101_spi_strobe_command(char address); @@ -145,6 +148,11 @@ int16_t c1101_spi_strobe_command(char address); uint16_t c1101_setFSKDeviationFromCarrier(int8_t m, int8_t e); void c1101_init(void); void c1101_init_ook_beacon(void); +uint8_t c1101_ook_power_get(void); +uint8_t c1101_ook_power_get_raw(void); +void c1101_ook_power_set(uint8_t power); +void c1101_ook_power_inc(void); +void c1101_ook_power_dec(void); void c1101_handleStatusByte(char sb); char c1101_getStatus(void); uint16_t c1101_measureTemp(void); diff --git a/software/hhd70dongle/hhd70.c b/software/hhd70dongle/hhd70.c index d2a3558..1e3b5c7 100644 --- a/software/hhd70dongle/hhd70.c +++ b/software/hhd70dongle/hhd70.c @@ -12,6 +12,7 @@ * * * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at> + * 2015 Christian Pointner <equinox@mur.at> * * This file is part of mur.sat. * @@ -85,7 +86,12 @@ void hhd70_set_OOK_GDO0_high(void) void hhd70_set_OOK_GDO0_low(void) { //pull low - SPI_PORT &= ~(1<<GDO0); + SPI_PORT &= ~(1<<GDO0); +} + +void hhd70_set_OOK_GDO0_toggle(void) +{ + SPI_PORT ^= (1 << GDO0); } void hhd70_spi_cs_enable(void) @@ -135,7 +141,7 @@ char hhd70_spi_read_byte(void) void hhd70_palna_txmode(void) { SPI_PORT |= (1<<TE); - hhd70_bias_on(); + hhd70_bias_on(); } void hhd70_palna_rxmode(void) diff --git a/software/hhd70dongle/hhd70.h b/software/hhd70dongle/hhd70.h index 8caccba..a1faea6 100644 --- a/software/hhd70dongle/hhd70.h +++ b/software/hhd70dongle/hhd70.h @@ -12,6 +12,7 @@ * * * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at> + * 2015 Christian Pointner <equinox@mur.at> * * This file is part of mur.sat. * @@ -66,6 +67,7 @@ int8_t hhd70_rx_data_available(void); void hhd70_config_GDO0_OOK_output(bool output_mode); void hhd70_set_OOK_GDO0_high(void); void hhd70_set_OOK_GDO0_low(void); +void hhd70_set_OOK_GDO0_toggle(void); void hhd70_bias_set(uint8_t val); uint8_t hhd70_bias_get(void); void hhd70_bias_inc(void); diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c index 730c28c..81fabf4 100644 --- a/software/hhd70dongle/hhd70dongle.c +++ b/software/hhd70dongle/hhd70dongle.c @@ -12,6 +12,7 @@ * * * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at> + * 2015 Christian Pointner <equinox@mur.at> * * This file is part of mur.sat. * @@ -183,6 +184,8 @@ int main(void) enable_tx_part=false; c1101_init_ook_beacon(); + printf("CC1101 enabling Beacon with Power: %3d (0x%02X)\r\n", (int)c1101_ook_power_get(), (int)c1101_ook_power_get_raw()); + beacon_enable(); beacon_on(); } @@ -284,7 +287,8 @@ int main(void) uint32_t hz = c1101_getCurrentCarrierFrequencyHz(); uint16_t mhz = hz / 1000000; uint16_t khz = (hz % 1000000)/1000; - printf("Frequency is now: %d.%03d MHz\r\n", mhz, khz); + hz %= 1000; + printf("Frequency is now: %d.%03d%03d MHz\r\n", mhz, khz, (uint16_t)hz); } else if ((char) recv_byte == 'p') { @@ -296,6 +300,38 @@ int main(void) hhd70_bias_inc(); printf("Bias Power is now: %d\r\n", hhd70_bias_get()); } + else if ((char) recv_byte == 'o') + { + if (enable_beacon_part) beacon_off(); + beacon_disable(); + + c1101_ook_power_dec(); + printf("CC1101 Power is now: %3d (0x%02X)\r\n", (int)c1101_ook_power_get(), (int)c1101_ook_power_get_raw()); + + if (enable_beacon_part) { + beacon_enable(); + beacon_on(); + } + } + else if ((char) recv_byte == 'O') + { + if (enable_beacon_part) beacon_off(); + beacon_disable(); + + c1101_ook_power_inc(); + printf("CC1101 Power is now: %3d (0x%02X)\r\n", (int)c1101_ook_power_get(), (int)c1101_ook_power_get_raw()); + + if (enable_beacon_part) { + beacon_enable(); + beacon_on(); + } + } + else if ((char) recv_byte == ' ') + { + if (enable_beacon_part) { + hhd70_set_OOK_GDO0_toggle(); + } + } } |