Hi! I'm trying to get the real time clock to work on my Giga. I have only found one example (original Arduino example):
#include "mbed.h"
#include <mbed_mktime.h>
constexpr unsigned long printInterval { 1000 };
unsigned long printNow {};
void setup() {
Serial.begin(9600);
RTCset();
}
void loop() {
if (millis() > printNow) {
Serial.print("System Clock: ");
Serial.println(getLocaltime());
printNow = millis() + printInterval;
}
}
void RTCset() // Set cpu RTC
{
tm t;
t.tm_sec = (0); // 0-59
t.tm_min = (52); // 0-59
t.tm_hour = (14); // 0-23
t.tm_mday = (18); // 1-31
t.tm_mon = (11); // 0-11 "0" = Jan, -1
t.tm_year = ((22)+100); // year since 1900, current year + 100 + 1900 = correct year
set_time(mktime(&t)); // set RTC clock
}
String getLocaltime()
{
char buffer[32];
tm t;
_rtc_localtime(time(NULL), &t, RTC_4_YEAR_LEAP_YEAR_SUPPORT);
strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t);
return String(buffer);
}
and this leads to a crashing of the Mbed OS - notice that nothing is connected, I just wanted to try it before connecting a battery and other stuff... Double tapping it and loading a different script works fine... Can anyone provide some help?