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:
#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
}