Interface AT24C02 Two-Wire Serial EEPROM with Arduino

1,996 views

Introduction

Electrically erasable programmable read-only memory (EEPROM) is a type of non-volatile memory found in computers and microcontrollers used in smart cards, among other things. EEPROMs are relatively inexpensive because they are small circuitry in compact packaging. Thus, In this tutorial, we are going to “Interface AT24C02 Two-Wire Serial EEPROM with Arduino”

AT24C02 Two-Wire Serial EEPROM

ATMEL’s AT24C02 is an external EEPROM series. One of them is the AT24C02, which offers a bi-directional I2C protocol enabling data transfer between eight devices. This version contains 2KB of memory space, which is organized in the form of 32 8-byte pages. It is a small, low-power gadget with two functioning modes that change based on the input voltage. The device features 8-byte write modes with a maximum write cycle of one million.

Features and Specifications

  • 256×8 (2 kbit)
  • 400 kHz (1.7V) and 1MHz (>2.5 V) clock compatibility.
  • Supports up to 8 devices on the bus.
  • Self-Timed Erase and Write cycle (5 ms max.)
  • Low power consumption.
  • Read current 0.4 mA (Typ), 1 mA (Max) standby current 6uA (Max).
  • Hardware write-protect pin.
  • More than 1 million erase/write cycles.
  • Data retention > 100 years.
  • Extended Temperature Range Available (Grades 1,2 and 3 as defined in AEC – Q 100).
    • Grade 1 Temperature Range:- 40° c to 125°
    • Grade 2 Temperature Range:- 40° c to 105°
    • Grade 3 Temperature Range:- 40°c to 85° c
  • Qualified for Automotive Applications.
  • Factory programming is Available.

Pin Configuration

Pin Number NameDescription
1A0Address Input A0
2A1Address Input A1
3A2Address Input A2
4GNDGND
5SDASerial DATA (I2C)
6SCLSerial CLOCK Input (I2C)
7WPWrite Protect
8VCCPower Supply

Hardware Required

S.noComponentValueQty
1.Arduino UNO1
2.USB Cable Type A to B1
3.EEPROM AT24C021
4.Jumper Wires
5.Bread Board1
6.Resistor2

Circuit Diagram

Connection Table

Arduino UNOAT24C02 EEPROM
GNDGND
5vVcc
A4SDA
A5SCL
WPGND

Arduino Code

#include <Wire.h>

#define ADDR_Ax 0b000 //A2, A1, A0
#define ADDR (0b1010 << 3) + ADDR_Ax

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Wire.begin();
  writeI2CByte(0, 1);
  Serial.println(readI2CByte(0));
}

void loop() {
  // put your main code here, to run repeatedly:
  
}

void writeI2CByte(byte data_addr, byte data){
  Wire.beginTransmission(ADDR);
  Wire.write(data_addr);
  Wire.write(data);
  Wire.endTransmission();
}

byte readI2CByte(byte data_addr){
  byte data = NULL;
  Wire.beginTransmission(ADDR);
  Wire.write(data_addr);
  Wire.endTransmission();
  Wire.requestFrom(ADDR, 1); //retrieve 1 returned byte
  delay(1);
  if(Wire.available()){
    data = Wire.read();
  }
  return data;
}

Interfacing AT24C02 Two-Wire Serial EEPROM with Arduino

Any microcontroller device that uses the I2C Bus protocol may be readily interfaced with the AT24C02. And, therefore arduino can be interfaced easily.  The power supply of both modules must be connected, and the EEPROM’s SDA and SCL must be connected to the Arduino’s I2C lines.   A minimum of one I2C port is included on almost all Arduino development boards. A similar I2C interface is available on the Arduino Uno, which we are able to write to and read from this EEPROM device. 

Code Explanation

  • To begin, the “Wire.h” library is included to execute read and write operations.
  • The data is then sent using the 8-bit device address. The address’s last bit controls if the device reads or writes to the EEPROM. The last bit must be zero in order to write the data. The memory data address that is supplied after it is followed by the data that will be written. The location is now where the data is stored.
  • To read data from that location, a request is made using “Wire.requestFrom,” which comprises the device address with the last bit set to 1, and the second parameter is set to 1, indicating that the function will return one byte of data. “Wire.available” checks the memory address and returns the data saved at the place. It will appear on the Serial monitor.

Application and Uses

  • Storage devices
  • Communication systems
  • Industrial and commercial applications, etc