Pages: [1]   Go Down
Author Topic: Memory overflow in EEPROM.write example  (Read 1887 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

At: EEPROMWrite Reference page

EEPROM.write(address, value)

address: the location to write to, from 0 to 511 (int)
value: the value to write, from 0 to 255 (byte)

Example
  for (int i = 0; i < 512; i++)
    EEPROM.write(i, i);

The example code writes values higher than 255 in EEPROM locations 256 and above, causing memory overflow.
Logged

Offline Offline
Edison Member
*
Karma: 3
Posts: 1001
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The example code writes values higher than 255 in EEPROM locations 256 and above, causing memory overflow.

I'm not sure I understand what you mean by "memory overflow", but if you think the code will attempt to write outside memory boundaries this is not so. Eeprom locations 256 through 511 will receive values 0 through 255.

I agree however that the example should be changed.

« Last Edit: November 12, 2009, 02:19:20 pm by borref » Logged

Australia
Offline Offline
Newbie
*
Karma: 0
Posts: 23
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Bumping this old thread to change the example located on http://arduino.cc/en/Reference/EEPROMWrite because it's writing a value (256-511) more than the 255 allowed.

Maybe change "i" to 256 to keep it all simple?
« Last Edit: January 03, 2011, 01:50:25 am by electricteardown » Logged

Pages: [1]   Go Up
Jump to: