Read/write 24c04 eeprom

Hi,
so basically i have an ecu with a 24c04 eeprom that i need to read, modify the contents and write.
i am new to the arduino world and c++ language (only started learning a few months ago).
i have found this sketch on this website (KN34PC - 24C04 Arduino library) that it seems it might work to read the eeprom but not to write the modified content.
What I need to change is this:

"In addresses 1EE to 1F9, write values ​​2A 4E 00 00 FF FF 00 9C D4 13 56 01"

i am trying to understand the code so that i can modify it to do want i want but i am not sure.
I would be gratfull if someone could help
thanks

Have you tried this library:

It comes with several examples and the updateByte() and updateBlock() functions should do what you want.

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

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.