Showing posts with label EEPROM Library - AVR. Show all posts
Showing posts with label EEPROM Library - AVR. Show all posts

Thursday, July 12, 2018

AVR EEPROM Library | ATmega328P

Sometimes some data needs to be saved after the microcontroller is powered off. Say you have a rotary encoder to set audio volume. When the user sets the volume, the value is stored in SRAM but when the power goes off, the memory content is lost. In this cases you would use the EEPROM memory to store data. AVR devices have three types of memory:
  • Flash memory - for the program code
  • SRAM memory - also referred as data memory (volatile memory)
  • EEPROM memory


EEPROM stands for Electronically Erasable Read-Only Memory and is a non-volatile memory, meaning that unlike RAM, it will hold the stored information even after power is removed, much like an USB flash drive. Here can be stored settings and data that can not be hard coded, usually taken by the interaction with a user. Keep in mind that the EEPROM has a lifespan of 100,000 writes - reads are unlimited - so is not a good idea to write to this memory every second or even every few seconds.

Normally, to make use of the EEPROM memory, you would have to read the datasheet and implement some read/write functions using some registers. But fear not - the AVR-GCC compiler comes with prebuilt routines making things much easier.