M328(P): Internal EEPROM Write-Only Mode

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

Hello,

 

I've got a question regarding the internal EEPROM of an ATmega328(P). Sadly the datasheet has no information for me.

 

Question: What happens if I use the Write-Only Mode on non-erased (!= 0xff) EEPROM cells (EEPM1 = 1)?

I tried simulating this special case in a simulator (not Atmel Studio). The simulator writes (independently from the contents of EEDR) 0x00 if I try writing in write-only mode to a non-erased cell.

This topic has a solution.
Last Edited: Mon. Jan 18, 2021 - 05:28 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It will clear all the 0 bits.

It will not write any 1 bits.

 

As a general rule,  you just call the library eeprom_update() and it does everything for you.

I doubt if it bothers with EEPM=1 or EEPM=2 modes.   Simply reads existing contents and writes if the new value is different.

 

I have not looked at the library code for EEPROM.    It might test for old & new == new and use EEPM=2

You definitely check this when writing to Flash Memory chips.

 

David.

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

david.prentice wrote:

It will clear all the 0 bits.

It will not write any 1 bits.

 

David.

 

By clearing all the 0 bits, do you mean that all zero bits are flipped to ones ? If so, isn't it in contradiction with your next sentence (It will not write any 1 bits) ?

 

Edit: Also thank you for your respond :)

Last Edited: Mon. Jan 18, 2021 - 05:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Milo-D wrote:
If so, isn't it in contradiction with your next sentence (It will not write any 1 bits) ?

No, it erases all zeros (so now all bits are 1's)

it then writes zeros(ignoring any 1's)

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

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

No it does not.

 

Erased is all 1s

 

Programmed is a 0.

 

For example.   D in "David" is 0b01000100.   J in "Jim" is 0b01001010

0b01000100  'D' old
0b01001010  'J' new
----------
0b01000000  '@' result

 

As I said in #3,  you just use the appropriate library function.    Everything works.

If you don't understand the concept of 1s and 0s don't try and write your own function.

 

David.

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

So effectively write-only mode on non-erased memory is writing 0x00. Thank you guys.

 

Edit: This post was written before answer #5

Last Edited: Mon. Jan 18, 2021 - 05:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:

No it does not.

 

Erased is all 1s

 

Programmed is a 0.

 

For example.   D in "David" is 0b01000100.   J in "Jim" is 0b01001010

0b01000100  'D' old
0b01001010  'J' new
----------
0b01000000  '@' result

 

As I said in #3,  you just use the appropriate library function.    Everything works.

If you don't understand the concept of 1s and 0s don't try and write your own function.

 

David.

 

I know what erase/programmed means. And I don't want to write my own functions. I need this little detail for my simulator.

 

But 'clearing all 0 bits' is not the same as 'erasing all 0 bits'. 'Clearing' bits is, atleast for me a form of writing bits. That is why I thought it would be a contradiction. So just a misunderstanding.

 

 

Last Edited: Mon. Jan 18, 2021 - 05:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Perhaps we have a language problem.  

 

J in "Jim" is 0b01001010  has three 1 bits and five 0 bits

 

Writing a 0 will change a 1 to 0  i.e. clears that bit

Writing a 1 makes no difference

 

Erasing a byte sets  all bits to 1 i.e. 0b11111111

 

It is a pretty simple concept for data memory e.g. my example J

 

Fuses are also 0s and 1s.    Most GUI software will put a tick in a box for 0 and empty a box for 1.   

Guaranteed to make your head hurt.  

 

David.

Last Edited: Mon. Jan 18, 2021 - 05:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, I think there was a misunderstanding.

 

I thought that you mean with 'It'

 

david.prentice wrote:

It will clear all the 0 bits.

It will not write any 1 bits.

 

the write-only mode. But I guess you mean that this is the general process of erasing ("it will clear all the 0 bits") and writing ("it will not write any 1 bits", so only 0 bits) the EEPROM.

 

So long story short, only zeros will be written when writing, and since there is no previous erase process in write-only mode, it will write only zero's.

I didn't know that, internally, there is no write of 1's of EEDR but only its 0's.

 

Thanks.

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

Flash is simple technology. If you apply a high voltage you can return all the 8 bits in a byte wide storage location to 1 so an erased byte is 0FF. After that, with "normal" low voltage writes the only thing you can do is knock the stored charge off that various transistors that make up the byte. So you can write 0 bits. SO if you start with 0xBC (10111100) you could write this to 0x94 (10010100) because the only bits that change are 1 to 0 transitions (2 of the transistors have changed state from 1 to 0 in this change). But you could not change 0xBC to 0x01 because while you can certainly clear all the other set bits with 1 to 0 transitions you cannot make bit 0 transition from 0 to 1. The only way you can do that is to erase the entire byte with high voltage (so initially it goes to 0xFF (11111111)) and then make 7 of the 8 bits do the 1 to 0 transition. Each time you do the high voltage operation to put 1 on all the transistors (erase) it oxidizes the insulator on the transistor gates. Over time the problem gets worse and worse until after 100,000 (0 to 1) transitions there is no further guarantee that the transistors can hold a 1 charge anymore. That is why you have to be careful with EEPROM that you don't erase too often as it has to last for the entire lifetime of the chip (the flash for code storage is worse still - it can only guarantee 10,000 0 to 1 transitions on each transistor.

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

Not to derail this thread, but thank you for that explanation clawson, I understand better how EEPROMs work now. One question, when you knock off the voltage of a 1 bit to make it a 0 bit, does that then not count towards the maximum programming count on the EEPROM? in other words, only a high voltage write of 0b11111111 to a byte constitutes a counted write cycle, but not a normal voltage write to knock it down to say 0b10101010, or later again to knock it down to say 0b10000010?

Wayne

East London
South Africa

 

  • No, I am not an Electronics Engineer, just a 54 year old hobbyist/enthusiast
  • Yes, I am using Proteus to learn more about circuit design and electronics
  • No, I do not own a licensed copy of Proteus, I am evaluating it legitimately
  • No, I do not believe in software or intellectual property piracy or theft
Last Edited: Tue. Jan 19, 2021 - 10:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WayneZA wrote:
does that then not count towards the maximum programming count on the EEPROM?
The thing that oxidizes the gate and breaks the isolation barrier is the application of high voltage (the chip contains a voltage pump) and that is only used during erase (ie moving 0 bits back up to 1).

 

I think there may be a lesser issue with 1 to 0 transitions but let's face it, from the erased state, a byte could never have more than eight 1 to 0 transitions anyway (and each transistor that makes up the byte will only ever transition once until the next erase)

 

Interesting app note: https://www.nxp.com/docs/en/appl...

Last Edited: Tue. Jan 19, 2021 - 11:27 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WayneZA wrote:

I understand better how EEPROMs work now. One question, when you knock off the voltage of a 1 bit to make it a 0 bit, does that then not count towards the maximum programming count on the EEPROM? in other words, only a high voltage write of 0b11111111 to a byte constitutes a counted write cycle, but not a normal voltage write to knock it down to say 0b10101010, or later again to knock it down to say 0b10000010?

Refer to Freescale application note 2166, there is a section called selective bit programming that partially answers your question. My interpretation is that one can extend the apparent lifetime of write cycles by only erasing a byte when a 0 to 1 bit transition is required to move from the existing value to the new value. 

 

Ah OK, also mentioned in this old thread.

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

ccrause wrote:
y interpretation is that one can extend the apparent lifetime of write cycles
Yup, i nthe past we wrote a flash wear levelling system that used the bits in a control byte to monitor the life of "pages". So one byte could hold the alive/dead state of 8 pages.

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

WayneZA wrote:
One question, when you knock off the voltage of a 1 bit to make it a 0 bit, does that then not count towards the maximum programming count on the EEPROM?

Isn't there a very extensive thread or set of threads where this was tested and documented with numbers?  Or maybe I am thinking of page-vs-byte?  Time to do some searching...  [btw, the site search engine doesn't seem to always pick up on certain keywords, or maybe it is creeping senility and forgetting]

 

[edit] page-vs-byte

https://www.avrfreaks.net/commen...

https://www.avrfreaks.net/forum/... ***

https://www.avrfreaks.net/forum/...

https://www.avrfreaks.net/forum/...

a good related read, and the thread that kicked off the experiments https://www.avrfreaks.net/forum/...

 

Now to try to find similar overwrite-the-bits threads...

lfmorrison gave a one-paragraph summary of the discussion here, in 2005.  No testing numbers.

https://www.avrfreaks.net/commen...

 

Extensive threads on the topic.  Definitive?  Y'all decide.

https://www.avrfreaks.net/forum/...

https://www.avrfreaks.net/forum/...

 

A what-if discussion from 2006.  Interesting as it starts with EEPROM activity on a '128 and then the difference to the newfangled '88 with erase-only and write-only.

https://www.avrfreaks.net/forum/...

So that brings another point:  whatever "decided" here would need to be confirmed on Xmega and Xtiny and such.

 

There is a reference to app note AVR103, dated 2005.  Still "PRELIMINARY" lol.

http://ww1.microchip.com/downloa...

Of particular importance here, right from the horse's mouth:

This application note implements a driver utilizing the programming modes available for the EEPROM in some AVR parts, like ATmega48/88/168, ATtiny13, ATtiny2313 and ATmega256x. The driver saves both power and time by always using the most efficient programming mode when writing data to EEPROMmemory. It ensures that EEPROM cells are only erased and programmed when itis required.

...

Note that even if EEPROM memory is accessed in bytes, bits can be programmed individually. Since only the bits being programmed are discharged (zero), the remaining unprogrammed bits are still charged (one). Any unprogrammed bit can beprogrammed at a later stage. Therefore, programming a byte that is alreadyprogrammed, without erasing in between, will result in a bit-wise AND between the old value and the new value.

...

Q.E.D?

 

 

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Tue. Jan 19, 2021 - 02:02 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course, we can forget about all this "Real Soon Now" when FRAM, et al, reach mass market ...

 

laugh

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you gents for the clarity. 'i should have searched but didn't because it was being discussed, but my bad, sorry. smiley

 

I will take a look through all the quoted resources, thank you.

Wayne

East London
South Africa

 

  • No, I am not an Electronics Engineer, just a 54 year old hobbyist/enthusiast
  • Yes, I am using Proteus to learn more about circuit design and electronics
  • No, I do not own a licensed copy of Proteus, I am evaluating it legitimately
  • No, I do not believe in software or intellectual property piracy or theft
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

WayneZA wrote:
'i should have searched but didn't because it was being discussed,...

No worries there, really.  It took a couple tugging synapses and some fairly thorough digging to get to those past threads.  And apparently no-one remembered that it was in the app note.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.