unable to disable wake up source after enable via esp_deep_sleep_enable_gpio_wakeup (ESP32C3)

zjustin
Posts: 18
Joined: Wed Jun 03, 2020 6:00 am

unable to disable wake up source after enable via esp_deep_sleep_enable_gpio_wakeup (ESP32C3)

Postby zjustin » Sat Feb 11, 2023 2:23 pm

I encounter a rather strange problem, not sure how do I resolve this

I have 2 GPIO pins used to wake up my ESP32C3.
GPIO 2: wake up device when active HIGH.
GPIO 3: wake up device when active LOW.
when I use the following code to and set ESP32C3 to sleep, I can wake up via both source properly.
but after the 1st wake up, I would like to disable the GPIO 2 wake up source. I tried various ways, like

esp_deep_sleep_enable_gpio_wakeup(0, ESP_GPIO_WAKEUP_GPIO_HIGH);
or
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);

both can not disable the previously enabled GPIO 2 wake up source. until ESP is rebooted.

Code: Select all

//Define bitmasks for GPIO pins used to wake from deep sleep
//Wake from deep sleep when these pins are high
const uint64_t WAKEUP_HIGH_PIN_BITMASK = 0b000100;  //GPIO2 for ACC INT
//Wake from deep sleep when these pins are low,
const uint64_t WAKEUP_LOW_PIN_BITMASK = 0b001000;  //GPIO3 for Button
before sleep cycle 1: use the following to enable both wake up source.

Code: Select all

esp_deep_sleep_enable_gpio_wakeup(WAKEUP_HIGH_PIN_BITMASK, ESP_GPIO_WAKEUP_GPIO_HIGH);
esp_deep_sleep_enable_gpio_wakeup(WAKEUP_LOW_PIN_BITMASK, ESP_GPIO_WAKEUP_GPIO_LOW);
esp_deep_sleep_start();
after wake up from cycle 1,
used the following to disable the GPIO 2 wake up source. but the device still wakes up on GPIO 2 source unless ESP is rebooted.

Code: Select all

esp_deep_sleep_enable_gpio_wakeup(0, ESP_GPIO_WAKEUP_GPIO_HIGH);
or

Code: Select all

esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
continue to keep GPIO 3 wake up source.

Code: Select all

esp_deep_sleep_enable_gpio_wakeup(WAKEUP_LOW_PIN_BITMASK, ESP_GPIO_WAKEUP_GPIO_LOW);
esp_deep_sleep_start();
any idea how do I disable the wakeup GPIO high without rebooting ESP ?

obscuretech
Posts: 1
Joined: Tue Feb 14, 2023 11:05 am

Re: unable to disable wake up source after enable via esp_deep_sleep_enable_gpio_wakeup (ESP32C3)

Postby obscuretech » Tue Feb 14, 2023 11:13 am

On wake-up from deep sleep no code following the start of deep sleep will ever be run, the unit will restart from cold-start as if the reset button had been pressed.

soundchasr
Posts: 1
Joined: Wed Jun 14, 2023 7:09 am

Re: unable to disable wake up source after enable via esp_deep_sleep_enable_gpio_wakeup (ESP32C3)

Postby soundchasr » Wed Jun 14, 2023 7:11 am

You can modify sleep_modes.c on component source.

from https://wooorazil.blogspot.com/2023/06/ ... blegp.html


modify esp_deep_sleep_enable_gpio_wakeup function like this.

[Codebox]
esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepsleep_gpio_wake_up_mode_t mode)
{
if (mode > ESP_GPIO_WAKEUP_GPIO_HIGH) {
ESP_LOGE(TAG, "invalid mode");
return ESP_ERR_INVALID_ARG;
}
gpio_int_type_t intr_type = ((mode == ESP_GPIO_WAKEUP_GPIO_LOW) ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL);
esp_err_t err = ESP_OK;

for (gpio_num_t gpio_idx = GPIO_NUM_0; gpio_idx < 6; gpio_idx++, gpio_pin_mask >>= 1) {
if ((gpio_pin_mask & 1) == 0) {
s_config.gpio_wakeup_mask &= ~BIT(gpio_idx);
gpio_deep_sleep_wakeup_disable(gpio_idx);

continue;
}
if (!esp_sleep_is_valid_wakeup_gpio(gpio_idx)) {
ESP_LOGE(TAG, "invalid mask, please ensure gpio number is no more than 5");
return ESP_ERR_INVALID_ARG;
}
err = gpio_deep_sleep_wakeup_enable(gpio_idx, intr_type);

s_config.gpio_wakeup_mask |= BIT(gpio_idx);
if (mode == ESP_GPIO_WAKEUP_GPIO_HIGH) {
s_config.gpio_trigger_mode |= (mode << gpio_idx);
} else {
s_config.gpio_trigger_mode &= ~(mode << gpio_idx);
}
}
s_config.wakeup_triggers |= RTC_GPIO_TRIG_EN;
rtc_hal_gpio_clear_wakeup_pins();
return err;
}[/Codebox]

Who is online

Users browsing this forum: No registered users and 29 guests