Page 1 of 1

Bug of deep sleep with GPIO

Posted: Mon Feb 19, 2018 3:16 pm
by neosarchizo
Hi!

I developed an application that use deep sleep.
And I need to read a level of a GPIO that is used to awake after a device is awakened.
I used internal pull-up resistor and I made the device will be awake when the level of the GPIO is LOW.
But after the device is awakend, the level is always LOW, never change!
First I used esp_sleep_enable_ext0_wakeup function like this.

Code: Select all

esp_sleep_enable_ext0_wakeup(14, 0);
gpio_pad_select_gpio(14);
gpio_set_direction(14, GPIO_MODE_INPUT);
gpio_set_pull_mode(14, GPIO_PULLUP_ONLY);

esp_deep_sleep_start();


And I also used esp_sleep_enable_ext1_wakeup function too.

Code: Select all

esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
gpio_pullup_en(14);
gpio_pulldown_dis(14);

const int ext_wakeup_pin_1 = 14;
const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW);

esp_deep_sleep_start();


A result of the two codes are same. The level of GPIO 14 is always LOW after the device is awakened.
Even if I used external pull-up resistor with esp_sleep_enable_ext0_wakeup.
But when I used external pull-up resistor with esp_sleep_enable_ext1_wakeup, the level of GPIO 14 is changing.

I think that this is a bug.

Re: Bug of deep sleep with GPIO

Posted: Mon Feb 19, 2018 11:21 pm
by WiFive
After you wake up do you use rtc functions to read gpio or configure it back to normal gpio?

Re: Bug of deep sleep with GPIO

Posted: Tue Feb 20, 2018 3:06 am
by neosarchizo
Here is example code.

Code: Select all

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_sleep.h"
#include "esp_log.h"
#include "esp32/ulp.h"
#include "driver/touch_pad.h"
#include "driver/adc.h"
#include "driver/rtc_io.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
#include "soc/rtc.h"

void app_main()
{
    switch (esp_sleep_get_wakeup_cause()) {
        case ESP_SLEEP_WAKEUP_EXT0:
        case ESP_SLEEP_WAKEUP_EXT1:
        {
            printf("ESP_SLEEP_WAKEUP_EXT0 or EXT1\n");
            gpio_pad_select_gpio(14);
            ESP_ERROR_CHECK(gpio_set_direction(14, GPIO_MODE_INPUT));
              ESP_ERROR_CHECK(gpio_set_pull_mode(14, GPIO_PULLUP_ONLY));

              while(1) {
                 printf("level : %d\n", gpio_get_level(14));

                 vTaskDelay(1000 / portTICK_PERIOD_MS);
              }
            break;
        }
        case ESP_SLEEP_WAKEUP_UNDEFINED:
        default:
            printf("Not a deep sleep reset\n");
    }

    vTaskDelay(1000 / portTICK_PERIOD_MS);

    esp_sleep_enable_ext0_wakeup(14, 0);

    gpio_pad_select_gpio(14);
     gpio_set_direction(14, GPIO_MODE_INPUT);
     gpio_set_pull_mode(14, GPIO_PULLUP_ONLY);

    // esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
    // gpio_pullup_en(14);
    // gpio_pulldown_dis(14);
    // const int ext_wakeup_pin_1 = 14;
    // const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
    //
    // printf("Enabling EXT1 wakeup on pins GPIO%d\n", ext_wakeup_pin_1);
    // esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW);

    printf("Entering deep sleep\n");

    esp_deep_sleep_start();
}


Re: Bug of deep sleep with GPIO

Posted: Tue Feb 20, 2018 3:19 am
by WiFive
After wake up from sleep, IO pad used for wakeup will be configured as RTC IO. Before using this pad as digital GPIO, reconfigure it using rtc_gpio_deinit(gpio_num) function.


https://esp-idf.readthedocs.io/en/lates ... modes.html

Re: Bug of deep sleep with GPIO

Posted: Tue Feb 20, 2018 3:30 am
by neosarchizo
You are right. It works! It's my fault.