In light sleep mode, digital peripherals, most of the RAM, and CPUs are clock-gated, and supply voltage is reduced. Upon exit from light sleep, peripherals and CPUs resume operation, their internal state is preserved.

Documentation

https://docs.espressif.com/projects/esp-idf/en/v4.4.5/esp32c3/api-reference/system/sleep_modes.html

Example light sleep function

Used with ESP32 C3

#include "esp_sleep.h"
//#include "esp_bt.h"
//#include "esp_bt_main.h"

//***************************************
//***************************************
//********** ENTER LIGHT SLEEP **********
//***************************************
//***************************************
void EnterLightSleep (void)
{

	//----- SET PRE SLEEP GPIO STATE -----
	//When entering light sleep GPIO pins will be shut off regardless of state unless you use gpio_hold_en() to force their state to be locked
	//Once the ESP32 wakes, the pin level will be set back to whatever level it was in memory prior to entering light sleep

	//Set output pin states
	gpio_set_level(GPIO_NUM_0, 0);
	gpio_set_level(GPIO_NUM_1, 0);
	gpio_set_level(GPIO_NUM_3, 0);

	//Lock the states
	ESP_ERROR_CHECK(gpio_hold_en(GPIO_NUM_0));
	ESP_ERROR_CHECK(gpio_hold_en(GPIO_NUM_1));
	ESP_ERROR_CHECK(gpio_hold_en(GPIO_NUM_3));

	//Optional isolate gpio pins to to prevent extra current draw from pull resistors
	//rtc_gpio_isolate(GPIO_NUM_10)


	//-----	DISABLE WIFI AND BT -----
	//If used
	//esp_bluedroid_disable();
	//esp_bluedroid_deinit();
	//esp_bt_controller_disable();
	//esp_bt_controller_deinit();
	//esp_wifi_stop();


	//----- SETUP GPIO INPUTS AS WAKEUP TRIGGERS -----
	//Any IO can be used as an external input to wakeup the chip from Light-sleep

	//Call gpio_wakeup_enable, specifying gpio number and wakeup level, for each GPIO which is used for wakeup
	ESP_ERROR_CHECK(gpio_wakeup_enable(GPIO_NUM_8, GPIO_INTR_LOW_LEVEL));		//GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL
	ESP_ERROR_CHECK(gpio_wakeup_enable(GPIO_NUM_18, GPIO_INTR_LOW_LEVEL));
	ESP_ERROR_CHECK(gpio_wakeup_enable(GPIO_NUM_4, GPIO_INTR_LOW_LEVEL));

	//Enable this wakeup source
	esp_sleep_enable_gpio_wakeup();


	//----- SETUP TIMER AS WAKEUP TRIGGER -----
	esp_sleep_enable_timer_wakeup(5000000);		//uint64_t value in uS


	//-----------------------
	//----- GO TO SLEEP -----
	//-----------------------
	ESP_LOGI(TAG, "Entering light sleep...");
	vTaskDelay(100 / portTICK_PERIOD_MS);		//Delay to let the console message be sent!

	//----- ENTER LIGHT SLEEP MODE -----
	esp_light_sleep_start();

	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> WE ARE SLEEPING! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
	//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

	ESP_LOGI(TAG, "Wakeup from light sleep...");

	//--------------------
	//----- WOKEN UP -----
	//--------------------

	//----- SET POST SLEEP GPIO STATE -----
	//Release otuput pin states you previously locked
	gpio_hold_dis(GPIO_NUM_0);
	gpio_hold_dis(GPIO_NUM_1);
	gpio_hold_dis(GPIO_NUM_3);

	//Return any output states to normal as needed
	gpio_set_level(GPIO_NUM_0, 1);
	gpio_set_level(GPIO_NUM_1, 1);
	gpio_set_level(GPIO_NUM_3, 1);

}
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

Comments

Your email address will not be published. Required fields are marked *