RTC - RV-1805 - Receiving PartNr 165 back

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! :slight_smile:

brg,

Kristian Holm Jensen

Hello Kristian,

Unfortunately, SparkFun Tech Support cannot help debug custom code but I can try to point you to a couple of resources that may help you troubleshoot this issue. Here is a link to the [RV1805 Begin Function from our [Arduino Library. The [header file might also help you out here.

If possible, try using the Qwiic RTC with an Arduino and our examples to make sure your RTC is working properly.](SparkFun_RV-1805_Arduino_Library/src/SparkFun_RV1805.h at master · sparkfun/SparkFun_RV-1805_Arduino_Library · GitHub)](GitHub - sparkfun/SparkFun_RV-1805_Arduino_Library: A SparkFun Arduino library for the extremely low power, very precise, and highly configurable RV-1805-C3 Real Time Clock from Micro Crystal.)](SparkFun_RV-1805_Arduino_Library/src/SparkFun_RV1805.cpp at master · sparkfun/SparkFun_RV-1805_Arduino_Library · GitHub)

Dear Mark,

thank you for your feedback, most appreciated!

The libraries you have referenced are the ones I am using as “guideline”, still without luck though.

You have any contact details to vendor tech-support for this?

Anyway, thank you for replying! :slight_smile:

Best Regards,

Kristian H Jensen

Hi Mark,

NB: I made a rookie mistake left shifting the I2C address by one. The I2C read and write addresses given in the documentation are the full 8bit read/write address, not the 7bit.

#define RTC_Address 0xD2
#define RTC_AddressRead  (RTC_Address << 1) | 0x01 //ERROR --> Shall not be left shifted, as 0xD3 is itself the 8bit Read Address to use
#define RTC_AddressWrite (RTC_Address << 1) | 0x00  //ERROR --> Shall not be left shifted, as 0xD2 is itself the 8bit Write address to use

Everything worked nicely once I figured this out.

Thank you for your feedback!

Brg,

Kristian H Jensen

Good catch! I’m glad everything is working as expected now.