RTC crystal required?
kriswiner opened this issue · 9 comments
Just curious if this requires a 32.768 kHz crystal on RTC pins 32 and 33 and uses the internal RTC hardware and SDK native RTC functions to implement RTC time keeping, or is this simply a fancy timer based om the HSE?
Lore is that managing an RTC on the ESP32 requires the SDK. SO another way to ask my question is, is this an Arduino wrapper for an SDK RTC function?
In any case, it seems to work, so thanks for the library!
Yes, this is a wrapper library for RTC functions on ESP32
On Arduino, there is no way of changing the clock source unless by recompiling the libraries. This library uses the default which is the internal 150kHz RC oscillator
. The 32.768kHz crystal is not required unless you change the clock source.
I plan to play with this as well.
If the RTC keeps running in deep sleep mode it would be awesome.
It is awesome: snippet
The only issue is why it takes 5010 millisecs to get the time from the RTC (it might be my board).
Apparently, the full signature of getLocalTime is
bool getLocalTime(struct tm * info, uint32_t ms)
with a default value of 5000 ms.
The purpose is pretty obscure:
bool getLocalTime(struct tm * info, uint32_t ms)
{
uint32_t start = millis();
time_t now;
while((millis()-start) <= ms) {
time(&now);
localtime_r(&now, info);
if(info->tm_year > (2016 - 1900)){
return true;
}
delay(10);
}
return false;
}
Seems like the RTC might not have been reliable and keep reading until the year returns in the 1900-2016 range.
Opening a bug there.
No, this seems to be a bug in the code. Clearly they are expecting a date range that is wrong (2016?).
But I reduced the latency to 10msec by forcing 0 as second parameter. It works great, no recompilation.
still like your idea of an external crystal but I am afraid it might require GPIO pins so I don't think it will survive a deep sleep.
Interesting topic, I want to dig more.
(I updated the snippet to the bare minimum)
the getLocalTime()
function is taken from esp32-hal-time.c
which is used in the SimpleTime example.
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time"); // time is less than 2016, ie. not set
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}
The RTC time is considered not set if the time is below the year 2016 since it starts counting from the year 1900
You are right, you can close this issue then
Thanks! I didn't even know the ESP32 had an RTC. How convenient.