Skip to content

UART not able to wake ESP32 from Light Sleep #5107

Closed
@dalbert2

Description

@dalbert2

Hardware:

Board: ESP32 WROOM-32 on custom board
Core Installation version: 1.0.6
IDE name: VSCode with PlatformIO
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Windows 10

Description:

How can I wake the ESP32 from light sleep when a UART character is received?

Problem: system enters light sleep successfully, power consumption drops as expected, system wakes for timer, but UART activity does not trigger wake from sleep. Serial I/O works correctly when not entering light sleep mode.

Sketch:

#include <Arduino.h>
#include <driver/uart.h>

  // See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/uart.html#api-reference
  // See: https://docs.espressif.com/projects/esp-idf/en/latest/esp32c3/api-reference/system/sleep_modes.html#entering-light-sleep

void serialEvent();

void setup() {
  // wake from sleep every 10s
  esp_sleep_enable_timer_wakeup(10*1000000); 

  // Configure UART0
  Serial.begin(115200);
  while (!Serial) { delay(500); }
  uart_set_wakeup_threshold(UART_NUM_0, 3);   // 3 edges on U0RXD to wakeup
  esp_sleep_enable_uart_wakeup(UART_NUM_0);   // Enable UART 0 as wakeup source

  Serial.printf("ESP32 light sleep with UART wake\r\n");
  Serial.printf("SDK: %s\r\n", ESP.getSdkVersion());
  Serial.flush();

}

void loop() {
  if (Serial.available()) {
     Serial.printf("Got key: 0x%X\r\n", Serial.read());
     Serial.flush();
  } else {
     esp_light_sleep_start();
     esp_sleep_wakeup_cause_t wakeup_cause;
     wakeup_cause = esp_sleep_get_wakeup_cause();
     Serial.printf("Wake cause: %d\r\n",(int) wakeup_cause);
     Serial.flush();

  }
}

Debug Messages:

ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
ESP32 light sleep with UART wake
SDK: v3.3.5-1-g85c43024c
Wake cause: 4
Wake cause: 4
etc.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions