I'm wondering if there is a way to store a small integer in a way that if you turn the microcontroller (an atmega328, in my case) off, and then turn it back on again, the variable won't reset. Do I need external hardware to do this? If the answer is yes, what do I need and how do I use it? If I can do this directly within the atmega328, (I doubt it, but maybe I'm wrong) how do I do it?
\$\begingroup\$ \$\endgroup\$
3 - 1\$\begingroup\$ ww1.microchip.com/downloads/en/Appnotes/… \$\endgroup\$BeB00– BeB002022-03-01 06:15:53 +00:00Commented Mar 1, 2022 at 6:15
- 2\$\begingroup\$ It's called "non-volatile" memory. Volatile memory goes away when you lose power. \$\endgroup\$DKNguyen– DKNguyen2022-03-01 06:18:37 +00:00Commented Mar 1, 2022 at 6:18
- 1\$\begingroup\$ If the write is fairly frequent there is a wear issue with eeprom. Examples: hour meter or odometer. Ferroelectric RAM is better for this. \$\endgroup\$hacktastical– hacktastical2022-03-01 07:06:07 +00:00Commented Mar 1, 2022 at 7:06
Add a comment |
1 Answer
\$\begingroup\$ \$\endgroup\$
Yes it is possible.
No external components needed.
The ATMega328 contains built-in EEPROM that can be used for storing data.
How to do it depends on you choise of programming language and compiler but the MCU datasheet contains the info if your compiler manual does not provide you with a library of EEPROM functions.