diff options
author | Christian Pointner <equinox@mur.at> | 2013-03-21 02:31:10 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2013-03-21 02:31:10 +0000 |
commit | a5d9e5e231f3e1e2946a7c2b849e60e7dadef6e3 (patch) | |
tree | 8fac589a88d5e76dec5a595b61fca7e843f0a200 | |
parent | parts of rda1846dongle working (diff) |
first working receive
git-svn-id: https://svn.spreadspace.org/mur.sat@703 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r-- | software/rda1846dongle/rda1846.c | 95 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846.h | 8 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846_defines.h | 1 | ||||
-rw-r--r-- | software/rda1846dongle/rda1846dongle.c | 20 |
4 files changed, 89 insertions, 35 deletions
diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c index c806036..fec9c05 100644 --- a/software/rda1846dongle/rda1846.c +++ b/software/rda1846dongle/rda1846.c @@ -109,6 +109,11 @@ static uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data) } +void rda1846_soft_reset(void) +{ + rda1846_write_register(RDA1846_REG_CTL, RDA1846_CTL_SOFT_RST); +} + void rda1846_init(void) { TWI_Init(TWI_BIT_PRESCALE_1, TWI_BITLENGTH_FROM_FREQ(1, 200000)); @@ -121,21 +126,47 @@ void rda1846_init(void) rda1846_write_register(RDA1846_REG_ADCLK, RDA1846_ADCLK_FREQ); rda1846_write_register(RDA1846_REG_CLK_MODE, RDA1846_CLK_MODE); - rda1846_write_register(RDA1846_REG_CTL, RDA1846_CTL_CH_12K5 | RDA1846_CTL_RX_M_TX_M | RDA1846_CTL_RX); - rda1846_write_register(RDA1846_REG_INT, RDA1846_INT_DTMF_IDLE); + rda1846_write_register(RDA1846_REG_CTL, RDA1846_CTL_CH_12K5 | RDA1846_CTL_RX_M_TX_M); - // use this if VOX, SQ, TXON_RF, RXON_RF are meant as outputs +// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_NONE); +// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_MIC); + rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_TONE2); + +// rda1846_write_register(RDA1846_REG_DTMF_CTL, RDA1846_DTMF_DUAL | RDA1846_DTMF_EN); +// rda1846_write_register(RDA1846_REG_INT, RDA1846_INT_DTMF_IDLE); + + rda1846_gpio_default(); +} + +void rda1846_gpio_default(void) +{ rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_7_VOX | RDA1846_GPIO_6_SQ | RDA1846_GPIO_5_TXON_RF | RDA1846_GPIO_4_RXON_RF | RDA1846_GPIO_2_INT); - // use this if VOX, SQ, TXON_RF, RXON_RF are meant as inputs -// rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_2_INT); +} -// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_NONE); - rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_MIC); -// rda1846_write_register(RDA1846_REG_TX_VOICE, RDA1846_TX_VOICE_TONE2); +void rda1846_gpio_AA(void) +{ + rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_7_HIGH | RDA1846_GPIO_6_LOW | + RDA1846_GPIO_5_HIGH | RDA1846_GPIO_4_LOW | + RDA1846_GPIO_3_HIGH | RDA1846_GPIO_2_LOW | + RDA1846_GPIO_1_HIGH | RDA1846_GPIO_0_LOW); +} -// rda1846_write_register(RDA1846_REG_DTMF_CTL, RDA1846_DTMF_DUAL | RDA1846_DTMF_EN); +void rda1846_gpio_55(void) +{ + rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_7_LOW | RDA1846_GPIO_6_HIGH | + RDA1846_GPIO_5_LOW | RDA1846_GPIO_4_HIGH | + RDA1846_GPIO_3_LOW | RDA1846_GPIO_2_HIGH | + RDA1846_GPIO_1_LOW | RDA1846_GPIO_0_HIGH); +} + +void rda1846_gpio_off(void) +{ + rda1846_write_register(RDA1846_REG_GPIO, RDA1846_GPIO_7_HI_Z | RDA1846_GPIO_6_HI_Z | + RDA1846_GPIO_5_HI_Z | RDA1846_GPIO_4_HI_Z | + RDA1846_GPIO_3_HI_Z | RDA1846_GPIO_2_HI_Z | + RDA1846_GPIO_1_HI_Z | RDA1846_GPIO_0_HI_Z); } void rda1846_powerdown(void) @@ -145,7 +176,7 @@ void rda1846_powerdown(void) return; data &= ~(RDA1846_CTL_PDN); - rda1846_write_register(RDA1846_REG_CTL, data); + rda1846_write_register(RDA1846_REG_CTL, data); } void rda1846_wakeup(void) @@ -155,7 +186,18 @@ void rda1846_wakeup(void) return; data |= RDA1846_CTL_PDN; - rda1846_write_register(RDA1846_REG_CTL, data); + rda1846_write_register(RDA1846_REG_CTL, data); +} + + +void rda1846_idle(void) +{ + uint16_t data; + if(rda1846_read_register(RDA1846_REG_CTL, &data)) + return; + + data &= ~(RDA1846_CTL_TX | RDA1846_CTL_RX | RDA1846_CTL_CHIP_CAL); + rda1846_write_register(RDA1846_REG_CTL, data); } void rda1846_receive(void) @@ -164,9 +206,9 @@ void rda1846_receive(void) if(rda1846_read_register(RDA1846_REG_CTL, &data)) return; - data |= RDA1846_CTL_RX; + data |= RDA1846_CTL_RX | RDA1846_CTL_CHIP_CAL; data &= ~(RDA1846_CTL_TX); - rda1846_write_register(RDA1846_REG_CTL, data); + rda1846_write_register(RDA1846_REG_CTL, data); } void rda1846_transmit(void) @@ -176,23 +218,17 @@ void rda1846_transmit(void) return; data &= ~(RDA1846_CTL_RX); - data |= RDA1846_CTL_TX; - rda1846_write_register(RDA1846_REG_CTL, data); + data |= RDA1846_CTL_TX | RDA1846_CTL_CHIP_CAL; + rda1846_write_register(RDA1846_REG_CTL, data); } -void rda1846_soft_reset(void) -{ - rda1846_write_register(RDA1846_REG_CTL, RDA1846_CTL_SOFT_RST); -} - - int16_t rda1846_get_rssi(void) { uint16_t data; if(rda1846_read_register(RDA1846_REG_RSSI, &data)) return -1; - return (int16_t)data; + return ((int16_t)(data & 0x03FF) - 135*8); } int16_t rda1846_get_vssi(void) @@ -209,7 +245,7 @@ uint16_t rda1846_get_flags(void) uint16_t data; if(rda1846_read_register(RDA1846_REG_FLAG, &data)) return 0xFFFF; - + return data & 0x1687; } @@ -280,6 +316,7 @@ char* rda1846_regaddr_to_string(uint8_t addr) case RDA1846_REG_VOX_OPEN: return "VOX_OPEN"; case RDA1846_REG_VOX_SHUT: return "VOX_SHUT"; case RDA1846_REG_SUBAUDIO: return "SUBAUDIO"; + case RDA1846_REG_RX_VOICE: return "RX_VOICE"; case RDA1846_REG_SQ_OPEN: return "SQ_OPEN"; case RDA1846_REG_SQ_SHUT: return "SQ_SHUT"; case RDA1846_REG_DTMF_CTL: return "DTMF_CTL"; @@ -298,11 +335,13 @@ void rda1846_dump_register(void) { printf("RDA1846: register dump\r\n"); - const uint8_t regs[] = { RDA1846_REG_RF_BAND, RDA1846_REG_XTAL, RDA1846_REG_ADCLK, - RDA1846_REG_CLK_MODE, RDA1846_REG_CTL, RDA1846_REG_INT, - RDA1846_REG_GPIO, RDA1846_REG_TX_VOICE, RDA1846_REG_DTMF_CTL, - RDA1846_REG_RSSI, RDA1846_REG_VSSI, RDA1846_REG_FLAG, - RDA1846_REG_DTMF_OUT, RDA1846_REG_FREQH, RDA1846_REG_FREQL }; + const uint8_t regs[] = { RDA1846_REG_CLK_MODE, RDA1846_REG_XTAL, RDA1846_REG_ADCLK, + RDA1846_REG_RF_BAND, RDA1846_REG_FREQH, RDA1846_REG_FREQL, + RDA1846_REG_CTL, RDA1846_REG_INT, RDA1846_REG_GPIO, + RDA1846_REG_PA_BIAS, RDA1846_REG_TX_VOICE, RDA1846_REG_VOX_OPEN, RDA1846_REG_VOX_SHUT, + RDA1846_REG_SUBAUDIO, RDA1846_REG_RX_VOICE, RDA1846_REG_SQ_OPEN, RDA1846_REG_SQ_SHUT, + RDA1846_REG_DTMF_CTL, RDA1846_REG_DTMF_OUT, + RDA1846_REG_RSSI, RDA1846_REG_VSSI, RDA1846_REG_FLAG }; int i; for(i=0; i<sizeof(regs); ++i) { diff --git a/software/rda1846dongle/rda1846.h b/software/rda1846dongle/rda1846.h index 71d292b..c1db4a1 100644 --- a/software/rda1846dongle/rda1846.h +++ b/software/rda1846dongle/rda1846.h @@ -33,15 +33,21 @@ #ifndef MURSAT_rda1846_h_INCLUDED #define MURSAT_rda1846_h_INCLUDED -void rda1846_init(void); void rda1846_soft_reset(void); +void rda1846_init(void); void rda1846_powerdown(void); void rda1846_wakeup(void); +void rda1846_idle(void); void rda1846_receive(void); void rda1846_transmit(void); +void rda1846_gpio_default(void); +void rda1846_gpio_55(void); +void rda1846_gpio_AA(void); +void rda1846_gpio_off(void); + int16_t rda1846_get_rssi(void); int16_t rda1846_get_vssi(void); uint16_t rda1846_get_flags(void); diff --git a/software/rda1846dongle/rda1846_defines.h b/software/rda1846dongle/rda1846_defines.h index ad08703..a6281dd 100644 --- a/software/rda1846dongle/rda1846_defines.h +++ b/software/rda1846dongle/rda1846_defines.h @@ -61,6 +61,7 @@ #define RDA1846_REG_VOX_OPEN 0x41 #define RDA1846_REG_VOX_SHUT 0x42 +#define RDA1846_REG_RX_VOICE 0x44 #define RDA1846_REG_SUBAUDIO 0x45 #define RDA1846_REG_SQ_OPEN 0x48 #define RDA1846_REG_SQ_SHUT 0x49 diff --git a/software/rda1846dongle/rda1846dongle.c b/software/rda1846dongle/rda1846dongle.c index ebb97de..757356d 100644 --- a/software/rda1846dongle/rda1846dongle.c +++ b/software/rda1846dongle/rda1846dongle.c @@ -88,10 +88,12 @@ static void update_current_freq(void) static void print_status(void) { int16_t rssi = rda1846_get_rssi(); - if(rssi < 0) - printf("rssi: NaN dB\r\n"); - else - printf("rssi: %d.%03d dB\r\n", (uint16_t)(rssi / 8), (uint16_t)((rssi % 8)*125)); + printf("rssi: "); + if(rssi < 0) { + printf("-"); + rssi*=-1; + } + printf("%d.%03d dB\r\n", (uint16_t)(rssi / 8), (uint16_t)((rssi % 8)*125)); int16_t vssi = rda1846_get_vssi(); if(vssi < 0) @@ -121,13 +123,18 @@ static void print_dtmf(void) static void handle_cmd(uint8_t cmd) { switch(cmd) { - case '0': led_off(); printf("led OFF\r\n"); break; - case '1': led_on(); printf("led ON\r\n"); break; + case '0': rda1846_gpio_AA(); led_off(); printf("led OFF\r\n"); break; + case '1': rda1846_gpio_55(); led_on(); printf("led ON\r\n"); break; case 't': led_toggle(); printf("led TOGGLE\r\n"); break; case '!': reset2bootloader(); break; + case 'r': rda1846_soft_reset(); printf("soft resetting RDA1846.\r\n"); break; case 'i': rda1846_init(); printf("initializing RDA1846.\r\n"); break; case 'F': set_default_freq(); break; + + case 'g': rda1846_gpio_off(); printf("GPIO off\r\n"); break; + case 'G': rda1846_gpio_default(); printf("GPIO to defaults\r\n"); break; + case 'f': print_actual_freq(); break; case 's': print_status(); break; case 'd': print_dtmf(); break; @@ -135,6 +142,7 @@ static void handle_cmd(uint8_t cmd) case 'p': rda1846_powerdown(); break; case 'P': rda1846_wakeup(); break; + case 'I': rda1846_idle(); break; case 'R': rda1846_receive(); break; case 'T': rda1846_transmit(); break; |