How to correct the UNO R4 RTC time difference

As you all know, Arduino UNO R4 does not have an external crystal oscillator, so when using RTC, the time lags by about 10 minutes a day.
There were many discussions by various people, which were very helpful.

I first switched the main clock (MOCO) to an externally attached crystal and looked at the RTC, but the deviation was the same.

Next, I tried to correct the RTC using the clock error correction register (RADJ), but the data sheet says that RADJ cannot be used with the internal clock (LOCO 32.768 kHz).

And I installed an external crystal (32.768 kHz), but I couldn't figure out how to switch the clock source in the sketch.

Finally, I rewrote "define RTC_CLOCK_SOURCE RTC_CLOCK_SOURCE_LOCO" on line 455 of RTC.cpp to "define RTC_CLOCK_SOURCE RTC_CLOCK_SOURCE_SUBCLK".
As a result, the time difference became less than 1 second per day.

So, my question is,
1 is it possible to switch the clock source by manipulating registers in the sketch without rewriting RTC.cpp?

2 Is there a way to check the settings of registers such as clock source in Arduino IDE?

I'm using Google Translate.

check - Can we fix the RTC?

No

Yes.

thank you for your reply.
I'm not familiar with this forum so I apologize for the inconvenience.

I'm currently checking a UNO R4 with an external clock installed and a CR2032 installed as a backup. I attach and check the USB cable once every few hours, and there is no deviation.

Currently, there are 38 articles that describe RTC in the UNO R4 category, which I found very helpful.

Among them, I often read "Can we fix the RTC?" and "UNO R4 WiFi RTC runs fast by about 1 second per minute."
In particular, "Can we fix the RTC?" How to measure and correct the LOCO frequency is very nice.
I verified on the actual device that the clocks that can be used with RTC are SOSC and LOCO, and that the RADJ register is for SOSC, as stated in this article.

Then, I tried adding an external subclock as an easy way to eliminate the RTC discrepancy. At that time, I was unable to switch the clock other than by rewriting RTC.cpp, so I asked this question.
The result turned out to be NO.

Let me requalify that answer. I suppose you could always write your own RTC code and not use RTC .h at all. But if you want to use RTC.h then you will have to modify that library.

Thank you for reading my post and replying.

In order to correct RTC, in addition to adding an external clock using hardware, it seems that there is also a method of correcting with CAC that you came up with, and a method of rewriting "freq_compare_value_loco = 255" in RTC.cpp.

I look forward to seeing new ways you come up with.

I hate to say it probably won't be me. I've given up hope on the RTC for the R4. I'm not going to go through the bother of adding a crystal to the Minima. I'm mostly working with the R4 WiFi and it doesn't have the option.

If you add an external crystal for SOSC then you shouldn't need any correction. If you do then you chose the wrong crystal. Consult the datasheet. I believe there is one register to change to swap the RTC source to SOSC. Since LOCO and SOSC run at the same speed I think that's the only change you'll need.

Have a look at the hardware modifications in this thread:

Hi,

Where the heck is the RTC.cpp located for the Arduino R4? I've tried the usual hiding spots. Can you help?

Thanks,

Robert

.arduino15/packages/arduino/hardware/renesas_uno/1.0.4/libraries/RTC

Thanks. Not easy to find when it's hidden like that!

I was wondering if you have a picture of the 32 kHz crystal connected to RA4M1? How on earth can you connect anything to that SMD chip without destroying it with blobs of solder?!

I have the UNO R4 WiFi, but I think that using the NTP protocol library to keep the RTC updated once a minute is probably the only "easy" way to fix this horrendous design error. Heck, even the lowly DS1307 keeps better time! I'm hoping that Arduino realizes the mistake and fixes the issue in a harware upgrade or perhaps someone will come up with a plug-in board fix.

I've been using the excellent DS3231 with TCXO with my R3 and it keeps amazing time even in cold temps and high temps.

Thanks once again for the information.

Regards,

Robert

That's the way to go with the R4 as well.

Adding the crystal can be done on the Minima as there are solder pads on the board for it. It would be pretty close to impossible on the WiFi.

I wrote that I was using an external crystal oscillator, but that's not exactly true.
For comparison, I separately purchased a board equipped with "RA4M1" that comes with a crystal oscillator.
It's called "WeActStudio RA4M1 CoreBoard" and I bought it on Aliexpress. This board comes with a main and sub crystal oscillator, a VBATT terminal, and can be purchased for less than $10.
The genuine UNO R4 Minima is used for comparison without modification.

I am currently conducting two experiments.

One is a regular R4 Minima, which modifies the RTC without an external crystal.
I found Renesas's document "RTC AUTOMATIC ADJUSTMENT LOCO EXTERNAL SUB CLOCK" and learned that the built-in clock (LOCO) can be modified using the "RFRL register", so I changed ".freq_compare_value_loco = 255" in RTC.cpp. I tried this, but I could only get it down to about 2 minutes in a day.

The other uses RTC with an external clock. This is working without any problems.
By using VBATT and backing up with a CR2032 battery, the time can be maintained without error even if the power is turned off for more than a week.

A friend of mine found a way to switch the RTC clock within the Arduino IDE sketch.
This blog also describes how to correct errors in external clocks and how to check the clock by taking it outside.

My question was resolved on March 8, 2024.

If you are interested in the content, please visit the website below, which is in Japanese.

By the way, to check the clock source, you can view the contents of the register with "R_RTC->RCR4".
To correct clock errors, use the "R_RTC->RADJ" register.

Note that this only works when using SOSC as the clock source. Under normal circumstances when the LOCO clock is driving the RTC the RADJ register is disabled.

Note the very last sentence here.

1 Like

It's exactly as you say.

RADJ registers are not available in LOCO.
"To correct clock errors, use the "R_RTC->RADJ" register." was incorrectly translated.

To fix clock errors when switching the clock to SOSC as described in this Japanese blog, use the "R_RTC->RADJ" register.

On Radio Pliers' website, it was possible to adjust the frequency register (RFRL) and LOCO's trim register within 1 minute per day without modifying the Arduino UNO R4.

Details are available on this Japanese blog.

Now I can use the RTC of Arduino UNO R4 as I want, I will summarize the method in order.

In addition, all the information was thought up by Mr. Radio Pliers in March 2024.
Feel free to try it out yourself, but please don't say you came up with it when you publish it.

  1. How to output a signal from the pin and check it with a counter to check the error of the oscillator of your Arduino UNO R4
    http://radiopench.blog96.fc2.com/blog-entry-1274.html

  2. The RTC of unmodified Arduino UNO R4 has an error of about 10 minutes per day.
    Adjusting the RFRL register can correct that error within a few minutes.

  3. By combining the RFRL register and LOCO trim register, the daily difference can be adjusted within 1 minute.
    ラジオペンチ Arduino UNO R4 のRTCの誤差を限界まで補正(内蔵CRオシレーター)
    This can be done without modification.

For RTC clock adjustment, please see Renesas's "RTC AUTOMATIC ADJUSTMENT LOCO EXTERNAL SUB CLOCK".

  1. If you install an external crystal, the difference can be kept within 1 second per day.
    See here for a sketch to switch the clock.
    ラジオペンチ Arduino UNO R4のRTC、クロックソース切替と精度測定

For information on how to install a crystal resonator, please see Renesas's "R01AN7202EJ0100".

  1. The error of the external oscillator can also be adjusted by using the sketch. Please check here.
    ラジオペンチ Arduino UNO R4 のRTCの外部水晶の誤差を補正

All procedures are also maintained with backup batteries.

Please note that Mr. Radio Pliers, who came up with this information, has no plans to create an English website.
We apologize for the inconvenience, but please use a translation tool such as Google Chrome.