How I can read directly RTC register in ESP32-S3

wegi01
Posts: 2
Joined: Mon May 11, 2026 8:25 am

How I can read directly RTC register in ESP32-S3

Postby wegi01 » Mon May 11, 2026 10:06 am

Hello,
Greetings for all ppl here. This is my first post and thread.

I don't know what I'm doing wrong bcos I can't properly read RTC LO/HI registers. Also here exists unresolvet this thread:
viewtopic.php?t=18013

example of my code:

Code: Select all

#include "soc/rtc_cntl_reg.h"

        //---
        SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
        uint32_t rtc_timestamp_low = READ_PERI_REG(RTC_CNTL_TIME0_REG);
        uint32_t rtc_timestamp_high = READ_PERI_REG(RTC_CNTL_TIME1_REG);
        time_t rtc_epoch;
        time(&rtc_epoch);

        Serial.printf("\n\n==========================================================\n");
        Serial.printf("rtc_timestamp_low = %d\n", rtc_timestamp_low);
        Serial.printf("rtc_timestamp_high = %d\n", rtc_timestamp_high);
        Serial.printf("RTC value of time_t rtc_epoch = %d\n", rtc_epoch);
        Serial.printf("==========================================================\n\n");
        //---
Output console show, how the high RTC register is allways 0:

==========================================================
rtc_timestamp_low = 38456010
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021110895
==========================================================
I wonder what is wrong bcos the system time() and any RTC functions working flawlesly and they must reading of RTC registers.

If anyone know how to read low level RTS registers in ESP32-S3 pleasse let me know here.
Thank you in advance.

wegi01
Posts: 2
Joined: Mon May 11, 2026 8:25 am

Re: How I can read directly RTC register in ESP32-S3

Postby wegi01 » Mon May 11, 2026 4:51 pm

Ok...

What I did and what I understand:

Code: Select all

  #include "soc/rtc_cntl_reg.h"
  LVGL_Timer = xTimerCreate("LVGL_Timer", pdMS_TO_TICKS(128000), pdTRUE, (void *)0, LVGL_Timer_Callback);
  extern uint32_t last_read;
  SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
  last_read = READ_PERI_REG(RTC_CNTL_TIME0_REG);
  xTimerStart(LVGL_Timer, 0);

Code: Select all

uint32_t last_read = 0;
//===================================================================================================================
void LVGL_Timer_Callback(TimerHandle_t xTimer)
{
     //---
    SET_PERI_REG_MASK(RTC_CNTL_TIME_UPDATE_REG, RTC_CNTL_TIME_UPDATE);
    uint32_t rtc_timestamp_low = READ_PERI_REG(RTC_CNTL_TIME0_REG);
    uint32_t rtc_timestamp_high = READ_PERI_REG(RTC_CNTL_TIME1_REG);
    time_t rtc_epoch;
    time(&rtc_epoch);

    Serial.printf("\n==========================================================\n");
    Serial.printf("rtc_timestamp_low = %d\n", rtc_timestamp_low);
    Serial.printf("rtc_timestamp_high = %d\n", rtc_timestamp_high);
    Serial.printf("RTC value of time_t rtc_epoch = %d\n", rtc_epoch);
    Serial.printf("Ticks per seconds = %d\n", ((rtc_timestamp_low - last_read) >> 7));
    Serial.printf("==========================================================\n");
    last_read = rtc_timestamp_low;
    //---
}
//---
Output terminal:
==========================================================
rtc_timestamp_low = 1084964449
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021133799
Ticks per seconds = 130399
==========================================================

==========================================================
rtc_timestamp_low = 1101659100
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021133927
Ticks per seconds = 130426
==========================================================

==========================================================
rtc_timestamp_low = 1118352170
rtc_timestamp_high = 0
RTC value of time_t rtc_epoch = 1021134055
Ticks per seconds = 130414
==========================================================
In the ESP32 doesn't exist physically RTC register. Here exist 48bit counter of low speed clk which after reset is choosed internal low speed clk:

Code: Select all

// On esp32s3, RC_SLOW_CLK has a freq of ~136kHz
#define SOC_CLK_RC_SLOW_FREQ_APPROX    136000
// '150K' does not mean the actual freq, it represents the clock source is RC_SLOW_CLK. RC_SLOW_CLK has a freq of ~150kHz only on esp32.
#define RTC_SLOW_CLK_FREQ_150K      SOC_CLK_RC_SLOW_FREQ_APPROX
And in the ROM is created programmatically RTC and all POSIX functions like time(), mktime(), settimeofday() and so on... these functions are build and working with this programming make RTC.

High 16bits of low speed clk timer will increase after arround 9,15hours.

Completly another way and subject it's put the epoch time in the (virtual) RTC registers or update (increase) it after every one second all the time, what is doing by procedures implemented in ROM.


After reset these two rtc low speed clock registers are set as "0". These two registers only counting jitter low speed RTC clock. They are not directly RTC.

Who is online

Users browsing this forum: meta-externalagent, Semrush [Bot] and 18 guests