Ok, so I put back the 5kOhm pull up resistor and now it still works fine.
I don't know what I've done, maybe using a wrong piece of code.
The Eeprom's reference I'm using are hard to read.
I've one :
ST CHN F
24C02 6
K0C828
I can write and read till 256 value in it. If I write, then read more than 256 value, the #256 store the same value as #0 and so on.
The second one I'm using is :
24C04
BL116
But the reference is very hard to see, so there might be something after the 4.
It behaves the same way as the first one despite it should be double size in memory !!!!
Here is the code I'm using :
#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<258; i++)
{
writeData(i,i);
}
Serial.println("DONE");
Serial.println("Reading data...");
for (int i=0; i<258; 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();
while(1) {
Wire.beginTransmission(i2caddr);
if(Wire.endTransmission() == 0)break;
}
}
// 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()
{
}
Both Eeprom work the same with this code.
If I change the code to this, (concerning the way of addressing) I've got only 255 in all the bytes.
#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<258; i++)
{
writeData(i,i);
}
Serial.println("DONE");
Serial.println("Reading data...");
for (int i=0; i<258; 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();
while(1) {
Wire.beginTransmission(i2caddr);
if(Wire.endTransmission() == 0)break;
}
}
// 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()
{
}