AB1805_RK library - getRtcAsTime() not returning current time

I have been using the AB1805_RK library for this watchdog/RTC IC and this appears to be working OK with P2 and Device OS 6.3.0. I have recently got further into a new product where I am using EthernetWiFi network detection and connection during startup. This works however the time isn't being set until the cloud connection is made and to get around this I thought I would use the time from the RTC on AB1805.

If I test first for isRTCSet() being true (the RTC on AB1805 has been set by sync with cloud time service) then I assumed a call to getRtcAsTime() would return the actual time/date being kept by the AB1805 RTC - unfortunately this isn't what it is returning. It appears to be the time when the device was last restarted (and time cloud sync'd) almost as though the AB1805 RTC was not advancing.

Any ideas as to why the AB1805 RTC is not keeping time? The board the P2 is on has a LiPo backup battery so the power should stay on to the IC. Other time details like time zone and DST are stored in the RAM in the AB1805 and this is working fine through a restart.

That is the correct call.

I would enable logging and see the low-level messages from the library. If time is not incrementing after being set from the cloud, it could be an oscillator issue on the AB1805.

Possibly, I am sure that this was working on a previous board spin. Just wanted to check it wasn't a setting. I am wondering if VBAT needs to be connected to 3V3 otherwise the clock doesn't update? Datasheet is a bit vague.

If you are not using VBAT it must be connected to GND. I'm not sure what happens if you don't, but the clock not running is a plausible scenario.

I have experimented with VBAT tied to 3V3 (with the LiPo backup battery) and to GND. In both cases the getRtcAsTime() is returning the last time set (restart time) and not the current time.

This is the schematic - R36 is DNF.

Question - if the AB1805 RTC is not working (I have found it to be a hard IC to use - the data sheet is vague) and there is now the option to use the watchdog on the P2 - do you think I should implement a more reliable RTC like DS3231?

It sounds like your 32kHz crystal isn't starting. The AB1805 has integral resistor and capacitors on the crystal oscillator pins. Have you tried removing C18 and C19? I don't think you need or want them.

2 Likes

Brian - thanks for that observation - I will try removing them and seeing if it then works.

1 Like

Thanks Brian, that's solved that problem!

I'll need to find out why the board designer put the capacitors to ground on each end of the crystal.

The next mystery is connecting NRST on the AB1805 to NRST on P2 stops it starting, at least it was before I removed C18 and C19. Time to retry R36.

1 Like

Solved - designer assumed a 'normal' arrangement with capacitors to ground on either end of the crystal rather than the internal arrangement with the AB1805. Solved.

The start up issue with NRST has also gone away with the removal of the capacitors. Solved.

Device is now able to recover AB1805 RTC time with time zone, DST adjustments immediately at restart!

2 Likes