RV3028 not keeping correct time

It looks like I may have a bad RV3028. It was working fine as near as I can tell but is now unreliable after doing a config txt edit dtoverlay=i2c-rtc,rv3028,backup-switchover-mode=1.

It now craps out if left for any amount of time. I booted up that Pi yesterday and the time was off. And running sudo hwclock -r gets me that error message.
hwclock: ioctl(RTC_RD_TIME) to .dev/rtc0 to read time failed: invalid argument
I reset it to the correct time, and tested it once. After about a 15 minute shutdown with no power to the Pi it was Ok. But after leaving it unpowered overnight its not working anymore. It showed yesterdays time and hwclock -r gets me that error message above. Bad battery maybe? I powered down and swapped in my other RV3028 and it read the correct time. I didn’t have to do anything. I had checked this second one yesterday and its been sitting unplugged since then. This Pi is not connected to the internet. I’m going to leave the second RV3028 in and power down, then check it in a few hours. If it works its likey a hardware issue with the other one. If it doesn’t its software I guess?

It appears to be a dud battery. It tests in the red on my battery tester set for 1.5V coin cells. I’ll have to have a look for one at a pharmacy etc. And do some more tests with a new one inserted in its place.

That sounds right.
The first day in tech school they told us: “Always verify your power source”. Meaning, is it plugged in? ;)

I only just got it in November, just bad luck I guess.

Yeah but you don’t know how long it was on the shelf before you got it.

There may be a date code on the battery.

According to the product page the battery has a shelf life of 5 years, and should be good for ~ 3 years of use. Like everything else though thats not etched in stone. Best guess is I got a dud battery. I have a Ds1307 I bought years ago thats till working just fine with its original battery. Luck of the draw etc.
I took the battery from my working RV3028 and swapped it into the RV3028 that had the bad one. Latter on today I’ll have a look see to see if it now works Ok. A failure on the RV3028 could in theory drain the battery so I’ll just have to wait and see how it works over time to be 100% sure it was just a dud battery.

It may also depend on how much time the Pi is off. I believe the Pi supplies voltage to the clock (turning off the battery) when it’s on, saving the battery.

I have an old Casio plastic watch that has been running for at least 15 years. The battery was rated for 10. But I never use the light or beeper so it uses almost no juice. Amazing.

The actual RV3028 is also faulty. I just booted that Pi up and it was showing the time that it was shut down at.
And running sudo hwclock -r gets me that error message.
hwclock: ioctl(RTC_RD_TIME) to .dev/rtc0 to read time failed: invalid argument.
The battery that is in it measures in the green / good.
The one that originally was in it measures in the Red / bad.
I just put the good battery in the good RV3028 for one last long downtime check. I’ll leave it off overnight and check it tomorrow some time.

I’m starting to chase my tail now. =( Neither one is working and I’m not sure which one is which anymore. Going to have to put a mark on one with a sharpie or something.
It doesn’t matter which one is in, on a reboot after sitting unpowered for a while the time is off and sudo hwclock -r gets me that error message. I’m starting to wonder if I have the battery in upside down or something? There are no marks to say which way it goes in and the product page doesn’t say?
I’m just about to ready wipe my SD card and start all over again.

Phil @gadgetoid help please!!

The + up is the correct way. I remarked out the rtc dtoverly entry in config.txt and rebooted. That gets control back to me and lets me run the Pimoroni set time get time python files. They both work and the one thats plugged in right now is keeping its time. I’m going to check it one more time after I’m done reflashing my SD card. That Pi has the power supply unplugged. Looking at the python code it only uses the battery if Vin drops below 2V. There is a note to that effect in the set time and get time files. It will have been siting for 30+ minutes with no power. I’ll reinstall the Pimoroni software, and check it again to see if it has kept time. Then swap the battery over to the other one and wash rinse and repeat.

EDIT: So far so good, both RV3028’s are keeping thier time. For 30+ minutes anyway. My next step is to leave the Pi unplugged tonight and check it tomorrow some time. I’m going to try and leave it idle with no power for at least 12 hours. If that breakout checks out OK I’ll swap the battery over to the other one, set the time in it, and leave it sit unpowered overnight. If it also works that means all I need is a battery. And to sort out how to actually set it up as a RTC in Raspbian.

I hope it all works out.

Two steps back, one step forward, lol. This all started after doing that dtoverlay edit to add that backup-switchover-mode=1 option. It may just be a coincidence, not sure?
I should go see what that option actually does I guess.
According to this, its not what caused my issue.
https://github.com/raspberrypi/linux/blob/0d72d83ec92acda1e8cbad0d4213a5ec2b3f2e1b/arch/arm/boot/dts/overlays/README#L1079

backup-switchover-mode Backup power supply switch mode.
Must be 0 for off or 1 for Vdd < VBackup (RV3028 only)

Disturbing a working system is always a risk. ;)

It’s my breadboarding rig, its what I use to setup new breakouts etc. It had a DS3231 already setup on it. I likely could have just made one small config txt edit and swapped the RV3018 in its place, but I wanted to go with a clean install and do it all from scratch. It also has my other two breakout garden breakouts on it. The Light level sensor and the UV light sensor.
Anyway, just having my first cup of java and getting ready for my morning walk with my dog. When I get back I’ll check to see if the RV3028 kept time or not.

One down one to go. This one RV3028 kept its time overnight. I’m just checking it with the python files for now, no way for the OS to mess it up on me. I just swapped the battery and set the second one to the correct time and turned off the WIFI. I’ll let it sit overnight and check it tomorrow. Once i sort if it’s OK or not I’ll set one of them up as a RTC for Raspbian.

Step by step. I hope all goes well.

I’m making some headway. The other RV3028 also kept its time. Time to set it up to pass the time to Raspbian. I am going to do the dtoverlay=i2c-rtc,rv3028,backup-switchover-mode=1 option as I think its required to extend the life of the battery. Maybe thats why the other battery died? I was using dtoverlay=i2c-rtc,rv3028

I’m pretty well back to where I was after the two steps back.
I did the dtoverlay=i2c-rtc,rv3028,backup-switchover-mode=1 config.txt edit and rebooted.
hwclock -r showed the correct time.
I left it unpowered for a couple of hours and booted it up to check it again.
Running hwclock -r now gets me that same error message I got the first time around.
hwclock: ioctl(RTC_RD_TIME) to .dev/rtc0 to read time failed: invalid argument.
I then remarked out the dtoverlay entry, rebooted, and ran get time py file.
It showed as 1st of Jan 2000 and the time was counting up from 0 seconds.
If I do a hwclock -w and then a hwclock -r it reads out the time that was saved with no error message

I think at this point I’m going to reflash my SD card with a clean Buster image, put my DS3231 in place, and set that up via the Adafruit tutorial.

Hopefully on Monday I can get some feed back from somebody that works at Pimoroni on how to get this working? I’m leaning back to this being a result of the backup-switchover-mode dtoverlay entry?

I setup my DS3231 with the steps I listed in the other thread. Checked it a couple of times and it was working and keeping an accurate time.
I then removed its dtoverlay entry in config.txt and replaced it with one of the RV3028’s. Installed the python stuff, ran set time and get time, all good.
I then edited config.txt and added dtoverlay=i2c-rtc,rv3028, like I had done the first time around and the one time I had it working reliably. The 52 changed to uu in i2cdetect -y 1. running hwclock -r worked and read back the correct time. So far so good, don’t want to get to excited though, not just yet.
Now its another wait and see. I turned off the WIFI and shut down and removed power. I’ll wait an hour or so and check it. If its OK I’ll shut it down for the night and have another check tomorrow some time.

So far so good it is working. I left it shut down with the power supply unplugged overnight 12+ hours and it was working when I checked it moments ago. I booted it up with no Internet connection and the time was accurate.
And running sudo hwclock -r worked with no error message.
I’m going to hold off testing my second RV3028 until I can get a replacement battery for it.

IMHO until told otherwise by somebody from Pimoroni I would “not” add the backup-switchover-mode=1 to the config.txt dtoverlay entry, just use the following.
dtoverlay=i2c-rtc,rv3028
If you run the python set time file before making that config.txt edit it will work. It will set the time and put the battery in the correct backup mode. Once you make that entry and reboot, you can use sudo hwclock -w and sudo hwclock -r.