Deep slepp question - esp_deep_sleep_get_wakeup_cause
Posted: Tue May 02, 2017 3:24 am
Hi,
I try this code(simplified deep_sleep_example_main.c)
The ESP32 go to deep slepp, periodically.
When wake up, why don't give : ESP_DEEP_SLEEP_WAKEUP_TIMER event?
(Thanks)
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();
}
When wake up, why don't give : ESP_DEEP_SLEEP_WAKEUP_TIMER event?
(Thanks)