I2C EEprom problem

I am trying to use a 24LC128 EEprom (virtually same as 24LC256) and I can’t receive any bytes.

I have a small PCB board that works perfectly with a Basic Stamp. It has 4.7K pullup resistors on the SDA and SCL lines. WP, AO, A1 and A2 are connected to GND. A 0.1uf cap is across the Vcc and Vss.

SDA is connected to Arduino pin 4 and SCL to pin 5. (the leads from the PCB to the Arduino are about 5"

I have examined various code examples and forum messages but see no reason why this code fails. All I get is 0xFF (the initialize value) in the read routine.

Any suggestions?
Thanks!

#include <Wire.h>
#define EEPROM_ADDR 0x50 // I2C Buss address of 24LC128 or 24LC256 EEPROM

int val = 0;
char addr[5];
int memaddr = 0;
int bytesread = 0;

byte edata;

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

void loop(){
Serial.println(“Enter 5 byte memory address”);
bytesread = 0;
while(bytesread<5) { // read 10 digit code
if( Serial.available() > 0) {
val = Serial.read();
if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
break; // stop reading
}
addr[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
Serial.println(addr);
memaddr = atoi(addr);
Serial.print (“Memory addr: “);
Serial.println(memaddr);
for (int i=memaddr; i< memaddr + 32; i++) {
// Serial.println(i);
// Serial.print(i2c_eeprom_read_byte(EEPROM_ADDR, i),BYTE);
edata = i2c_eeprom_read_byte(EEPROM_ADDR, i);
Serial.print(edata, HEX);
Serial.print(” “);
}
Serial.println(””);
}

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

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

SDA is connected to Arduino pin 4 and SCL to pin 5.

Is that analogue pins 4 & 5? It needs to be, not the digital 4 & 5

DUH!!!!!

THANK YOU!!!

I've only had my Arduino a week - after using Basic Stamps for a long while I tend to forget about the analog pins.

Glad I tried the eeprom before I tackled the DS1037 real time clock.

I appreciate your help!

  • Ron