I2C eeprom 24c04 - reading problem

Hi,
I’m trying to read data from my Samsung toner chip.
As seen in the picture below,

the printer communicate via I2C protocol with the chip (M24C04-WMN6).
Datasheet here.

Conection (from chip) to Arduino Leonardo
chip Arduino Lonardo
GND----->GND
SCL------>SCL
SDA------>SDA
VCC------>5V

The code: I’ve tried the code from this topic, but it isn’t reading anything (stuck at “Reading 1 byte…”).
From i2c scanner i know the eeprom address of the chip: 0x58 ->0x5F
My code:

#include <Wire.h>

const int EEPROMID = 0x58;
int byte_address=10;
byte exampleByte =0x10;

void setup(){
 Serial.begin(9600);
 Wire.begin();
 delay(5000);//delay for Arduino Leonardo board...
 Serial.println("Program started");
 Serial.println("Reading 1 byte..");
 byte b = eepRead(byte_address);
 Serial.print("read: ");
 Serial.println(b);  
}

void loop(){};

byte eepRead(int address){
 byte data;
 Wire.beginTransmission(EEPROMID);
 Wire.write(address);
 Wire.endTransmission();
 Wire.requestFrom(EEPROMID, 1);
  while(Wire.available()==0);
 data=Wire.read();
 return data;
}

Program returns:

Program started
Reading 1 byte..

Thanks for your help :slight_smile: !

I'm not sure that this statement is required:

 while(Wire.available()==0);

Comment it out and see if it helps.

Pete

Yep… it’s reading the byte but it won’t read another byte:

Code:

#include <Wire.h>

const int EEPROMID = 0x58;

void setup(){
 Serial.begin(9600);
 Wire.begin();
 delay(5000);//delay for Arduino Leonardo board...
 Serial.println("Program started");
 Serial.println("Reading 1 byte from 0x09");
 byte b = eepRead(9);
 Serial.print("read: ");
 Serial.println(b);  
 Serial.println("Reading 1 byte from 0x10");
 b = eepRead(10);
 Serial.print("read: ");
 Serial.println(b); 
}

void loop(){};

byte eepRead(int address){
 byte data;
 Wire.beginTransmission(EEPROMID);
 Wire.write(address);
 Wire.endTransmission();
 Wire.requestFrom(EEPROMID, 1);
  //while(Wire.available()==0);
 data=Wire.read();
 return data;
}

Output:

Program started
Reading 1 byte from 0x09
read: 255
Reading 1 byte from 0x10

I can’t figure out the problem…
Thanks for your answer!

Do you have 4k7 ohm pullup resistors on the SDA and SCL lines?

Pete
P.S.

 Serial.println("Reading 1 byte from 0x10");
 b = eepRead(10);

0x10 and 10 aren’t the same thing :slight_smile:

Between SDA and VCC (5V) 4.67 Kohm resistance
Between SCL and VCC (5V) 4.69 Kohm resistance
I don't think that the connection is the problem because the printer reads fine the chips(got 2 of them and tried both of them and the printer is reading them fine).

It's quite strange: Eeprog program running in a Linux(Ubuntu) is reading just 0xff values at all addresses....

I think I will just connect pin 8 and pin 7 so the chip is read-only and the printer won't be able to increment the page counter from the chip... This way I won't have the change the chip every time I refill the toner.

Thanks for you help!