Hi.
I had already some problem with I2C Eeprom, but bit by bit I'm getting sorted out.
I've used Nick Gammons' I2C scanner and found my Eeprom is a 4kb, so I find 2 devices 0x50 and 0x51 on the same Eeprom.
Here is Nick Gammons' I2C scanner I've used.
// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011
#include <Wire.h>
void setup() {
Serial.begin (9600);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
Then, to read i'm using this :
#include <Wire.h>
#define disk1 0x50
void setup(void){
Serial.begin(9600);
Wire.begin();
unsigned int address = 0;
for (address = 0; address < 4096; address++)
{
Serial.print(address);
Serial.print("\t");
Serial.print(readEEPROM(disk1, address), DEC);
Serial.println();
}
}
void loop()
{
}
byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
byte rdata = 0xFF;
Wire.beginTransmission(deviceaddress);
Wire.write((int)(eeaddress >> 8)); // MSB
Wire.write((int)(eeaddress & 0xFF)); // LSB
Wire.endTransmission();
Wire.requestFrom(deviceaddress,1);
if (Wire.available()) rdata = Wire.read();
return rdata;
}
But I've got only 255 value in all world adress.
If I take off this part of code :
Wire.write((int)(eeaddress >> 8)); // MSB
I've can read till #255 the right value, then on #256 I'm reading back #0 value.
How can I do for correctly addressing world further than 255 ?