Hi, I need help with understanding this I2C eeprom
The code ive got sort of works, i can write a byte (or more) to “some” address and read “something” back in. But the addressing part does not work, it always returns the last value written.
For a start, you’re addressing is wrong for this device. The address is a single byte. The device is paged with 16 bytes per page so the address byte will be 0 to 127. This means you have to read and write 1 to 16 bytes at the same time. If you only want to change a single byte, you need to read the number of bytes that it fits into for that page, write the new value to the buffer and then write the buffer back out to the device.
I just don’t get it.
on page 15 of the datasheet there’s a byte write, and page 16 there’s a page write. So I think you can read or write 1 byte at a time, as well as read a page of 16 bytes.
as I understand it, to construct a write buffer I need at least 3 bytes, 1 for the device select + read/write flag, 1 for the memory address and 1 for my data (a number 0-255 stored as byte)
so I removed buffer[1] from the code, but doesn’t buffer[0] when right shifted 8 places always return 0?
where’s the eeprom data address then?
Heres what I got now, ive simplified this, and it works the same as before only the last values is stored, addressing does not work (I think I read from and write to address 0 all the time)
I always get the last number either 55 or 86 depending on the order I push the buttons, even after restart of device, so the eeprom works just not the addressing.
The I2C driver takes care of the address. You set this when you create it.
var settings = new I2cConnectionSettings(0x1C); //The slave's address.
settings.BusSpeed = I2cBusSpeed.FastMode;
var controller = I2cController.FromName(FEZ.I2cBus.I2c1);
var eeprom= controller.GetDevice(settings);