5

When I write '13' to the EEPROM and read it straight after it works correctly.

However when I comment out the write part of the code and try to just read the data, the value is no longer 13 as it used to be but reverts back to 255. Whats going on?

I am running a standalone atmega328 on a breadboard with a 16mhz crystal, programmed by a Nano R3.

void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT);

//EEPROM.write(1,13);
}

void loop() {
scoreBinary();


}

void scoreBinary(){

int score= EEPROM.read(1);

if(score==13){
digitalWrite(2,HIGH);
}
delay(10000);
}
MoKaM
  • 51
  • 2

1 Answers1

4

By default the EEPROM in the MCU is erased (to 0xff) when the chip is erased before flash is written to. If you want to prevent this then you will need to program EESAVE in the fuse bits, which is bit 3 in the high fuse byte of the '328.

Ignacio Vazquez-Abrams
  • 17,733
  • 1
  • 28
  • 32