[fpc-pascal] FPC/Lazarus on RPi4 - How to read/write I2C connected EEPROM?
giuliano.colla at fastwebnet.it
Sun Apr 2 00:22:13 CEST 2023
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 RaspberryPi4.
> 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 itself.
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.
Do not do to others as you would have them do to you.They might have different tastes.
More information about the fpc-pascal