Page 1 of 1

RTC Memory in Deep Sleep

Posted: Wed Jan 13, 2021 2:12 am
by monkey
Hi ESP32 Community. Bit of help needed. I've tried to use RTC Memory to store some stuff during deep sleep but can't make any head way with it:

Code: Select all

RTC_NOINIT_ATTR uint32_t testValue1 = 0;
RTC_DATA_ATTR   uint32_t testValue2 = 0;
RTC_DATA_ATTR   uint32_t testValue3;
RTC_SLOW_ATTR   uint32_t testValue4 = 0;
RTC_FAST_ATTR   uint32_t testValue5 = 0;
__NOINIT_ATTR   uint32_t testValue6;
RTC_IRAM_ATTR   uint32_t testValue7 = 0;

...

{
    ...

    if (wokeFromDeepSleep) {
       ...
    } else {
        seqNumber = 0;
        testValue3 = 0;
        testValue6 = 0;
    }
    ESP_LOGE(TAG, "seqNumber = %d", seqNumber);
    seqNumber_g = seqNumber;
    ESP_LOGE(TAG, "testValue1 = %d", testValue1++);
    ESP_LOGE(TAG, "testValue2 = %d", testValue2++);
    ESP_LOGE(TAG, "testValue3 = %d", testValue3++);
    ESP_LOGE(TAG, "testValue4 = %d", testValue4++);
    ESP_LOGE(TAG, "testValue5 = %d", testValue5++);
    ESP_LOGE(TAG, "testValue6 = %d", testValue6++);
    ESP_LOGE(TAG, "testValue7 = %d", testValue7++);
And ont he console, I'm getting all sort of rubbish. The first time round, everything is 0, then it seems pretty random.

Code: Select all

E (126) app_main: testValue1 = -1327966875
E (126) app_main: testValue2 = 431137070
E (136) app_main: testValue3 = -175958291
E (136) app_main: testValue4 = 1345924420
E (146) app_main: testValue5 = -831327041
E (146) app_main: testValue6 = 194569138
E (146) app_main: testValue7 = -1662166550

Re: RTC Memory in Deep Sleep

Posted: Wed Jan 13, 2021 5:54 am
by boarchuz
Try:

Code: Select all

esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_ON);

Re: RTC Memory in Deep Sleep

Posted: Wed Jan 13, 2021 6:39 am
by monkey
@boarchuz I read your post and then thought back to something I had spent an afternoon doing about 2 months ago. I went through every single thing I could think of to reduce the deep sleep power consumption of the device. So, I went to my file deep_sleep.c and found this:

Code: Select all

// Power Down RTC Domains! should get from 150 uA to 7 uA!
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
    // esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);

I've fixed it up and it runs like a dream. So, in a way, you have saved me from myself!!!

I've checked the datasheet: attached. It won't draw additional current. I'll rerun the tests to be on the safe side. Awesome outcome. Thanks heaps!