Maximum ESP32-S2 Deep Sleep Duration

art4evs
Posts: 5
Joined: Thu Feb 03, 2022 10:14 am

Maximum ESP32-S2 Deep Sleep Duration

Postby art4evs » Wed Mar 09, 2022 9:55 pm

Using 'esp_sleep_enable_timer_wakeup()' with an 'unsigned long long' constant, what is the highest value that can be passed and still have wakeup work properly? In other words, what's the longest possible duration of deep sleep? I've looked everywhere I can think to for this and can't find it, but I assume it's some number of bits on a 32.768kHz timebase (32/48/64?), which would correspond to the standard RTC rate. 'esp_sleep_enable_timer_wakeup()' is supposed to return 'ESP_ERR_INVALID_ARG' in some cases, but it appears from the source code that this hasn't been implemented yet. Thanks!

art4evs
Posts: 5
Joined: Thu Feb 03, 2022 10:14 am

Re: Maximum ESP32-S2 Deep Sleep Duration

Postby art4evs » Mon Mar 14, 2022 8:01 pm

Well, I've confirmed that it sleeps fine and wakes after 48 hours, within about two seconds in fact. It'd be nice to know if a month was possible without testing as that's my eventual goal. The maximum time by the uint64_t argument itself seems to be 584558 years, but probably there's a smaller limit internally. Does anyone have a better answer to this?


art4evs
Posts: 5
Joined: Thu Feb 03, 2022 10:14 am

Re: Maximum ESP32-S2 Deep Sleep Duration

Postby art4evs » Mon Mar 14, 2022 11:09 pm

Thank you WiFive! Just what I was looking for. I grepped for this function previously but missed its definition in "rtc_time.c" and incorrectly assumed it was internally provided. In case the link breaks, here is what it says:

Code: Select all

uint64_t rtc_time_us_to_slowclk(uint64_t time_in_us, uint32_t period)
{
    /* Overflow will happen in this function if time_in_us >= 2^45, which is about 400 days.
     * TODO: fix overflow.
     */
    return (time_in_us << RTC_CLK_CAL_FRACT) / period;
}
Hopefully this helps other people as well as I've seen it asked/discussed here and there. Thanks again!

Who is online

Users browsing this forum: Baidu [Spider] and 66 guests