Uno R4 RTC shows zero time on reboot

Using Uno R4 Wifi and testing Real Time Clock. I load the software to set the time and read the time and all is fine. I attach a 3v battery to VRTC and GND pins. I comment out the two lines for setting time and reload the sketch. The RTC stops and displays the same time each second.
If I then press the reset button, the RTC changes to 00:00:00 and does not increase.
I have hunted the internet and Youtube but nothing talks about this.
I have checked the voltage of the CR2302 battery connected to VRTC and it is 3v.
Very frustrating. Please help. Anthony Sullivan

Welcome to the forum

I have moved your topic to a more appropriate category dedicated to the Uno R4 WiFi

I seem to be having trouble seeing these lines that are commented out.
I know how about posting the whole code you have, along with a schematic showing how everything is wired.

I am sure that will help us see your problem.

Also see this near identical problem.

I've experienced the same problem.
As neither posters on the two threads are forthcoming with their sketches, here is the one that I have tried.
It comes from the Uno R4 WiFi RTC tutorial.

#include "RTC.h"

void setup() {
  Serial.begin(9600);

  RTC.begin();

  RTCTime startTime(18, Month::AUGUST, 2023, 14, 00, 00, DayOfWeek::FRIDAY, SaveLight::SAVING_TIME_ACTIVE);

  RTC.setTime(startTime);
}

void loop() {
  RTCTime currentTime;

  // Get current time from RTC
  RTC.getTime(currentTime);

  // Print out date (DD/MM//YYYY)
  Serial.print(currentTime.getDayOfMonth());
  Serial.print("/");
  Serial.print(Month2int(currentTime.getMonth()));
  Serial.print("/");
  Serial.print(currentTime.getYear());
  Serial.print(" - ");

  // Print time (HH/MM/SS)
  Serial.print(currentTime.getHour());
  Serial.print(":");
  Serial.print(currentTime.getMinutes());
  Serial.print(":");
  Serial.println(currentTime.getSeconds());

  delay(1000);
}

After uploading the sketch to the Uno and starting the RTC, I commented out the line RTC.setTime(startTime), and recompiled.

This is the result on the serial monitor:

After recompiling the clock has stopped, but retained the time.

If the power is removed, and reinstated, then the date and time get reset to 1/1/2000 - 0:0:0.

The same thing happens whether or not the VRTC pin has +3.6 V applied (from a power supply).

Has the power supply got a common GND with the Uno ?

Yes it has a common ground.

I used the GND pin annotated in the picture above, but have checked for continuity to the other GND pins.

If I remove the supply, then the voltage on the VRTC pin falls off as expected. (The time constant of oscilloscope X10 probe and C8 on the PCB is 10MΩ x 100nF = 1s).

The problem occurs whether or not there is a voltage applied to the VRTC pin.

I've just checked, and the Uno R4 Minima (which has no facility for connecting a backup battery/power supply) behaves the same.

Hi John, Yes exactly what I am experiencing. Such strange behaviour. I hope somebody can find a solution. I wonder if we should use a different library?

Hi John, One more issue that needs sorting is how to get Computer System Time into Arduino to set the RTC. That way you would not need to set the time manually every time you upload the software.

Take a look at using __DATE__ and __TIME__

They give you the date and time of compilation

One of the examples in the IDE uses a similar technique.
"RTC_AutomaticExample" uses 'TIMESTAMP'.

There is a comment in the example that says they don't use 'DATE' and 'TIME' because they don't give you the day of the week.

How come UKHeliBob can write __DATE__ and __TIME__, but if I type it , it comes out as 'DATE' and 'TIME'?

Because the double underscore is interpretted as the tag for bold

Put the __DATE__ and __TIME__ in single backticks to have them interpreted as formatted text so that further interpretation does not take occur

Thank you - I was using a single inverted comma, I wasn't aware of the backtick.

Hello John, Thanks I think we have established that there is either a fault on the UNO R4 board or we need a different Sketch to make the onboard RTC work properly. Do you think Arduino plan to do anything about this soon?
Thanks also for the hint on getting the time the Sketch is compiled. It is only about ten seconds later than the actual computer time when it starts running. Still there should be a way to get actual computer time when the Sketch is actually running. Thanks Anthony

I have the same problem with this board, but also with the Portenta C33 mounted on the Portenta Breakout with a fresh/new CR2032 battery installed in the battery holder.
(Portenta C33 is also based on a Renesas chip - RA6M5).

I know that these boards are relatively new to the market, but it is too poor to promote functions that do not work or are not fully developed.

I look forward to a solution to the RTC and backup battery problem.

If it can be of any help, I am ready to try various software based solution attempts, with both my boards.

I've experienced similar bugs with the Uno R4 WiFi's real time clock (RTC) as anthonyalansullivan's original post. The RTC example sketch RTC_NTPSynch works like a charm to set the clock, but I failed to read time/date with subsequent simple sketches designed to only read the already-set RTC. Here's my simple sketch loaded after running RTC_NTPSynch:

#include <RTC.h>

void setup() {
  Serial.begin(9600);
  while(!Serial);
  RTC.begin();
}

void loop() {
  delay(5000);
  if(!RTC.isRunning()){
    Serial.println("RTC Not Running?");
  }
  RTCTime currentTime;
  RTC.getTime(currentTime); 
  Serial.println("The RTC says: " + String(currentTime));
}

The first time running this sketch, the serial monitor displays:

RTC Not Running?
The RTC says: 2023-08-27T15:14:45

every 5 seconds.

Then something really weird happens. ...Hit the reset button on the Uno to run the same sketch and the output changes to:

RTC Not Running?
The RTC says: 2000-01-01T00:00:00

every 5 seconds.

I think that the if(!RTC.isRunning()) statement is diagnostic.

I should probably add that the USB-C connection to my PC powered the board the whole time. … hadn’t messed with the RTC battery backup yet.

Try this Arduino UNO R4 WiFi VRTC & OFF Pins

Per NightTrain's last point... The UNO stays powered and the RTC gets cleared. I've also powered it from the on-board 3.3V supply. Bluntly... the RTC state does not survive a reset. Please tell us: Is there a design flaw, Is there a work around, or When will it get fixed. You guys should be able to be exactly clear about this.

Best,

Rich

Thanks for your response. Given your thoughts I've done the following to clear the BPWSWSTP:

R_SYSTEM->PRCR = 0xA502 | (R_SYSTEM->PRCR & ~0x02);       // Write enable VBTCR1  
R_SYSTEM->VBTCR1 = R_SYSTEM->VBTCR1 & ~0x01;                  // Turn off BPWSWSTP
R_SYSTEM->PRCR = 0xA500 | (R_SYSTEM->PRCR & ~0x02);       // Write protect VBTCR1

That is happening but the problem still exists. The strange thing is I can set the date/time via RTC and it survives ONE reboot but not a second. I think I'll try this on Minima to see if the ESP32 is doing something strange - like double resetting while BPWSWSTP is high...

Best,

Rich