From 4e4691b663f30b530b3800b617279901e2c1f698 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Wed, 27 Feb 2013 23:21:12 +0000 Subject: rda146dongle: raw read and write finished git-svn-id: https://svn.spreadspace.org/mur.sat@684 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/rda1846dongle/rda1846.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'software/rda1846dongle') diff --git a/software/rda1846dongle/rda1846.c b/software/rda1846dongle/rda1846.c index f12c40f..5277d3e 100644 --- a/software/rda1846dongle/rda1846.c +++ b/software/rda1846dongle/rda1846.c @@ -32,12 +32,12 @@ uint8_t rda1846_write_register(const uint8_t addr, const uint16_t data) { + if(addr >= 0x7F) // no support for this at the moment !!! + return 255; + if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError) return 1; - if(addr >= 0x7F) - goto i2c_error; // no support for this at the moment !!! - if(!TWI_SendByte(addr | RDA1846_ADDR_W)) goto i2c_error; if(!TWI_SendByte((uint8_t)(data>>8))) @@ -55,19 +55,23 @@ i2c_error: uint8_t rda1846_read_register(const uint8_t addr, uint16_t* data) { + if(addr >= 0x7F) // no support for this at the moment !!! + return 255; + if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_WRITE,10) != TWI_ERROR_NoError) return 1; - - if(addr >= 0x7F) - goto i2c_error; // no support for this at the moment !!! - if(!TWI_SendByte(addr | RDA1846_ADDR_R)) goto i2c_error; if(TWI_StartTransmission(RDA1846_CHIP_ADDR | TWI_ADDRESS_READ,10) != TWI_ERROR_NoError) goto i2c_error; - - // TODO read data + uint8_t tmp; + if(!TWI_ReceiveByte(&tmp, 0)) + goto i2c_error; + *data = tmp << 8; + if(!TWI_ReceiveByte(&tmp, 1)) + goto i2c_error; + data |= tmp; TWI_StopTransmission(); return 0; -- cgit v1.2.3