Hello Pete.
I've changed the (1) with the () ind the write, but it doesn't make any change. Still wrong data in the EEPROM.
The sketch in now as below :
#include <Wire.h> // for I2C
#define i2caddr 0x50 // device address
byte d=0; // data to store in or read from the EEPROM
void setup()
{
Serial.begin(9600); // Initialize the serial line
Wire.begin(); // wake up the I2C
Serial.println("Writing data...");
for (int i=0; i<257; i++)
{
writeData(i,i);
}
Serial.println("DONE");
Serial.println("Reading data...");
for (int i=0; i<257; i++)
{
Serial.print(i);
Serial.print(" : ");
d=readData(i);
Serial.println(d, DEC);
}
Serial.println("DONE");
}
// writes a byte of data in memory location addr
void writeData(unsigned int addr, byte data)
{
Wire.beginTransmission(i2caddr);
// set the pointer position
//Wire.write((int)(addr >> 8));
Wire.write((int)(addr & 0xFF));
Wire.write(data);
Wire.endTransmission();
delay(10);
}
// reads a byte of data from memory location addr
byte readData(unsigned int addr)
{
byte result;
Wire.beginTransmission(i2caddr);
// set the pointer position
//Wire.write((int)(addr >> 8));
Wire.write((int)(addr & 0xFF));
Wire.endTransmission(1);
Wire.requestFrom(i2caddr,1); // get the byte of data
result = Wire.read();
return result;
}
void loop()
{
}
By the way. I'm having so hard time with this I2C EEPROM, would you have any good link with some sketches very well explained. I haven't been able to find something that could help me properly yet !
At the end, my project is to reprogram a Laser printer chip.
So, read an EEPROM (brand new and already programmed), then, write the data to the old one, so I've got a spare one.
I'll need some advice to do this. I've already read the data of the new 24C04.
I'll now need to inject these data in the old one.