Page 1 of 1

GPIO_NUM_5 has weird state before deep sleep

Posted: Thu Jun 25, 2020 8:38 am
by JorgeSayMe
I am developing an application with an ESP32 as a microcontroller.
I always use the same function to have the minimum power consumption (above 8 - 10 uA) and I have never had problems.

But in this development, I use GPIO_NUM_5 to turn on/off a 3,3 Volts regulator. With a '0' the regulator is off and with a '1' is on.

I usually initialice the GPIOS like this:

//GPIO_SEL_5 (Regulator TPS610986DSER, PWR_MODE)
gpio_struct.pin_bit_mask = GPIO_SEL_5;
gpio_struct.mode = GPIO_MODE_OUTPUT;
gpio_struct.pull_up_en = GPIO_PULLUP_DISABLE; //Dont have external PULLUP
gpio_struct.pull_down_en = GPIO_PULLDOWN_DISABLE; //Dont have external PULLDOWN
gpio_struct.intr_type = GPIO_INTR_DISABLE; //Dont need int
ESP_ERROR_CHECK(gpio_config(&gpio_struct)); //Note, ampersand is OK, is only the text format

The pin goes to 0 Volts and to 3,3 Volts (logic '1') when I need it without problems, but before deep_sleep
the GPIO_NUM_5 goes from 0 Volts to 1 Volt, enabling the regulator and increasing the power consumption.

I have mapped a cable to externally pull down to GND to have a real '0' with 0 volts value


I don't know if there is something special to know about GPIO_NUM_5, because I have never had to use it
due to the immense quantity of GPIOs that an ESP32 has.



The function called before deep sleep is:
void prepare_sleep_mode(void)
{
gpio_set_level(GPIO_NUM_13, 0);
gpio_hold_en(GPIO_NUM_13);

gpio_set_level(GPIO_NUM_14, 0);
gpio_hold_en(GPIO_NUM_14);

gpio_set_level(GPIO_NUM_15, 0);
gpio_hold_en(GPIO_NUM_15);

gpio_set_level(GPIO_NUM_32, 0);
gpio_hold_en(GPIO_NUM_32);

gpio_set_level(GPIO_NUM_33, 1);
gpio_hold_en(GPIO_NUM_33);

gpio_set_level(GPIO_NUM_25, 1);
gpio_hold_en(GPIO_NUM_25);

gpio_set_level(GPIO_NUM_12, 0);
gpio_hold_en(GPIO_NUM_12);

gpio_set_level(GPIO_NUM_4, 0);
gpio_hold_en(GPIO_NUM_4);

gpio_set_level(GPIO_NUM_16, 0);
gpio_hold_en(GPIO_NUM_16);

gpio_set_level(GPIO_NUM_23, 0);
gpio_hold_en(GPIO_NUM_23);

gpio_set_level(GPIO_NUM_22, 0);
gpio_hold_en(GPIO_NUM_22);

gpio_set_level(GPIO_NUM_21, 0);
gpio_hold_en(GPIO_NUM_21);

gpio_set_level(GPIO_NUM_5, 0);
gpio_hold_en(GPIO_NUM_5);

//Isolate RTC I/O's (DON´T ISOLATE WAKE UP SOURCES)
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_0));
rtc_gpio_isolate(GPIO_NUM_0);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_2));
rtc_gpio_isolate(GPIO_NUM_2);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_4));
rtc_gpio_isolate(GPIO_NUM_4);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_12));
rtc_gpio_isolate(GPIO_NUM_12);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_14));
rtc_gpio_isolate(GPIO_NUM_14);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_15));
rtc_gpio_isolate(GPIO_NUM_15);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_25));
rtc_gpio_isolate(GPIO_NUM_25);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_26));
rtc_gpio_isolate(GPIO_NUM_26);
/*ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_27));
rtc_gpio_isolate(GPIO_NUM_27);*/
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_32));
rtc_gpio_isolate(GPIO_NUM_32);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_34));
rtc_gpio_isolate(GPIO_NUM_34);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_35));
rtc_gpio_isolate(GPIO_NUM_35);
ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_36));
rtc_gpio_isolate(GPIO_NUM_36);
/*ESP_ERROR_CHECK(rtc_gpio_init(GPIO_NUM_39));
rtc_gpio_isolate(GPIO_NUM_39);*/

//Disable RTC Fast Memory and XTAL Domain
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF);
//esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);

//Turn off ADC
adc_power_off();

//Delete drivers for UART and I2C
ESP_ERROR_CHECK(i2c_driver_delete(I2C_NUM_1));
ESP_ERROR_CHECK(uart_driver_delete(UART_NUM_1));
}

So,

There is something i am forgetting when using GPIO_NUM_5? With other GPIOS (like GPIO_NUM_16) I don´t have these problem.

Re: GPIO_NUM_5 has weird state before deep sleep

Posted: Thu Jun 25, 2020 8:56 am
by chegewara
JorgeSayMe wrote: gpio_struct.pull_up_en = GPIO_PULLUP_DISABLE; //Dont have external PULLUP
gpio_struct.pull_down_en = GPIO_PULLDOWN_DISABLE; //Dont have external PULLDOWN
Those settings are not about external pull down/up, its about internal. You disabled both, so pin is floating.
In addition pin 5 itself is not a bootstrap pin, but for some reason its state is read during startup:
https://github.com/espressif/esptool/wi ... de-message

I would recommend to set pull down to enable and if that wont fix problem, then maybe weak external pull down.

Re: GPIO_NUM_5 has weird state before deep sleep

Posted: Thu Jun 25, 2020 12:01 pm
by JorgeSayMe
I just try to use:

//GPIO_SEL_5 (Regulator TPS610986DSER, PWR_MODE)
gpio_struct.pin_bit_mask = GPIO_SEL_5;
gpio_struct.mode = GPIO_MODE_OUTPUT;
gpio_struct.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_struct.pull_down_en = GPIO_PULLDOWN_ENABLE;
gpio_struct.intr_type = GPIO_INTR_DISABLE;
ESP_ERROR_CHECK(gpio_config(&gpio_struct));

But the problem persists.

I think there is something with the GPIO_NUM _5 on deep sleep when it starts.
I will do a new design with an external Pull-Down Resistor (10 - 100 KOhms) to force '0' when the regulator isn´t required.