Post topics, source code that relate to the Arduino Platform

User avatar
By DinoN
#44264 HI,

I am trying to save and access values in the RTC memory during DEEP sleep. Here is the sketch:

Code: Select all#include <ESP8266WiFi.h>

const unsigned long SLEEP_INTERVAL = 20 * 1000 * 1000; // 20 sec

extern "C" {
  #include "user_interface.h"
}

void setup() {
  Serial.begin(74880);
  Serial.println();

  Serial.println("RTC Memory Test");
 
  byte rtcStore[2];
  system_rtc_mem_read(64, rtcStore, 2);
 
  Serial.print("current value = ");
  Serial.println(*rtcStore);


  (*rtcStore)++;
  Serial.print("new value = ");
  Serial.println(*rtcStore);
 
  system_rtc_mem_write(64, rtcStore, 2);
 
  //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
}


But it is not working. In the Serial output I am getting:
Code: Select allets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

RTC Memory Test
current value = 0
new value = 1

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

RTC Memory Test
current value = 0
new value = 1


I am using Arduino 1.6.8. Do I need to flash ESP-12 with some specific firmware (isn′t arduino uploading all that is needed) ?

Thanx,
DiNo
User avatar
By martinayotte
#44265 The Word address 64 is currently/mistakenly used by eboot (it should be fixed in next 2.2.0), so it is overwritten to zero at each reboot.

In the mean time, you can use other location staring at Word 65, but beware that word 95 is also used overwritten.
User avatar
By DinoN
#44269 Thank you it works fine now !

Code: Select all ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

RTC Memory Test
current value = 111
new value = 112

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld

RTC Memory Test
current value = 112
new value = 113
User avatar
By Rupak
#50313 I used the below code

```
Serial.println("RTC Memory Test");

byte rtcStore[2];
system_rtc_mem_read(65, rtcStore, 2);

Serial.print("current value = ");
Serial.println(*rtcStore);


(*rtcStore)++;
Serial.print("new value = ");
Serial.println(*rtcStore);

system_rtc_mem_write(65, rtcStore, 2);

//sleep modes: WAKE_RF_DEFAULT, WAKE_RFCAL, WAKE_NO_RFCAL, WAKE_RF_DISABLED
ESP.deepSleep(30*1000000, WAKE_RF_DISABLED);

delay(1000);
```

But I am not getting incremental data as mentioned by last post.

output:
RTC Memory Test
current value = 239
new value = 240

RTC Memory Test
current value = 239
new value = 240