Chat here about code rewrites, mods, etc... with respect to the github project https://github.com/esp8266/Arduino

Moderator: igrr

User avatar
By gerardwr
#16609
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.
User avatar
By gerardwr
#16614 @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?
User avatar
By gerardwr
#16978 @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()
{
}
User avatar
By jwatte
#17051 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.