Address problems with External I2C EEPROM

Hi,

I think im missing something really simple and its driving me nuts.

Im using the example for the R/W to the I2C EEPROM found here:

I2C EEPROM

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) 
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
 
  delay(5);
}
 
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;
}

I am writing to and reading from the EEPROM just fine when i send one data value:

  writeEEPROM(disk1, 1, 123);
  Serial.println(readEEPROM(disk1, 1), DEC);
  Serial.println("");

But when i try to send a different data value to store in a different address, all im getting in the Serial Monitor is "123" then "200", instead of "123" then "456".

  writeEEPROM(disk1, 1, 123);
  Serial.println(readEEPROM(disk1, 1), DEC);
  Serial.println("");


 writeEEPROM(disk1, 2, 456);
 Serial.println(readEEPROM(disk1, 2), DEC);
 Serial.println("");

Any pointers? I know its got to be something simple.

It takes time to write EEPROM. Maybe you didn't wait long enough for the programming time to elapse. There may be a way to read the status, so you know exactly when that is.

456 is > 255, 8 bits can only hold 0 to 255. Do the function handle 16-bit values?

Thankyou CrossRoads!

That makes complete sense. I cant believe i was trying a larger number than 255 in my test code as my data never goes higher than 255!!!

I'm now going to go and bang my head on the wall for missing something so simple! Beer to you my friend!