Read/write 24c04 eeprom

1. Connect the AT24C04 EEPROM with UNO/NANO as per Fig-1.

24C04Cir
Figure-1:

2. Upload the sketch of Section-3 to write your data in the indicated locations of the EEPROM of type AT24C04 having:

512x8 locations,
(24C04 ===> 1024x4 = 4096 bits capacity ===> 4096/8 = 512 bytes capacity)

8-byte page size and hence 64 pages (512/8 = 64),

Page addresses are:

0x0000 - 0x0007, 0x0008 - 0x000F, 0x0010 - 0x0017, ...,
0x01E0 - 0x01E7, 0x01E8 - 0x01EF, 0x1F0 - 0x1F7, 0x1F8 - 0x01FF

We will write in the following locations:

0x01EE - 0x01EF ; data: 2A 4E partial page
0x01F0 - 0x01F7; data:  00 00 FF FF 00 9C D4 13 full page
0x01F8 - 0x1F9; data: 56 01 partial page

3. The Sketch

#include<Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.beginTransmission(0x50);
  Wire.write(0x01); //pointing high byte of EEPROM location: 01FE
  Wire.write(0xFE); //lower byte of EEPROM location
  Wire.write (0x2A); //data for location: 01EF
  Wire.write(0x4E); //data for location 01EF
  Wire.endTransmission();
  delay(5);  //write-time delay
  //--read back and show on Serial Monitor
  Wire.beginTransmission(0x50);
  Wire.write(0x01); //higher byte og location
  Wire.write(0xFE); //lower byte of location
  Wire.endTransmission();

  Wire.requestFrom(0x50, 2); //request to read 2 bytes
  Serial.println(Wire.read(), HEX); //should show: 2A
  Serial.println(Wire.read(), HEX); //should show: 4E
  //--- if works, follow similar way to write other bytes.
 //write next page of 8-byte
 //write next two byte (partial paging is allowed).
}

void loop(){}
1 Like