# EEPROM emulator

**URL:** <https://community.particle.io/t/eeprom-emulator/12874>\
**Category:** General\
**Created:** [June 29, 2015, 8:38pm UTC](https://community.particle.io/t/eeprom-emulator/12874 "2015-06-29T20:38:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack/32/5412_2.png) [@Jack](https://community.particle.io/u/Jack)\
**Post date:** [June 29, 2015, 8:38pm UTC](https://community.particle.io/t/eeprom-emulator/12874/1 "2015-06-29T20:38:46Z")

</div>

Documentation Quote:  
The EEPROM emulator allocates a region of the device’s built-in flash memory to act as EEPROM. Unlike “true” EEPROM, flash doesn’t suffer from write “wear” with each write to each individual address. Instead, the page suffers wear when it is filled. Each write will add more data to the page until it is full, causing a page erase.

Sorry, but I don’t understand this “page erase” thing.

For example: if I `EEPROM.write(6, 126);` two thousand times ( or 9 trillion times), will that cause a page erase?

---

<div class="post-metadata">

**Author:** ![AndyW](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/andyw/32/686_2.png) [@AndyW](https://community.particle.io/u/AndyW)\
**Post date:** [June 29, 2015, 8:43pm UTC](https://community.particle.io/t/eeprom-emulator/12874/2 "2015-06-29T20:43:15Z")

</div>

google the way flash works, you’ll see that it can only erase a page at a time, unlike eeprom that can (usually) work at the byte level.

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack/32/5412_2.png) [@Jack](https://community.particle.io/u/Jack)\
**Post date:** [June 29, 2015, 8:46pm UTC](https://community.particle.io/t/eeprom-emulator/12874/3 "2015-06-29T20:46:15Z")

</div>

Ok, thanks for the info. But does that mean that my saved data will be transferred to a new page, and I don’t really need to worry about its inner workings, or will my stored data just disappear ?

---

<div class="post-metadata">

**Author:** ![AndyW](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/andyw/32/686_2.png) [@AndyW](https://community.particle.io/u/AndyW)\
**Post date:** [June 29, 2015, 8:50pm UTC](https://community.particle.io/t/eeprom-emulator/12874/4 "2015-06-29T20:50:08Z")

</div>

it’d be a pretty poor emulation of eeprom if it ate your data.

It should not eat your data.

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack/32/5412_2.png) [@Jack](https://community.particle.io/u/Jack)\
**Post date:** [June 29, 2015, 8:54pm UTC](https://community.particle.io/t/eeprom-emulator/12874/5 "2015-06-29T20:54:14Z")

</div>

Thanks @AndyW for the info. When I read the documentation on EEPROM, I started to worry.  
So, my saved data will be accessible by the addressing, and I really don’t care what page it is on at the moment…

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 30, 2015, 2:24am UTC](https://community.particle.io/t/eeprom-emulator/12874/6 "2015-06-30T02:24:38Z")

</div>

All data can be accessed as long as people know where to find it. That’s not an EEPROM issue at all.

You need encryption or self-defined values that only your program can decipher if that’s a concern.

FLASH areas on the Photon are locked and probing on the surface in general will not reveal too much info.

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack/32/5412_2.png) [@Jack](https://community.particle.io/u/Jack)\
**Post date:** [June 30, 2015, 2:14pm UTC](https://community.particle.io/t/eeprom-emulator/12874/7 "2015-06-30T14:14:18Z")

</div>

> [@kennethlimcp](#):
>
> All data can be accessed as long as people know where to find it

So, does that mean if I use:

EEPROM.write(6, 126); // 9 trillion times  
Then later, maybe months/years  
value = EEPROM.read(6);

I will get my "126" back ?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [June 30, 2015, 2:18pm UTC](https://community.particle.io/t/eeprom-emulator/12874/8 "2015-06-30T14:18:34Z")

</div>

Your data will probably be corrupted an exceeded the write cycle for 9 trillion times. 😉

There’s a stated guarantee for data retention for STM32 ICs if i am not wrong and you can read that up 🙂

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [June 30, 2015, 2:35pm UTC](https://community.particle.io/t/eeprom-emulator/12874/9 "2015-06-30T14:35:09Z")

</div>

You would get “126” back because the library is smart enough to know that it doesn’t need to write the value if it is the same as the value already stored. If you wrote different data to the same location, you **might** wear out the underlying FLASH RAM used to emulate an EEPROM, but it is hard to calculate since it is page erases that count for wear and the library does wear leveling using the algorithm that ST Micro, the processor manufacturer, recommends. It is actually data dependent since the FLASH is erased to all 1’s and can only be written to zeros and the library knows this and is clever.

It would take at least 100 days of continuous writing to get to 9 trillion writes, by the way.

Can we please be done being silly here?

---

<div class="post-metadata">

**Author:** ![Jack](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jack/32/5412_2.png) [@Jack](https://community.particle.io/u/Jack)\
**Post date:** [June 30, 2015, 2:39pm UTC](https://community.particle.io/t/eeprom-emulator/12874/10 "2015-06-30T14:39:08Z")

</div>

Ok, I think I see. There is still some write wear, and 9 trillion writes would probably be to much.  
But if that was reduced to about 5 million, it should work fine? Maybe even 2 billion?  
Is there a time delay during writing? Does it block other user code from running?

BTW: I wasn’t trying to be silly, just give an example that was not ambiguous. If I had said 2 billion, that would have been borderline I thought. Sorry
