EEPROM empty ?

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, 

 

Is there a way to know if the EEPROM cell is empty ? At the beginning of my programm, I would look into the EEPROM in order to know if a data has been saved or not. The first time that the programm will be launched, the EEPROM will be "empty", so there will not be datas saved. However, I think that the cell will contain a data which is random ... 

Thank you and have a nice day ! 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

EEPROM is non-volatile.  That is the whole point of it.

 

Most programming software will erase the EEPROM as default.   So unless you ask it to do anything different,   your programs will start with EEPROM containing 0xFF.

 

You can always check your EEPROM at any stage in your program.   Of course writing EEPROM is a SLOW operation e.g. 5ms per byte.    Reading all the bytes of EEPROM is only going to take a millisecond or so.

 

A common strategy is to start with an empty EEPROM.    Write a magic value to a special location in EEPROM when you first write any data.

 

A subsequent run will check the magic value.
 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no such thing as a memory cell being "empty". It always holds some value.

 

If I recall correctly, an AVR fresh from the factory has 0xFF (decimal 255) in all its cells.

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Last Edited: Mon. Jul 17, 2017 - 08:11 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There's no such thing as "empty". EEPROM is just memory cells and each one is bound to hold some value between 0x00 and 0xFF. Because of the nature of non volatile memory cells when they are "erased" all the gates hold 1 so complete bytes hold 0xFF so I guess you might use that as an indication of "not programmed yet" but a better way to do it is to accompany your data with some non-0xFF "cookie" value. When you are happy your other data is recorded set the cookie to 0x55AA or something. Then later as a validity check read the cookie first. If it holds the "special value" you know that the other bytes have been programmed. If you need "more security" beyond that then run a CRC/Checksum over the stored data and later check that to verify that not only are the data values programmed but they are "intact".

 

EDIT: need to learn to type faster!

Last Edited: Mon. Jul 17, 2017 - 08:14 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

leoleoleo240 wrote:
I think that the cell will contain a data which is random

You are thinking of RAM there?

 

Although beware of the word "random" - undefined may be better.

 

As the others have all said, an erased EEPROM has the very definite, well-known value of all-ones

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok thank you very much ! It will help me a lot ! Have a nice day ! :D