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

Bo Berglund bo.berglund at gmail.com
Sun Apr 2 10:23:24 CEST 2023

On Sun, 2 Apr 2023 07:31:43 +0200, Christo Crause via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

>On Sat, Apr 1, 2023 at 9:57?PM Bo Berglund via fpc-pascal <
>fpc-pascal at lists.freepascal.org> wrote:
>> Question:
>> Can I use Linux file system commands to read/write the data on the i2c
>> memory device and if so how from fpc?
>To some extent it is possible to handle i2c transactions as file read/write
>operations, but some ioctl calls are required to configure e.g. the device
>address [1]. Take note that only a subset of i2c functionality is available
>using read/write calls. Lazi2cdev [2] uses this approach.
>For finer control over the i2c transactions (for example combined
>write/read transactions) low level ioctl calls are available in Linux.  I
>wrote an i2c class [3] using this approach.
>1. https://www.kernel.org/doc/html/latest/i2c/dev-interface.html
>2. https://github.com/laz2wiringpi/lazI2cdev/blob/master/i2cdev_base.pas
>2. https://github.com/ccrause/rpiplc_pas/blob/main/native/i2c.pas

Thanks for the reply and links!
Then I need to go the low-level way, I guess...

I had hoped it would be a simpler way using OS available functions on RPi.

I have used these EEPROM devices on some Microchip PIC24 projects where I had to
do the nitty-gritty low level stuff myself including bit-banging the I2C bus...

With that approach I have to *read the details* on the EEPROM datasheets to see
how they are handled, unless of course I can port my own i2c code (Ansi-C) to

Luckily on RPi the system is built to allow users to do low-level stuff on the
I/O lines.

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list