Deep slepp question - esp_deep_sleep_get_wakeup_cause

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Deep slepp question - esp_deep_sleep_get_wakeup_cause

Postby battancs.zsolt » Tue May 02, 2017 3:24 am

Hi,

I try this code(simplified deep_sleep_example_main.c)

Code: Select all

#include <time.h>
#include <sys/time.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_deep_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"

static RTC_DATA_ATTR struct timeval sleep_enter_time;

void app_main()
{
    struct timeval now;
    gettimeofday(&now, NULL);
    int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;

    printf("-----------------------------------------------------------------------------\n");
    switch (esp_deep_sleep_get_wakeup_cause()) {
        case ESP_DEEP_SLEEP_WAKEUP_EXT1: {
            uint64_t wakeup_pin_mask = esp_deep_sleep_get_ext1_wakeup_status();
            if (wakeup_pin_mask != 0) {
                int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
                printf("Wake up from GPIO %d\n", pin);
            } else {
                printf("Wake up from GPIO\n");
            }
            break;
        }
        case ESP_DEEP_SLEEP_WAKEUP_TIMER: {
            printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
            break;
        }
        case ESP_DEEP_SLEEP_WAKEUP_UNDEFINED:
        default:
            printf("Not a deep sleep reset\n");
    }
    printf("-----------------------------------------------------------------------------\n");

    vTaskDelay(1000 / portTICK_PERIOD_MS);

    const int wakeup_time_sec = 20;
    printf("Enabling timer wakeup, %ds\n", wakeup_time_sec);
    esp_deep_sleep_enable_timer_wakeup(wakeup_time_sec * 1000000);

    const int ext_wakeup_pin_1 = 25;
    const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
    const int ext_wakeup_pin_2 = 26;
    const uint64_t ext_wakeup_pin_2_mask = 1ULL << ext_wakeup_pin_2;

    printf("Enabling EXT1 wakeup on pins GPIO%d, GPIO%d\n", ext_wakeup_pin_1, ext_wakeup_pin_2);
    esp_deep_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask | ext_wakeup_pin_2_mask, ESP_EXT1_WAKEUP_ANY_HIGH);

    printf("Entering deep sleep\n");
    gettimeofday(&sleep_enter_time, NULL);

    esp_deep_sleep_start();
}
The ESP32 go to deep slepp, periodically.

When wake up, why don't give : ESP_DEEP_SLEEP_WAKEUP_TIMER event?

(Thanks)

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Deep slepp question - esp_deep_sleep_get_wakeup_cause

Postby ESP_igrr » Tue May 02, 2017 5:41 am

Can you attach the serial output and your sdkconfig file?

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: Deep slepp question - esp_deep_sleep_get_wakeup_cause

Postby battancs.zsolt » Tue May 02, 2017 5:15 pm

ESP_igrr wrote:Can you attach the serial output and your sdkconfig file?
Hi, Igor!

I attach the files. (sorry for pdf extension ).

Thanks,

zs
Attachments
serial.log.pdf
(2.97 KiB) Downloaded 444 times
sdkconfig.pdf
(8.44 KiB) Downloaded 467 times

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Deep slepp question - esp_deep_sleep_get_wakeup_cause

Postby ESP_igrr » Fri May 05, 2017 4:30 pm

Could you please try with CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=1000?

battancs.zsolt
Posts: 9
Joined: Mon Feb 29, 2016 8:09 am

Re: Deep slepp question - esp_deep_sleep_get_wakeup_cause

Postby battancs.zsolt » Mon May 08, 2017 7:56 pm

ESP_igrr wrote:Could you please try with CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY=1000?
Yes. A little better!

Still not "ESP_DEEP_SLEEP_WAKEUP_TIMER" event.

Code: Select all

----------------------------
Wake up from GPIO 26
-----------------------------------------------------------------------------
Enabling timer wakeup, 20s
Enabling EXT1 wakeup on pins GPIO25, GPIO26
Entering deep sleep
Thanks.

Who is online

Users browsing this forum: No registered users and 120 guests