Skip to content

Commit

Permalink
Adding deep sleep example.
Browse files Browse the repository at this point in the history
The program is a simple loop: Read VDD, sleep for 5 second.
  • Loading branch information
nqd committed Jul 11, 2015
1 parent 5ebb4c5 commit 3d043a6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions examples/deepsleep/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ROOT = ../..

#FLASH_SIZE=512
#OTA=0

include $(ROOT)/Makefile.common
Binary file added examples/deepsleep/esp_init_data_default.bin
Binary file not shown.
17 changes: 17 additions & 0 deletions examples/deepsleep/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
To read VDD
-------------------

The 107th byte in esp_init_data_default.bin (0~127byte) is named as "vdd33_const" , when TOUT pin is suspended vdd33_const must be set as 0xFF, that is 255.

Should change byte 107th of esp_init_data_default.bin to run this program.

With vi:
:%!xxd
[edit]
:%!xxd -r
:wq

To wakeup from deep sleep
------------------

Connect GPIO16 to Reset pin
4 changes: 4 additions & 0 deletions examples/deepsleep/user/user_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#ifndef _USER_CONFIG_H_
#define _USER_CONFIG_H_

#endif
35 changes: 35 additions & 0 deletions examples/deepsleep/user/user_main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "user_config.h"
#include "user_interface.h"

#include "driver/uart.h"

#define INFO(...) os_printf(__VA_ARGS__)
#define __SET__DEEP_SLEEP__WAKEUP_NO_RF__ system_deep_sleep_set_option(4)
#define __SET__DEEP_SLEEP__WAKEUP_NORMAL__ system_deep_sleep_set_option(1)

static ETSTimer report_timer;

void ICACHE_FLASH_ATTR
read_vdcc()
{
uint16_t vdd33 = system_get_vdd33();
uint16_t vdd = vdd33*100/1024;
INFO("VDD = %d.%d\n", vdd/100, vdd%100);
}

//Init function
void ICACHE_FLASH_ATTR
user_init()
{
// UART setup
uart_init(BIT_RATE_115200, BIT_RATE_115200);
os_delay_us(2000000); // 1 sec

read_vdcc();
__SET__DEEP_SLEEP__WAKEUP_NORMAL__;
system_deep_sleep(5000000);
}

0 comments on commit 3d043a6

Please sign in to comment.