Hello,
I'm working with Espressif-IDE and framework 5.3.1. I am able to get the updated time from SNTP and have it written to the ESP32 RTC. And I can also retrieve individual elements of the RTC time using specifiers in the strftime function, for example
strftime(MY_TIME, sizeof(MY_TIME), "%I:%M%p", &timeinfo);
or
strftime(MY_HOUR, sizeof(MY_HOUR), "%I", &timeinfo);
The problem I have is ultimately I am using an external RTC chip for my timekeeping, MCP79510 over SPI. This too is working fine. I can read the individual registers, create a string and write it to my oled display.
The external SPI RTC needs to have the data written to each register as uint8_t values. But the values retrieved from the internal RTC are string values. How can I get for example the HOUR value as a uint8_t to be able to write it to the external RTC?
Order of operation:
Get SNTP time > write to internal RTC > read internal RTC individual elements (HOUR, MINUTE) > write uint8_t HOUR,MINUTE to external RTC.
In Arduino, I can see there are functions such as getMinute(), getHour() but I see nothing in ESP-IDF that does the same.
Any help is appreciated, going nuts trying to figure it out.
Getting Hour and Minutes from ESP32 RTC
-
- Posts: 32
- Joined: Tue Feb 05, 2019 5:26 pm
Re: Getting Hour and Minutes from ESP32 RTC
I think I may have found an answer, but need to test more.
I did
uint8_t hrt = timeinfo.tm_hour;
and then to test I printed
ESP_LOGI(TAG, "The formatted int hour is : %d", hrt);
And it printed the correct value of the current hour that was stored in the internal RTC. Does this make sense?
I did
uint8_t hrt = timeinfo.tm_hour;
and then to test I printed
ESP_LOGI(TAG, "The formatted int hour is : %d", hrt);
And it printed the correct value of the current hour that was stored in the internal RTC. Does this make sense?
-
- Posts: 1821
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Getting Hour and Minutes from ESP32 RTC
Probably. Impossible to tell without knowing what your "timeinfo" is (struct tm?) and, more importantly, how you got the data into it.
You may want to check <time.h>.
-
- Posts: 32
- Joined: Tue Feb 05, 2019 5:26 pm
Re: Getting Hour and Minutes from ESP32 RTC
The internal RTC is written into by the example SNTP code of the ESP-IDF. The timeinfo is the structure used to get the internal RTC data. The structure has members for year, hour, minutes... that are accessible by reading .tm_year, .tm_hour, .tm_min...etc...
The good thing is I can get the data. The bad is now I'm stuck again because the external RTC is expecting BCD data to be written to the registers. I'll be making another post for that.
The good thing is I can get the data. The bad is now I'm stuck again because the external RTC is expecting BCD data to be written to the registers. I'll be making another post for that.
-
- Posts: 1821
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: Getting Hour and Minutes from ESP32 RTC
Code: Select all
uint8_t bcd = ((value / 10) << 4) | (value % 10);
Who is online
Users browsing this forum: calvong, Google [Bot] and 64 guests