[fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?
tsiegel at softcon.com
tsiegel at softcon.com
Sun Apr 2 02:30:02 CEST 2023
Generally, raspberry pi devices connected to other devices will (by
default) use python for their programming. The python libs have all the
setup and tear down code built in. You can use C as well, so I see no
reason why FPC couldn't be used. It's probably going to take some work
though. You'll need to either find the appropriate python files, and
port them to FPC, or convert the C headers into something pascal can
understand. I've never made the attempt to do this, though now that you
bring this up, I might just take a crack at it. Up until now, I've used
C (since I'm not a fan of python) when talking to raspberry connected
devices, but I'm pretty sure I've seen posts where folks were using
other languages such as PHP or Java to talk to the pi devices, so those
header files have most certainly been ported to other languages. It's
possible someone already did the pascal port, though I can't point to
one. I've not been messing with my raspberry pis for the last year or
so because of moving, and things are just now getting back to normal (I
hate moving), and I need a new pi anyhow, so perhaps I will get back to
it this year, but the reason I say this, is because I've not kept up
with the pi forums, so I don't know what's happening around the pi
ecosystems lately, which is why I can't answer the question directly,
though it's certainly more than possible.
Sorry I don't have more solid information for you.
On 4/1/2023 6:22 PM, Giuliano Colla via fpc-pascal wrote:
> Il 01/04/2023 21:56, Bo Berglund via fpc-pascal ha scritto:
>> I need to read and write data to an EEPROM connected by I2C on a
>> The I2C channel is found in /dev as i2c-1:
>> $ ll /dev/i2*
>> crw-rw---- 1 root i2c 89, 1 2019-02-14 11:12 /dev/i2c-1
>> In this channel the EEPROM CAT24C128 is at address 0x50
>> The data on the device is organized as 256 pages of 64 bytes data
>> each AFAIU.
>> I can check the EEPROM using i2c-tools, which I have installed, but I
>> am unsure
>> if the read is correct...
>> Can I use Linux file system commands to read/write the data on the
>> i2c EEPROM
>> memory device and if so how from fpc?
>> I have installed the current versions of Lazarus and Fpc on the RPi4
> I2c is a serial protocol. All what the hardware can see is just a pair
> of bits: a clock line and a data line. I2c-tools provides the required
> software to write and read those two bits. In your case for
> programming the EEPROM and reading it back. The linux kernel uses
> i2c-tools and knows what i2c-tools tell it.
> I don't know if i2c-tools can be required to emulate a block device
> thus providing the system a block device, which then becomes readable
> by any means. But even if it does, and you can read your EEPROM from
> fpc, or whatever software you like, you will not gain any advantage,
> because the reading mechanism will be implemented by i2c-tools, and it
> will be exactly the same when verifying after programming. If reading
> was wrong, it will be wrong again, if it was good it'll be good again.
> Forget about writing. Writing an EEPROM is a complex procedure. If
> i2c-tools knows how to do it, let it do it.
> If you really need an independent verification, you should find an
> adapter which accepts your EEPROM and makes it accessible via a block
> device interface, such as USB. I don't know if such adapter does
> exist, but it's the only way.
More information about the fpc-pascal