diff options
Diffstat (limited to 'software/rda1846dongle')
-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; |