ESP32-C3 deep sleep GPIO wakeup reason

HelgardM
Posts: 2
Joined: Wed Jun 21, 2023 9:34 am

ESP32-C3 deep sleep GPIO wakeup reason

Postby HelgardM » Wed Jun 21, 2023 9:46 am

Hello all,

I'm using a deep sleep GPIO wakeup mechanism. The GPIO signal that wakes the ESP32 is a high frequency switching signal (up to 3kHz).
The wakeup works but after waking, my code relies on the

Code: Select all

esp_sleep_get_wakeup_cause()
function to return : ESP_SLEEP_WAKEUP_GPIO. This does not happen the very first wake. Instead, the function returns ESP_SLEEP_WAKEUP_UNDEFINED which causes the chip to go to sleep again, only to be awaken again by the switching GPIO. After this second wakeup, the wakeup_cause function returns the correct value.

TL;DR: The ESP32-C3 esp_sleep_get_wakeup_cause function returns ESP_SLEEP_WAKEUP_UNDEFINED when awaken by a GPIO level change the first time. After an immediate second deep sleep and wake sequence, the esp_sleep_get_wakeup_cause function returns the correct ESP_SLEEP_WAKEUP_GPIO.

What could be the cause of this?

Thanks!

andrewandroid
Posts: 7
Joined: Sat Dec 26, 2020 7:33 am

Re: ESP32-C3 deep sleep GPIO wakeup reason

Postby andrewandroid » Thu Sep 14, 2023 12:23 pm

I have the same issue.

I'm also using an ESP32-C3, and I get ESP_SLEEP_WAKEUP_UNDEFINED (i.e. 0) as the reason for waking after deep sleep, instead of ESP_SLEEP_WAKEUP_GPIO (i.e. 7) when I push a button to wake it from deep sleep.

It does wake up from deep sleep, but gives the wrong reason.

Code: Select all

// In setup:
esp_sleep_source_t thecause = get_wakeup_cause();
printf("Woke up for reason: %d.\n", thecause);
// Prints:
// Woke up for reason: 0.

esp_reset_reason_t resetreason = esp_reset_reason();
dprintf("resetreason: %d.\n", resetreason);
// Prints:
// resetreason: 1.
(...)

Code: Select all

// Later on, I tell it to go into deep sleep:

// Have to use a pin <= GPIO 5 to wake from deep sleep via GPIO
printf("Pin 3 validity: %d\n\r", (int) esp_sleep_is_valid_wakeup_gpio((gpio_num_t) 3));
printf("Pin 4 validity: %d\n\r", (int) esp_sleep_is_valid_wakeup_gpio((gpio_num_t) 4));
printf("Pin 5 validity: %d\n\r", (int) esp_sleep_is_valid_wakeup_gpio((gpio_num_t) 5));
// Prints:
// Pin 3 validity: 1
// Pin 4 validity: 1
// Pin 5 validity: 1

// Now setting GPIO dead interrupts to wake from sleep.
 
  esp_err_t deepsleepresult = esp_deep_sleep_enable_gpio_wakeup(
      ((1ULL<<3) | (1ULL<<4) | (1ULL<<5))
      , ESP_GPIO_WAKEUP_GPIO_HIGH);
      // Note, my buttons are connected to high via a 1k resistor, when the button is pressed.
      
  printf("deepsleepresult was %d.\n", (int) deepsleepresult);
// Prints:
// deepsleepresult was 0.
     
 
So it looks like esp_reset_reason() works, but get_wakeup_cause() does not. It should return ESP_SLEEP_WAKEUP_GPIO (which is 7), instead of ESP_SLEEP_WAKEUP_UNDEFINED (which is 0).

Can Espressif please confirm this bug?

I noticed another thread here with the same issue:
https://esp32.com/viewtopic.php?t=29054

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

Re: ESP32-C3 deep sleep GPIO wakeup reason

Postby felmue » Thu Sep 14, 2023 6:26 pm

Hello @andrewandroid

which ESP-IDF version are you using? Running the provided deep sleep example https://github.com/espressif/esp-idf/tr ... deep_sleep on my ESP32C3 works fine and I get the proper wake-up reason. I tried with the latest ESP-IDF from github, e.g. 5.2.x.

Thanks
Felix

Who is online

Users browsing this forum: No registered users and 366 guests