From a5d9e5e231f3e1e2946a7c2b849e60e7dadef6e3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 21 Mar 2013 02:31:10 +0000 Subject: first working receive git-svn-id: https://svn.spreadspace.org/mur.sat@703 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/rda1846dongle/rda1846.c | 95 ++++++++++++++++++++++---------- software/rda1846dongle/rda1846.h | 8 ++- software/rda1846dongle/rda1846_defines.h | 1 + software/rda1846dongle/rda1846dongle.c | 20 +++++-- 4 files changed, 89 insertions(+), 35 deletions(-) (limited to 'software') 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