Bug of deep sleep with GPIO

neosarchizo
Posts: 5
Joined: Tue Jul 04, 2017 6:33 am

Bug of deep sleep with GPIO

Postby neosarchizo » Mon Feb 19, 2018 3:16 pm

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.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Bug of deep sleep with GPIO

Postby WiFive » Mon Feb 19, 2018 11:21 pm

After you wake up do you use rtc functions to read gpio or configure it back to normal gpio?

neosarchizo
Posts: 5
Joined: Tue Jul 04, 2017 6:33 am

Re: Bug of deep sleep with GPIO

Postby neosarchizo » Tue Feb 20, 2018 3:06 am

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();
}


WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: Bug of deep sleep with GPIO

Postby WiFive » Tue Feb 20, 2018 3:19 am

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

neosarchizo
Posts: 5
Joined: Tue Jul 04, 2017 6:33 am

Re: Bug of deep sleep with GPIO

Postby neosarchizo » Tue Feb 20, 2018 3:30 am

You are right. It works! It's my fault.

Who is online

Users browsing this forum: Google Adsense [Bot] and 59 guests