24LC256 addressing problem

Hello,

Recently i was using 24LC64 - 64KB EEPROM. everything was working well, without problem. My write code begins I2C communication, then sends 2 bytes of address and one byte of data.

Now i upgraded to 24LC256 because device memory consumption has increased. For 256Kb i need 2^18 addresses and i'm confused how to manage this. I thought using uint32_t type and sending 4 bytesfollowed by 1 byte of data, but this don't work.

I googled case, in fact post authors are using 256KB memory, they send to it only 16bits of address, which can't write byte of data on the adress for example 150 000, because 16bit max value is 64 535.

So, please advice me something. thanks in advance.

I believe there is some confusion with bits and bytes.

The 24LC256 is 256kbits or 32kbytes. It should be addressed like the smaller eeprom you were using with address high byte and low byte sent before the data byte.

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data ) 
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));
  Wire.write((int)(eeaddress & 0xFF)); 
  Wire.write(data);
  Wire.endTransmission();
  delay(5);
}

The code is above, and if i write byte data = 213, and i have address 0, it will occupy addresses from 0 to 8?

it will occupy addresses from 0 to 8?

No, there will be 8 bits (one byte) stored in address 0.

check - Arduino Playground - LibraryForI2CEEPROM -