24C32 Ex01
#include <>
How to Usu I2C EEPROM What is EEPROM? Breaking Out Pins Wiring
Writing New Data Reading Data Whats Possible Code
Schematics Comments


How to Use I2C EEPROM © GPL3+
Expand your board's storage with an I2C-enabled EEPROM chip. data collection
What is EEPROM?
EEPROM stands for Electronically Erasable Programmable Read-Only Memory. It allows for values to be written and stored for long periods of time while using very little power. Most microcontrollers even have EEPROM directly in their circuitry, such as the ATmega328P (Arduino Uno chip), which has 1KB of it. But what if that’s not enough? SD cards have much greater storage sizes, but are also more complex, physically larger, and use more power. In this tutorial, I will show how easy it is to add another 2KB of non-volatile storage to a project with the 24C02 EEPROM IC.
Breaking Out Pins
The chip I chose comes in several packages, but because I needed to mount them on PCBs, I went with the SOIC-8 package, which is a surface-mount variant. To begin, I added the EEPROM IC part into Eagle, along with a 3-pin header for the ADDR pins and a 5-pin header for the other pins. Then I simply routed net segments between the pins to connect them. Next, I laid it all out on a PCB by placing the IC first and then the headers on either side. I made sure that they were directly lined up, as crossing the paths adds a lot of unnecessary complexity. I used Chilipeppr to generate Gcode for my CNC router, which I used to mill the traces on the board. Then it was simply a matter of soldering everything together.
Wiring
Connecting the EEPROM chip to an Arduino Uno board was simple. Here is a list of connections:
AT24C02|Uno
GND|GND
VCC|5v
SDA|SDA
SCL|SCL
WP|GND (Connect to VCC to disable writing)

Addressing
The address pins are only necessary if more than one EEPROM chips are going to be used. If that is the case, just increment the three-bit address value for each new chip. For example, the third IC would have these pins connected: A0 | A1 | A2 0 | 1 | 0
Writing New Data
To write data, first ensure the WP (write protect) pin is connected to GND. The device address is first sent with a value between 0x50 and 0x57. Then an eight bit must be added on to then end which toggles between reading or writing. To write, it gets set to 0. To demonstrate, the address byte of the first IC as a write operation would be 1010000. Next, an address is specified for the data to be written to, followed by the byte to be written. Using the Wire library, this looks like: Wire.beginTransmission( 0x50 ); Wire.write( address ); Wire.write( data ); Wire.endTransmission(); // STOP TRANSMITTING
Reading Data
Reading data from the chip is done in a similar way. First, the target storage address must be selected. This is done by sending a dummy write command to load in the target address. Next, one byte is sent containing the device address and the read/write bit as 1. The EEPROM chip then sends one byte of data in return. This looks like: /*F******************************************************************** * **********************************************************************/ Wire.beginTransmission( 0x50 ); Wire.send( targetAddress ); Wire.endTransmission(); Wire.requestFrom( 0x50, 1 ); If( Wire.available() ) { byte data = Wire.receive(); } Wire.endTransmission();
What’s Possible?
By using an EEPROM chip instead of an SD card, you can save space, power, and complexity. If you have a project that needs to store initial values for a game or have a save state, an EEPROM chip is perfect. It allows for the storage of values even after the main microcontroller has been powered off.
Code
Read and WriteC/C++ /*F******************************************************************** * **********************************************************************/ #include <Wire.h> //************************* DEFINES ************************************ #define ADDR_Ax 0b000 // A2, A1, A0 #define ADDR (0b1010 << 3) + ADDR_Ax //************************* PROTOTYPES ************************************ void writeI2CByte( byte data_addr, byte data ); byte readI2CByte( byte data_addr ); //************************* VARIABLES ************************************ /*F******************************************************************** * **********************************************************************/ void setup() { // PUT YOUR SETUP CODE HERE, TO RUN ONCE: Serial.begin( 9600 ); Wire.begin(); writeI2CByte( 0, 1 ); Serial.println( readI2CByte( 0 ) ); } /*F******************************************************************** * **********************************************************************/ void loop() { // PUT YOUR MAIN CODE HERE, TO RUN REPEATEDLY: } /*F******************************************************************** * **********************************************************************/ void writeI2CByte( byte data_addr, byte data ) { Wire.beginTransmission( ADDR ); Wire.write( data_addr ); Wire.write( data ); Wire.endTransmission(); } /*F******************************************************************** * **********************************************************************/ 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 ); }
Schematics
EEPROM Uploads/tmp/08ac9522 0ef6 40c9 bd0f bc83986c2805/schematic 6wwtgtkfoi Pins Uploads/tmp/e169de07 37c2 4224 943b 2be9e806a63b/pinout 2w7mfreext
Comments
rafael marroquin
2 years ago Realmente excelente vi un post sobre esta comunicacion pero lastimosamente estaba defasado en cuando a la libreria Wire. Me sirvio mucho ya que encontre un IC 24C01 (128 x8) y aca pude usar parte de la programacion que aca encontre.
Wrichik Basu
2 years ago In the readI2CByte(byte) function, the delay after Wire.endTransmission() should be 5ms instead of 1ms. I was facing some problem, and upon posting in the Arduino forums, I was advised to put a delay of 5ms, which solved the problem.
viliamk
a year ago Or maybe you can replace delay + if(Wire.available()) with while(!Wire.available()) {}. While waits till it is available and then the program continues. This can work faster and more reliably if you need to read from more addresses.
Kevin Pearce
6 months ago Hi guys. I have been trying to write and read data from a 24C04 EEPROM without success. I've wired it up to an Arduino uno as per the connections in this article, and am holding pins 1 through 4 (and pin 7 R/W) LOW. Uno A4 = SDA, and Uno A5 = SCL, with both pulled high to Vcc through 4k7 resistors. After I upload the code (and change the 1mS delay to 5mS (as per Wrichik Basu's suggestion), all I get on the serial monitor is a single 0. What is meant to happen ? Also, Viliamk's suggestion gives me nothing back on the serial monitor.
beskow178
3 months ago Did you ever resolve this? Am in a similar situation. sl001 sl001 2 months ago The code looks incorrect from the timing point of view. I have not tried out this code specifically but I have seen the mistake in some other I2C EEPROM implementations as well. The delay is not needed in the read code. The I2C EEPROM answers pretty fast on read. In the microsecond range. Remove the delay function in read. The delay is needed after write. In the data sheet of the I2C EEPROMs there is specific information on this. A 10ms (!!) delay is needed after each completed write cycle. You would need a delay( 10 ); at the end of the write function to make it work reliably. (Information refers to 24Cxx)