Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Arduino RTCZero and M4 boards
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino RTCZero and M4 boards

by jfleischer on Mon Dec 23, 2019 5:22 am

Would it be possible to either have a pull request done for the Arduino RTCZero library to support the metro m4? Alternatively, could a port be done for it? Or, is there a library available that will allow you to manage the M4 onboard RTC? I wanted to use it in my project using a WiFi shield to get ntp updates and such. Thanks!

jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Re: Arduino RTCZero and M4 boards

by User_UMjT7KxnxP8YN8 on Mon Dec 23, 2019 9:48 pm

It isn't a full-blown Arduino library, but I wrote functions to provide access to the ATSAMD51 RTC. You can find my code at https://github.com/SapientHetero/Real-t ... r-ATSAMD51. The example shows how to use it.

User_UMjT7KxnxP8YN8
 
Posts: 276
Joined: Tue Jul 17, 2018 1:28 pm

Re: Arduino RTCZero and M4 boards

by jfleischer on Tue Dec 24, 2019 12:37 am

Excellent! I will take a look after work. Thank you.

However, I hope the option of creating a formal library or updating RTCZero is still on the table. I spent days looking for a solution before I posted here.

jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Re: Arduino RTCZero and M4 boards

by jfleischer on Wed Dec 25, 2019 11:54 am

As a side note, after dinking around in platformio trying to figure out how to get this compiled in, it works beautifully. Thank you.

jfleischer
 
Posts: 15
Joined: Tue May 01, 2018 10:09 pm

Re: Arduino RTCZero and M4 boards

by User_UMjT7KxnxP8YN8 on Wed Dec 25, 2019 2:07 pm

Glad to hear it, and thanks for the feedback.

User_UMjT7KxnxP8YN8
 
Posts: 276
Joined: Tue Jul 17, 2018 1:28 pm

Re: Arduino RTCZero and M4 boards

by Jeremy97469 on Sun Oct 10, 2021 9:32 am

I have 3 examples of the M4 and would like to know about using the built-in RTC. Any suggestions for a more friendly way to use it? Currently using the Arduino IDE.

Jeremy97469
 
Posts: 11
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

by moonie223 on Wed Oct 13, 2021 6:41 pm

What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.

Trying to get the M4 to retain it's backup memory and keep the RTC running full time is more tedious but still possible. Some boards physically can't due to hardware errors, not without forcing the power domain to the main one, check the errata for versions.

The UF2 Bootloader BOD33 fixes to the flash corruption overwrite the BOD33 registers and fuse settings, you just need to disable BOD33 and reconfigure it from the sketch, or you can modify the UF2 bootloader. From there I've been able to get automatic RTC backup working on PB3. Not much of an RTC if it doesn't retain time, at least in my opinion...

moonie223
 
Posts: 48
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

by Jeremy97469 on Thu Oct 14, 2021 2:59 am

moonie223 wrote:What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.

Trying to get the M4 to retain it's backup memory and keep the RTC running full time is more tedious but still possible. Some boards physically can't due to hardware errors, not without forcing the power domain to the main one, check the errata for versions.

The UF2 Bootloader BOD33 fixes to the flash corruption overwrite the BOD33 registers and fuse settings, you just need to disable BOD33 and reconfigure it from the sketch, or you can modify the UF2 bootloader. From there I've been able to get automatic RTC backup working on PB3. Not much of an RTC if it doesn't retain time, at least in my opinion...

Thank you for the information. I was hoping to avoid needing a separate RTC.

Jeremy97469
 
Posts: 11
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

by Jeremy97469 on Tue Oct 19, 2021 2:52 am

moonie223 wrote:What exactly do you want to do with it? Getting it working and setting time at runtime is super easy and the code already provided is a good start. There are several on github, I've got one here https://github.com/deezums/RTC_E51.

Thank you for suggesting the RTC_E51. Finally got a chance to look it over and found that it will work nicely.

Jeremy97469
 
Posts: 11
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

by moonie223 on Tue Oct 19, 2021 10:00 pm

Glad it's working for you!

moonie223
 
Posts: 48
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

by Jeremy97469 on Wed Oct 27, 2021 4:44 am

The example program for "RTC_E51" will not compile for me.
Code: Select all | TOGGLE FULL SIZE
SimpleRTC:4:9: error: no matching function for call to 'RTC_E51::RTC_E51()'
    4 | RTC_E51 rtc;
      |         ^~~
In file included from /var/folders/l3/3ttpb5fx1k1f1c9lh5sp3fjc0000gn/T/arduino_modified_sketch_618601/SimpleRTC.ino:1:
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:38:3: note: candidate: 'RTC_E51::RTC_E51(uint8_t)'
   38 |   RTC_E51(uint8_t calib);
      |   ^~~~~~~
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:38:3: note:   candidate expects 1 argument, 0 provided
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note: candidate: 'constexpr RTC_E51::RTC_E51(const RTC_E51&)'
   24 | class RTC_E51 {
      |       ^~~~~~~
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note:   candidate expects 1 argument, 0 provided
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note: candidate: 'constexpr RTC_E51::RTC_E51(RTC_E51&&)'
/Users/jeremydboyd/Documents/Arduino/libraries/RTC_E51/src/RTC_E51.h:24:7: note:   candidate expects 1 argument, 0 provided
exit status 1
no matching function for call to 'RTC_E51::RTC_E51()'


From the following program:
Code: Select all | TOGGLE FULL SIZE
#include <RTC_E51.h>

/* Create an rtc object */
RTC_E51 rtc;

/* Change these values to set the current initial time */
const byte seconds = 0;
const byte minutes = 0;
const byte hours = 16;

/* Change these values to set the current initial date */
const byte day = 15;
const byte month = 6;
const byte year = 15;

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

  rtc.begin(); // initialize RTC

  // Set the time
  rtc.setHours(hours);
  rtc.setMinutes(minutes);
  rtc.setSeconds(seconds);

  // Set the date
  rtc.setDay(day);
  rtc.setMonth(month);
  rtc.setYear(year);

  // you can use also
  //rtc.setTime(hours, minutes, seconds);
  //rtc.setDate(day, month, year);
}

void loop()
{
  // Print date...
  print2digits(rtc.getDay());
  Serial.print("/");
  print2digits(rtc.getMonth());
  Serial.print("/");
  print2digits(rtc.getYear());
  Serial.print(" ");

  // ...and time
  print2digits(rtc.getHours());
  Serial.print(":");
  print2digits(rtc.getMinutes());
  Serial.print(":");
  print2digits(rtc.getSeconds());

  Serial.println();

  delay(1000);
}

void print2digits(int number) {
  if (number < 10) {
    Serial.print("0"); // print a 0 before if the number is < than 10
  }
  Serial.print(number);
}

Jeremy97469
 
Posts: 11
Joined: Sat Jun 24, 2017 1:25 am

Re: Arduino RTCZero and M4 boards

by moonie223 on Fri Oct 29, 2021 2:14 pm

In RTC_E51.h around line 38...

Change "RTC_E51(uint8_t calib);" to just "RTC_E51();"

I used to compensate the RTC by using the oscillator compensation, some datasheets detail changing it and others don't. I guess I forgot to update the .h file.

I'll try and remember to update github later, RTC mode allows a more traditional, cleaner PPM RTC compensation method.

moonie223
 
Posts: 48
Joined: Sun Feb 05, 2017 2:44 pm

Re: Arduino RTCZero and M4 boards

by Jeremy97469 on Sat Oct 30, 2021 11:18 am

moonie223 wrote:In RTC_E51.h around line 38...

Change "RTC_E51(uint8_t calib);" to just "RTC_E51();"

I used to compensate the RTC by using the oscillator compensation, some datasheets detail changing it and others don't. I guess I forgot to update the .h file.

I'll try and remember to update github later, RTC mode allows a more traditional, cleaner PPM RTC compensation method.

Thank you. I have the example program running on a Grand Central.

Jeremy97469
 
Posts: 11
Joined: Sat Jun 24, 2017 1:25 am

Please be positive and constructive with your questions and comments.