I’m currently working with the Xiao-ESP32-S3 Sense module and encountering an issue with its light sleep mode. It seems that the ESP hangs when going into light sleep and never wakes up from timer, sometimes it gets a reset.
I also tried waking it up from GPIO and BLE, only deep sleep works.
Has anyone faced a similar issue or found a workaround?
Hi there, and welcome,
So You could use the </> tags to post the code cleaner. FYI
SO I tried it and hangs after the delay’s stack up.
one note is this, When the ESP32 wakes up, it runs the whole code from the beginning.
It will come back to sleep once it reaches the line of code with the esp_deep_sleep_start(); function.
So, it will stay awake until running the esp_deep_sleep_start() function.
All your code should be placed before that function. More consistent results will be the outcome.
This works as It should.
// Light sleep
#include <Arduino.h>
#include <esp_sleep.h>
void setup () {
Serial.begin(9600);
delay (2000);
}
void loop () {
uint64_t sleepMicros = 500;
//delay(200);
esp_sleep_enable_timer_wakeup(sleepMicros);
//delay(200);
Serial.print("going to Sleep : ");
Serial.println(sleepMicros);
//delay(200);
uint32_t s = micros();
Serial.print("Awake: ");
uint32_t e = micros();
//delay(200);
Serial.println(e - s);
delay (500);
print_wakeup_reason();
esp_light_sleep_start();
//delay(1000);
}
void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch(wakeup_reason){
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program"); break;
default : Serial.printf("Wakeup was not caused by deep sleep: %d\n",wakeup_reason); break;
}
}
Output Looks like this:
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x15 (USB_UART_CHIP_RESET),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x4201e832
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbe4
load:0x403cc700,len:0x2a38
entry 0x403c98d4
going to Sleep : 500
Awake: 12
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 12
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 12
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 12
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 11
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 11
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 12
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 11
Wakeup was not caused by deep sleep: 0
going to Sleep : 500
Awake: 11
Found your sample/solution and it works. But if I increase sleepMicros to one second or so, it doesn’t output anymore. I ran this example including a blink on the internal LED and I see the LED blinking so it keepsrunning but without output.
Is this expected behaviour?
So you may see that the Other core that handles the WiFi and BLE are still running and the RTOS may be in the way as well as no Serial Flush is implemented. Causing the behavior you see with too Long of a delay.
HTH
GL PJ