ESP32 wakes up immediately from deep sleep indicating GPIO change
Posted: Sat Aug 19, 2023 12:44 am
Hi I am having a problem that when I go into deep sleep, the ESP32 immediately wakes up saying that a pulled down I/O pin connected to as push button has gone high when it has not. I have written test code with a standard interrupt routine to make sure the external hardware is acting properly and it is. Below is the code I use to go into deep sleep. Note that I want to wake up when the timer expires or the button is pushed. Also, note that while the ESP32 is awake I read from the pin to detect a long press. Thanks for any help you can give. This is on an ESP32 Devkit C.
Code: Select all
#define DEFAULT_WAKEUP_PIN (35)
void do_deep_sleep(int64_t time_to_sleep_in_us)
{
int result;
gpio_config_t config;
printf("Going to sleep for %lld us\n",time_to_sleep_in_us); fflush(stdout);
result = esp_sleep_enable_timer_wakeup(time_to_sleep_in_us);
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
reset_gpio(DEFAULT_WAKEUP_PIN);
uint64_t mask = 1;
mask <<= DEFAULT_WAKEUP_PIN;
config.pin_bit_mask = mask;
config.mode = GPIO_MODE_INPUT;
config.pull_up_en = GPIO_PULLUP_DISABLE;
config.pull_down_en = GPIO_PULLDOWN_DISABLE;
config.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&config));
ESP_ERROR_CHECK(esp_sleep_enable_ext0_wakeup((gpio_num_t)DEFAULT_WAKEUP_PIN,1));
/* Enter sleep mode */
if (result == ESP_OK)
esp_deep_sleep_start();
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}