Rv3028 rtc

Can anyone offer advice about the correct way to use the RV3028 RTC?

I’ve written a simple class in Python that requires the Backup Switchover Mode to be set on initialisation, and it’s initialised to Level Switching Mode.

I then write the current time, date and weekday into registers 0x00 to 0x06

The RV3028 then keeps good time. The time and date are usually restored successfully after a power cycle but not every time. About 1 out of 3 power cycles results in a reset to factory values.

Have I missed a critical configuration step or is it possible this is a hardware/battery issue?

Any ideas welcomed!

It’s a love hate relationship for me. I have a couple that are rock solid and some that just seem to randomly stop working.
I set mine up as follows.
Enable i2c via raspberry Pi Configuration and reboot.
Then run sudo pip install rv3028
Then I run set-time.py and then get-time.py from examples folder
That sets the battery backup in the correct mode, as far as I understand anyway.
Then I open a terminal window and run sudo i2cdetect -y 1
The RV3028 shows up as 52
Then I edit the config.txt sudo nano /boot/config.txt and add
ctrl x, y, enter and sudo reboot

Then open the terminal window and run sudo i2cdetect -y 1
The 52 is now UU which means its under system control.

Next disable the “fake hwclock” which interferes with the “real” hwclock

sudo apt-get -y remove fake-hwclock
sudo update-rc.d -f fake-hwclock remove
sudo systemctl disable fake-hwclock

Now with the fake-hw clock off, you can start the original ‘hardware clock’ script.

sudo nano /lib/udev/hwclock-set
and comment out these three lines:

if [ -e /run/systemd/system ] ; then
exit 0

Also comment out the two lines

/sbin/hwclock --rtc=$dev --systz --badyear
/sbin/hwclock --rtc=$dev --systz

ctrl x, y, enter

Sync time from Pi to RTC

sudo hwclock -w
sudo hwclock -r

sudo reboot