diff options
author | Christian Pointner <equinox@mur.at> | 2013-02-27 23:21:12 +0000 |
---|---|---|
committer | Christian Pointner <equinox@mur.at> | 2013-02-27 23:21:12 +0000 |
commit | 4e4691b663f30b530b3800b617279901e2c1f698 (patch) | |
tree | b3a3a5e5344c98c1fa8aaacd0d53ea6849d359f9 | |
parent | rda1826dongle: added register write and read subs (not working yet) (diff) |
rda146dongle: raw read and write finished
git-svn-id: https://svn.spreadspace.org/mur.sat@684 7de4ea59-55d0-425e-a1af-a3118ea81d4c
-rw-r--r-- | software/rda1846dongle/rda1846.c | 22 |
1 files changed, 13 insertions, 9 deletions
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; |