RTC not incrementing when board is off

I have added the RTC to my project and it has worked perfectly for over a week until recently I noticed that it reset to 0 so I set it in the code to the current timestamp which worked but then I noticed that it is not incrementing when the board is off (when I turn off the board at a certain value of the timestamp then I turn it on it resumes with that last value stored).
I thought it was a battery problem so I changed the battery cell but the problem is still there.
Anyone know what might be the cause of this ?

Thank you.

did you use the compile time and date to set the date? if so, every time you reboot you reset the clock to that time...

post your code for more info + details about your RTC (does it have a battery, is it working, how you wired it, ...)

(can you confirm that your question relates to Portenta Breakout?)

No I set the time and date manually to the current timestamp once then I uploaded a totally different code so it is not resetting to that timestamp everytime. I'm only using the get() function in a loop while and printing the timestamp.

	  // Read the current timestamp from the RTC

	  utcTime = Breakout.RTClock.getTime();

	  // Print the data

	  Serialx.println(utcTime.getUnixTimestamp());

	  Serialx.print("year: ");

	  Serialx.println(utcTime.year() + 1900);

	  Serialx.print("month: ");

	  Serialx.println(utcTime.month() + 1);

	  Serialx.print("day: ");

	  Serialx.println(utcTime.day());

	  Serialx.print("hours: ");

	  Serialx.println(utcTime.hour());

	  Serialx.print("minutes: ");

	  Serialx.println(utcTime.minute());

	  Serialx.print("seconds: ");

	  Serialx.println(utcTime.second());

	  osDelay(1000);

Yes I am using the Portenta Breakout and I have no idea how it is working or wired. I found the example I used it and it worked perfectly until recently.

there is a CR2032 RTC Lithium Battery backup on the break out. Did you check it's in good conditions ?

yes I have just bought a new one and replaced it

is it fully charged? connected in the right way? (I don't think the breakout recharges that battery if you picked a rechargeable model)

Yes it is at 3.3V and it is connected the right way. It is a new battery cell that I just bought, I think there is another problem and I can't seem to figure it out for now

OK - so you are saying this example no longer works (after setting the time once with Arduino_PortentaBreakout/BreakoutRTCSet.ino at main · arduino-libraries/Arduino_PortentaBreakout · GitHub and the correct unix timestamp)

No it works and it sets the time correctly however when I power off the board it stops incrementing so when I turn it back on I get the last value stored of the timestamp

That’s weird indeed. So you see that with the default example to read the RTC, right? (Not custom more complex code)

Yes it is the code that I posted in the reply above. I only use getTime() then I convert to unix timestamp with no additional code

if the CR2032 is fresh and inserted in the right way and you only use the provided examples then indeed the issue is somewhere else - may be hardware. I suppose you don't have another breakout / portenta to compare with ?

No it is the only board I have. I was thinking maybe there is a bit in the RTC registers that can disables it or something and maybe it got changed somehow

if you only used the standard API it should not impact the RTC.

there was a discussion on RTC accuracy a few months back, but not that issue

From a quick read of the datasheet:

the OSF bit is 1 when oscillator is stopped, 0 in normal operation. (so to use only for long time storage without the need of maintaining time).

edit: additionnal info :
image

1 Like

This could be the problem that I have. Any idea on how to access that register in the IDE or using Cube Programmer ?

do you use a library for I2C?

It is a simple write command but it depends how do you "play" with I2C protocol.
I wrote my own library, but it will be something like:

i2c_write_start(I2C_Adresse); // adress of your module
i2c_write_byte(register adress); // adress of the targeted register (0xOF, or just 0F)
i2c_write_byte(data); // the data to write so 0b00001000
I2C_stop;

thoses lines of code won't work in this state, please take time to see write examples for I2C protocol in an actual library!

This is a status bit. It just tells you if the clock lost power and thus you should not trust it’s value.

So it’s not your problem but if you reset it to 0 and you see it is set again then you know the battery likely does not work

hi!
Yet in trouble with your module?
I came back to my weather station project with a nano 33 IOT and a DS32223. For my needs, I use only <wire.h> library and wrote my personnal functions to communicate with the RTC so I have ready sketchs we can use to diag your config.

Keep in touch! :+1:

Yes I am still having the same problem. RTC works fine when the board is ON, I can set it to a different timestamp and I can read its current timestamp that increments every second. However, when I turn the board OFF and wait for let's say 30 seconds then I turn it back ON I find the last value I saw before going OFF and not that value + 30 seconds