-->
Page 2 of 8

Re: EEPROM put and get methods

PostPosted: Tue May 05, 2015 1:00 pm
by gerardwr
biobier wrote:Not sure what you mean! All what is stated in the doc is taken care in the code posted by me.


Shame on me, you're right, my apologies !!

Will have a BETTER look at your code and see if I can help.

Re: EEPROM put and get methods

PostPosted: Tue May 05, 2015 1:56 pm
by gerardwr
@biobier

Compiled your code, no output in the Serial Monitor, seems to "hang".

Compiled the supplied Example Sketch "eprom_write". Doesn't work for me either, also seems to "hang".

Maybe the library was broken?

Re: EEPROM put and get methods

PostPosted: Sat May 09, 2015 8:08 am
by gerardwr
@biobier

Had another look and it seems that the while loop takes too long and the ESP is reset, probably due to the WDT.

Your sketch runs OK with the following changes:
- add Serial.begin to setup, otherwise the print statements will not be visible in the serial monitor
- add a yield() ( or delay(0) ) instruction in the while loop to give the ESP time to do other things
- I changed the increment of the while counter i

Here's the code that runs:

Code: Select allinclude <EEPROM.h>

void setup()
{
  Serial.begin(115200);
  EEPROM.begin(512);
  // write a 0 to all 512 bytes of the EEPROM
  int i=0;
  byte data=0;
  while(i<512){
   EEPROM.put(i, data);
   i++;
   yield();
   Serial.println(i);
  }
  // turn the LED on when we're done
  Serial.println("Done!");
  digitalWrite(13, HIGH);
  EEPROM.end();
}

void loop()
{
}

Re: EEPROM put and get methods

PostPosted: Sat May 09, 2015 11:29 pm
by jwatte
I think the reason the original code breaks is that it overflows the allocated EEPROM buffer.

Specifically, sizeof(int) is 4, so if you write 512 of those together, you're overwriting 2048 bytes, which is more than the 512 byte buffer. Thus, you trash whatever is after the buffer in RAM.