An Introduction to EEPROM

umair nehri
RIXED_LABS
Published in
5 min readSep 10, 2021
Blog Banner

Hello everyone and welcome to yet another blog by a fellow nerd at Axial. Today, we will be discussing about the EEPROM Memory chips which are the first, and most commonly considered memory devices to add to embedded systems these days.

[0x00] What exactly is EEPROM?

EEPROM or Electrically Erasable Programmable Read-Only Memory is a non-volatile memory chip that can be used for storing a small amount of data from a computer or some other electronic device. EEPROM being non-volatile in terms of storage has the ability to retain the stored information even after the power is removed. An individual byte of data stored in the memory can be erased or reprogrammed (written to) repeatedly although it has a limited life, meaning that the number of times it can be reprogrammed to tens or hundreds of thousands of times.

In this blog, we will mainly focus on the ATMEGA328P microcontroller present on the Arduino UNO R3 Development Board. The microcontroller has an EEPROM having a total size of 1024 bytes. The EEPROM here has a life expectancy of around 100,000 Write/Erase cycles which means that you can write and erase/re-write bytes of data in this memory chip at least over 100,000 times before the EEPROM becomes unstable.

Image showing the expected lifetime of EEPROM at various write frequencies

In the image above, you can have an idea about the expected lifetime of the EEPROM at various write frequencies.

[0x01] Types of EEPROM

There are mainly two types of EEPROM interfaces used for data input/output, Serial and Parallel EEPROM memory.

1. Serial EEPROM Memory

Example of Serial EEPROM Memory

A Serial EEPROM is where the data is transferred serially which causes Serial EEPROM devices to be comparatively slower than Parallel EEPROM memory. They are relatively cheaper and less dense.

A Serial EEPROM device typically consists of three phases:

  • OP-Code Phase
  • Address Phase
  • Data Phase

2. Parallel EEPROM Memory

Example of Parallel EEPROM Memory

A Parallel EEPROM device generally has an 8-bit data bus and a wide address bus which is enough for total memory handling. When compared with Serial EEPROM devices, they are denser and reliable but due to their cost, parallel EEPROMs have lower popularity.

[0x02] The <EEPROM.h> Library

The Arduino IDE comes with the <EEPROM.h> library which enables a developer to read/write bytes of data into the EEPROM of the microcontrollers present in the Arduino and Genuino AVR based boards.

A developer can use this library by adding the below line of code:

#include <EEPROM.h>

Here are some of the functions that you can perform with the help of this library,

  • EEPROM ReadRead a byte of data from EEPROM and send it to the computer.
  • EEPROM Write — Write a byte of data from analog input to the EEPROM.
  • EEPROM Update — Write a byte of data to EEPROM only if the new value is different from the current value.
  • EEPROM Get — Get any value from EEPROM and print as float or struct or any datatype on serial.
  • EEPROM Put — Write any value to EEPROM as float or struct or any datatype.

The table below shows the size of EEPROM (in bytes) for different microcontrollers used in various Arduino based development boards. It will help you to get an idea about how many bytes you could read/write on the board that you’re using.

Table showing the size of EEPROM for different microcontrollers used in various Arduino boards.

[0x03] Using the<EEPROM.h> Library

Let us try to understand the use of <EEPROM.h> library through an example. Assume that we have set up a certain project with our Arduino Uno R3 Development board and that we need to store the end user's preferred settings on it. For functionalities like these, EEPROM memory could be of great help since it could store the values for the preferred settings into our Arduino board and since EEPROM is a non-volatile memory, it could retain our data even after the power is removed.

Let’s take a quick look over the below code,

Code Snippet Illustrating the Application of <EEPROM.h> library

Initially, we have imported the <EEPROM.h> library in line 1. We are using the variable choice for reading the input from the user and the variable defaultsettings for reading the value from the EEPROM memory.

The code basically lets the user input their choice on whether they would like to keep the on-board surface mount LED ON or OFF depending on the input (y or n). To check the previous state of the LED we are using the EEPROM.read() function to read the value from address 0 and pass it to the conditional statements to set the LED’s state initially. The code then lets the user input their choice which would then turn the LED’s state accordingly and finally write the choice on address 0 inside the EEPROM memory using the EEPROM.write() function.

[0x05] Conclusion

This brings us to the end of this blog. We covered the introduction to EEPROM memory chips, their types and finally the <EEPROM.h> library from Arduino IDE and its application. I hope this quick overview was enough to give you a brief understanding of what EEPROM actually is and how you can use it in your projects.

I look forward to bringing more such content in future but if you find any mistakes in this blog feel free to reach out through Twitter since I will really appreciate any sort of feedback for it.

Happy Hacking!

Blog by Nerd of AX1AL, join us on our discord server.

--

--