EEPROM Misreading (solved)

Donziboy2:
Im using <avr/eeprom.h>

Those functions should work but are designed strangely. They require casting an int EEPROM address into an SRAM pointer. I'm sure they cast that number back to an int before using it.

What is causing your problem is the resulting pointer math. What you wrote is:

  eeprom_write_word((uint16_t*)savedAddress + 3, counter);

What the compiler sees is:

  eeprom_write_word(&((uint16_t*)savedAddress)[3], counter);

Because you are indexing a WORD pointer it adds 6 (three words worth of bytes) instead of 3.

To fix it, do the addition BEFORE the cast:

  eeprom_write_word((uint16_t*)(savedAddress + 3), counter);

Be sure to fix that wherever you read or write a word.