periodically wake up in light sleep mode

zhaozhaozhao
Posts: 21
Joined: Tue Apr 13, 2021 8:43 am

periodically wake up in light sleep mode

Postby zhaozhaozhao » Fri Aug 06, 2021 9:29 am

Hello ESPers,

how do you wake up the ESP32 board in light sleep mode periodically and execute a certain function? In deep sleep mode I can check the wakeup reason at the beginning of the main function. However in light sleep mode the board just continues from where it stops right?

Is there any interrupt based methods that could detect the wakeup source is a timer and call a function?

To be more specific, I want to enable the ULP coprocessor while the main processor is in automatic light sleep mode. The ULP coprocessor poll sensor status from a IR camera and only wakes up the main processor when at least one pixel is hotter than a global threshold variable. This global variable should be updated by the main processor, reading from a temperature sensor every 2 hours. Now the problem is, how do I call a function when the main processor is waken from automatic light sleep mode?

Thx.
Best Regards
Zhao

felmue
Posts: 69
Joined: Mon Nov 16, 2020 2:55 pm

Re: periodically wake up in light sleep mode

Postby felmue » Fri Aug 06, 2021 10:40 am

Hello @zhaozhaozhao

have you had a look at the light-sleep example? It uses `esp_sleep_get_wakeup_cause()` to figure out the wake up reason.

https://github.com/espressif/esp-idf/tr ... ight_sleep

Thanks
Felix

boarchuz
Posts: 598
Joined: Tue Aug 21, 2018 5:28 am

Re: periodically wake up in light sleep mode

Postby boarchuz » Fri Aug 06, 2021 12:19 pm

I had the same problem and used this: https://github.com/espressif/esp-idf/pull/4352
Although if I was doing it today I'd simply put a callback in esp_light_sleep_start (just before it returns). Hopefully IDF will have something like that in future.

zhaozhaozhao
Posts: 21
Joined: Tue Apr 13, 2021 8:43 am

Re: periodically wake up in light sleep mode

Postby zhaozhaozhao » Sat Aug 07, 2021 5:32 am

felmue wrote:
Fri Aug 06, 2021 10:40 am
Hello @zhaozhaozhao

have you had a look at the light-sleep example? It uses `esp_sleep_get_wakeup_cause()` to figure out the wake up reason.

https://github.com/espressif/esp-idf/tr ... ight_sleep

Thanks
Felix
Thanks, but do you how do you call the function in automatic light sleep mode, where you do not explicitly call the esp_light_sleep_start() at all? This is supported by the freeRTOS tickless idle feature. See https://docs.espressif.com/projects/esp ... figuration

Since the automatic light sleep mode is all handled by the esp_pm.h module internally I have no idea when the board enters sleep mode.

Best Regards
Zhao

zhaozhaozhao
Posts: 21
Joined: Tue Apr 13, 2021 8:43 am

Re: periodically wake up in light sleep mode

Postby zhaozhaozhao » Sat Aug 07, 2021 5:48 am

boarchuz wrote:
Fri Aug 06, 2021 12:19 pm
I had the same problem and used this: https://github.com/espressif/esp-idf/pull/4352
Although if I was doing it today I'd simply put a callback in esp_light_sleep_start (just before it returns). Hopefully IDF will have something like that in future.
Thanks. It is good to know that there is a callback function interface, so all I need to do is write a function with the name s_light_sleep_cb and check light_sleep_wakeup_cause in it. But I guess a TaskDelay within the callback function is not allowed, because otherwise the automatic light sleep will be activated again? This is very interesting, and hopefully will sovle my problem.

Best Regards
Zhao

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 90 guests