RTC memory access
Posted: Tue Jun 09, 2015 4:40 pm
I want to use deep-sleep mode, but I need to retain state through that event. Since the module resets after deep sleep, only the RTC memory remains untouched (or so I read). As I understand it, the RTC User-Memory begins at address 60001200h. I have not found any examples (yet) that demonstrate preserving state through the deep-sleep-wake cycle.
I quickly hacked out the following code, which appears to work. It successfully saves a value prior to a deep sleep and retrieves it after waking up. However, I noticed that the memory location contains a consistent non-zero value following a power-up, leading me to believe it is being initialized by something. I did not expect that and I'm wondering if I'm stomping on a piece of memory used by the Esp8266-Arduino libraries, or the RTC itself.
Am I doing this right? And am I playing in a safe bit of the RTC RAM?
Using Esp8266/Arduino 1.6.4:
I quickly hacked out the following code, which appears to work. It successfully saves a value prior to a deep sleep and retrieves it after waking up. However, I noticed that the memory location contains a consistent non-zero value following a power-up, leading me to believe it is being initialized by something. I did not expect that and I'm wondering if I'm stomping on a piece of memory used by the Esp8266-Arduino libraries, or the RTC itself.
Am I doing this right? And am I playing in a safe bit of the RTC RAM?
Using Esp8266/Arduino 1.6.4:
Code: Select all
#include <ESP8266WiFi.h>
const unsigned long SLEEP_INTERVAL = 20 * 1000 * 1000; // 20 sec
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("RTC Memory Test");
long *rtcMemory = (long *)0x60001200;
Serial.print("current value = ");
Serial.println(*rtcMemory);
(*rtcMemory)++;
Serial.print("new value = ");
Serial.println(*rtcMemory);
//sleep modes: WAKE_RF_DEFAULT, WAKE_RFCAL, WAKE_NO_RFCAL, WAKE_RF_DISABLED
ESP.deepSleep(SLEEP_INTERVAL - micros(), WAKE_RF_DISABLED);
delay(1000);
}
void loop() {
// should never get here
}