Page 1 of 1

Need for help with EEPROM

Posted: 29 Sep 2020 22:40
by Erik-Odinsvej
I cannot get eeprom to work in AVR pascal for an ATMEGA328p, when I use the example in the help file it only work as long I have power on my device,
example I use following from example file:
for counter := 0 to 31 do EEPROM_Write(0x100 + counter, counter);

In datasheet I can use addresses from 0 to 1023
and when I read it back:

for counter := 0 to 31 do // Read 32 bytes block from address 0x100
begin
PORTC := EEPROM_Read(0x100+counter); // and display data on PORTC
Delay_ms(100);
end;
Then all works well but if I change my program and only want to read and not write to eeprom, then all byte I read is 255 ! ???
it have complete forgot the byte I write to eeprom before.
can anybody tell me what is wrong, I have read several time in the datasheet but cannot see what I do wrong.

really hope for a solution cos I need to store some data in the eeprom for to read everytime I turn on my project
Best regards Erik

Re: Need for help with EEPROM

Posted: 03 Oct 2020 15:45
by mikahawkins
Reading from the EEPROM basically follows the same three step process as writing to the EEPROM: Send the Most Significant Byte of the memory address that you want to write to. Send the Least Significant Byte of the memory address that you want to write to. Ask for the data byte at that location

Re: Need for help with EEPROM

Posted: 04 Oct 2020 17:54
by Erik-Odinsvej
Thanks for your feedback - however it did not solve my problem - I know the basic of the EEPROM_Read/Write - so I go thru some video on YouTube about the subject and after long time search I found what I was looking for (in a French youtube)
I cannot understand French but I look what he did on the screen : EESAVE fuses !
I just have to set an checkmark in "Preserve DATA (EEPROM)" in the AVRFLASH program under options and now everything work.
Apparently the flash erase all EEPROM when programming, I was not aware of this. - Regards Erik

Re: Need for help with EEPROM

Posted: 05 Oct 2020 08:38
by dibor
Erik-Odinsvej wrote:
29 Sep 2020 22:40
l but if I change my program and only want to read and not write to eeprom, then all byte I read is 255 ! ???
Hi.
New chip is coming with 0xFF in the all EEPROM.
So if you are do not write anything to it , you will read only 0xFF(255) from the all addresses of the EEPROM.

Best Wishes.