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);
}
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.

  • Ah! Thank you! Makes sense! Now to change the fuse bit should I change the value in boards.txt ? Currently the high fuse byte is diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xDA (1101 1010 in binary) And I should change this to diecimila.menu.cpu.atmega328.bootloader.high_fuses=0xFA (1111 0111 in binary) Is that correct =/ ? – MoKaM Apr 11 '15 at 23:11
  • Or perhaps theres something I can type in the cmd using avrdude? – MoKaM Apr 11 '15 at 23:12
  • 1
    Read the current high fuse value (avrdude ... -U hfuse:r:-:h), bitwise-and it with 0xf7, and write it back out. – Ignacio Vazquez-Abrams Apr 12 '15 at 0:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.