Need for help with EEPROM

General discussion on mikroPascal PRO for AVR.
Post Reply
Author
Message
Erik-Odinsvej
Posts: 20
Joined: 21 Jan 2008 21:37

Need for help with EEPROM

#1 Post by Erik-Odinsvej » 29 Sep 2020 22:40

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

mikahawkins
Posts: 5
Joined: 19 Sep 2020 07:44

Re: Need for help with EEPROM

#2 Post by mikahawkins » 03 Oct 2020 15:45

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
Mika HAwkins

Erik-Odinsvej
Posts: 20
Joined: 21 Jan 2008 21:37

Re: Need for help with EEPROM

#3 Post by Erik-Odinsvej » 04 Oct 2020 17:54

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

dibor
Posts: 208
Joined: 29 Dec 2014 18:59

Re: Need for help with EEPROM

#4 Post by dibor » 05 Oct 2020 08:38

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.

Post Reply

Return to “mikroPascal PRO for AVR General”