Chat freely about anything...

User avatar
By donnib
#38348 Hi,
I have following code :

Code: Select all#include "ESP8266WiFi.h"

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

byte rtcStore[1];
char trial[] = "[{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"},{\"T\":\"20\",\"H\":\"40\"}]";

void setup() {
  // Start Serial
  Serial.begin(115200);
  delay(10);

  Serial.println("Hello");
  // put your setup code here, to run once:
}

void loop() {
  delay(1000);
  rtcStore[0] = 10;
  Serial.println("Mem write rtcStore:");
  Serial.println(system_rtc_mem_write(65, rtcStore, sizeof(rtcStore)));
  Serial.println("Mem write trial:");
  Serial.println(system_rtc_mem_write(68, trial, sizeof(trial)));

  char t[sizeof(trial)];
  byte r[1];
  Serial.println("Mem read rtcStore:");
  Serial.println(system_rtc_mem_read(65, &r, sizeof(r)));
  Serial.println("Mem read trial:");
  Serial.println(system_rtc_mem_read(68, &t, sizeof(trial)));

  Serial.print('<');
  Serial.print(t);
  Serial.println('>');
  Serial.print('<');
  Serial.print(r[0]);
  Serial.println('>');

}


I have this output:

Code: Select allr...lœ˜rß.Œ#.ânÀ.ˆà..Œ..‚ì.pŒ|Ž‚ß.ìx.’ŸÇ’œäl.p...ònnä.„;ònĒœä..Ž.bŽcl`.$`.üpònàÃ܀..à‚ÇÀl.€Œœ€..€.bÀ.nâãnÀ$ŽŒŒŽØ.bÀÄ>~ònî.ÄÁŒŽ.l`.ü.Ü#‚nÀ..r....nrŽ’ß;.ÄÀ.?Œ.r...rßےnÀ..à‚ÇÄl`.üü‚nÄbàHello
Mem write rtcStore:
1
Mem write trial:
1
Mem read rtcStore:
0
Mem read trial:
1
<[{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"},{"T":"20","H":"40"}]>
<0>


As you can see readin rtcStore is returning 0 and that i don't understand. If i remove all the write/read code for trial variable then i can read rtcStore, it's like i am doing something wrong when i write trial but it works.

Any ideas ?

/donnib
User avatar
By martinayotte
#38379 I've some tries with system_rtc_mem_write() and system_rtc_mem_read(), which I've never did before, in my own Sketch_Buffet. I works without any problems.
So, I've copy/paste your own sketch, and I'm seeing the problem.
I didn't figure out yet where is the issue.
I will dig more ... :roll:
User avatar
By torntrousers
#38398 If you read the SDK Guide about the RTC read/write functions it mentions being 4 byte blocks -

"Note: RTC memory is 4 bytes aligned for read and write operations. Parameter src_addr means block number(4 bytes per block)."

I don't completely understand the implications of that, but if you change your
Code: Select allbyte r[1];
variable definition in your sketch to be
Code: Select allbyte r[1] __attribute__((aligned(4)));
it seems to fix it.