Dear Sparkfunners,
I am interfacing an RV1805-CW I2C (qwiik) wiring from an Atmega328p MCU, however I am not able to get “sensible” readings back. I know that my I2C interface is working, as I am getting sensible readings back from my tmp102 temperature module which is on the same TWI bus (also qwiiic).
When accessing the 0x28 register to get the “part nr” back from the RV1805, I should get back: 0x00011000 = 0x18 = 24 decimal (ref datasheet). However, ref attached snippet, I get 165 (decimal) back.
Below you will see the C code I am using to poll the part nr back from the module.
Are there any required “initialization routine” I will have to perform towards the RV1805 module in order to get it to work properly? Or, do you see any obvious error in my below c-code?
// --------------------------------------
#define RTC_Address 0xD2
#define RTC_AddressRead (RTC_Address << 1) | 0x01
#define RTC_AddressWrite (RTC_Address << 1) | 0x00
#define RV1805_ID0 0x28
uint8_t RTC_ReadPartNr() {
uint8_t ans;
ans=0x00;
TWI_start();
sRTC_Status.uint8t_Status = TWI_write_address(RTC_AddressWrite);
sRTC_Status.uint8t_Status = TWI_write_data(RV1805_ID0); //Reads addr 0x28 (Part Nr Upper Register - BCD format) - Should return 00011000 = "18" in BCD or 24 decimal.
TWI_repeated_start();
sRTC_Status.uint8t_Status = TWI_read_address(RTC_AddressRead);
ans = TWI_read_data_Nack2(); //0x28 - PartNr Upper Register BCD Format (Should return "18" in BCD format - 00011000 = 24 decimal)
TWI_stop();
return ans; //ans returned value gives me this 0b10100101 = 165 decimal
}
Hoping anyone can help!
brg,
Kristian Holm Jensen