Go Down

Topic: i2c eprom problem (Read 1 time) previous topic - next topic


Hi, i am currently trying to use the 24WC02 I2C EPROM with my arduino and noting is working... i think it is plugged in right (checked it twice) and used a code find on this forum for testing i2c EPROM... i just think something is different with mine and i need to change some little thing in the code but don't know what.... ( sorry i code only for fun and nobody ever showed me how.... (i'm only an electromecanic where i work...) also i didn't install any pull up resistor cause some say it is handled by the arduino...

this is the code i found on this forum... thx to the one who work on it btw...

Code: [Select]
/* Simple read & write to a 24LC256 256K EEPROM using the Wire library.
* Addresses are ints - 0000-7FFF (32767) Data is bytes (8 bits x 32767 = 256K)
* Functions for R/W of single byte or a page of bytes. Max page is 28 bytes.
* SETUP:           _ _                                
* Arduino GND- A0-|oU |-Vcc  to Arduino Vcc
* Arduino GND- A1-|   |-WP   to GND for now. Set to Vcc for write protection.
* Arduino GND- A2-|   |-SCL  to Arduino 5
* Arduino GND-Vss-|   |-SDA  to Arduino 4
*                  ---       (A2, A1, A0 to GND for 1010000 (0x50) address.)
*                            If set to Vcc adds to address (1010,A2,A1,A0)

#include <Wire.h>
#define EEPROM_ADDR 0x51           // I2C Buss address of 24LC256 256K EEPROM

void setup(){
 Wire.begin();                    // join I2C bus (address optional for master)

 Serial.println("Writing Test:");
 for (int i=0; i<32; i++){            // loop for first 20 slots
   i2c_eeprom_write_byte(EEPROM_ADDR,i,77-i);   // write address + 65 A or 97 a
   Serial.print(". ");
   delay(5);                         // NEED THIS DELAY! (tests suggest it can be as
                                     // small as delay(3) -- BBR

 Serial.println("Reading Test:");
 for (int i=0; i<32; i++){            // loop for first 20 slots
   Serial.print(i2c_eeprom_read_byte(EEPROM_ADDR, i),BYTE);
   Serial.print(" ");

 // setup for page tests . . .
 byte PageData[30];                   // array that will hold test data for a page
 byte PageRead[30];                   // array that will hold result of data for a page
 for (int i=0; i<30; i++){            // zero both arrays for next test
   PageData[i] = 0;    
   PageRead[i] = 0;
 for (int i=0; i<30; i++) PageData[i] = i+33;  // fill up array for next test char 33 = !

 Serial.println("Writing Page Test:");
 i2c_eeprom_write_page(EEPROM_ADDR, 100, PageData, 28 ); // 28 bytes/page is max

 Serial.println("Reading Page Test:");
 i2c_eeprom_read_buffer( EEPROM_ADDR, 100, PageRead, 28);
 for (int i=0; i<28; i++){
   Serial.print(PageRead[i],BYTE);    // display the array read
   Serial.print(" ");

void loop(){

void i2c_eeprom_write_byte( int deviceaddress, unsigned int eeaddress, byte data ) {
 int rdata = data;
 Wire.send((int)(eeaddress >> 8));    // Address High Byte
 Wire.send((int)(eeaddress & 0xFF));  // Address Low Byte

// Address is a page address, 6-bit (63). More and end will wrap around
// But data can be maximum of 28 bytes, because the Wire library has a buffer of 32 bytes
void i2c_eeprom_write_page( int deviceaddress, unsigned int eeaddresspage, byte* data, byte length ) {
 Wire.send((int)(eeaddresspage >> 8)); // Address High Byte
 Wire.send((int)(eeaddresspage & 0xFF)); // Address Low Byte
 byte c;
 for ( c = 0; c < length; c++)
 delay(10);                           // need some delay

byte i2c_eeprom_read_byte( int deviceaddress, unsigned int eeaddress ) {
 byte rdata = 0xFF;
 Wire.send((int)(eeaddress >> 8));    // Address High Byte
 Wire.send((int)(eeaddress & 0xFF));  // Address Low Byte
 if (Wire.available()) rdata = Wire.receive();
 return rdata;

// should not read more than 28 bytes at a time!
void i2c_eeprom_read_buffer( int deviceaddress, unsigned int eeaddress, byte *buffer, int length ) {
 Wire.send((int)(eeaddress >> 8));    // Address High Byte
 Wire.send((int)(eeaddress & 0xFF));  // Address Low Byte
 //int c = 0;
 for ( int c = 0; c < length; c++ )
   if (Wire.available()) buffer[c] = Wire.receive();

Mike Rice

The code you are using is for a 24LC256... but your chip is a 24WC02. A quick glance at their datasheets reveals an important difference right away... their I2C bus addresses are different.

It is important to always read the datasheet for your part before ever touching the keyboard. There may be more differences than just the bus address.


i read the datasheets but i dont know what to change.... i want to make this one work but dont know what to try... i just want to be able to read and write to it... after i will make my own code... but i know noting in I2C... so this is why im asking for help....

Mike Rice

What I am saying is that these chips are pretty different from each other, you cannot just re-use the code from the 256 chip as-is.

The /02 requires an 8 bit memory address, while the /256 requires a 15 bit memory address. This is due to their respective sizes and organization.

The example code thus sends a two byte address, which your chip will mis-interpret as an 8 bit address followed by data.

There may be other differences as well. In fact, there probably are.

hector albornoz

Until few eeprom I can connect?
What eeprom reference recommended for use with "Arduino 328"?
As you connect the eeprom?
As fits Vcc write protection?

According to what I say, this would be the connection for a eeprom, as it is for two or more epprom? and how we define additional addresses for each eeprom?


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131