[fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?

Bo Berglund bo.berglund at gmail.com
Mon Apr 3 16:53:22 CEST 2023


On Mon, 3 Apr 2023 08:42:12 -0400, "Jeffrey A. Wormsley via fpc-pascal"
<fpc-pascal at lists.freepascal.org> wrote:

>>
>> i2c_read_reg works too inasmuch as it does not error out, but it returns FF
>> whatever addres I read like the i2c-tools command does.
>> I am not sure that it is correct though...
>>
>
>Yes this is expected, as eeproms erase to $FF.  You can write to the same
>byte as many times as you want, as long as you only change 1 bits to 0
>bits.  If you must change a 0 bit to a 1 bit, you have to erase back to $FF
>first.  Be aware that erase means erasing the entire page, and not just a
>single byte.  This is where things like "wear leveling" come into play,
>because a page can only be erased a limited number of times (it used to be
>around 10,000, but maybe newer devices have extended this).  How you manage
>writes to eeprom can be tricky, best to use them for things that don't
>change very often, such as configuration data.
>
>Jeff
>

This is incorrect!
The EEPROM I am talking about is a small 8-pin chip specifically used in IoT
devices to save non-volatile data and these devices are r/w on single bytes.

I have just tested it by executing command line commands to write a set of data
to a specific address and then read it back and verified that it was there.
Then I repeated the process for the same addresses but different data.
Readback again showed only the new data correctly.

What you are talking about might be certain microcontrollers which simulate an
EEPROM memory in their flash program memory data. That flash is commonly
erasable only for full pages. Not the case here...

I am working on using the FreePascal GitHub code and expanding it into a class I
can use in my RPi4 project. Since I want to generalize it as much as possible it
takes a few more hours than I thought...


-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list