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);
}
asked Apr 11, 2015 at 21:35

1 Answer 1

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.

answered Apr 11, 2015 at 21:46
3
  • 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 =/ ? Commented Apr 11, 2015 at 23:11
  • Or perhaps theres something I can type in the cmd using avrdude? Commented Apr 11, 2015 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. Commented Apr 12, 2015 at 0:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.