FpWrite to an i2c device doesn't work properly lazarus / 32-Linux ---------------------------------------------------------------------- jpelletier · 2014-06-13 04:19 On Linux, using lazarus and free pascal, I'm trying to use the I2C device by opening /dev/i2c-7 which is a dongle on a parallel port. Hardware is known good and has been tested with known good software. A bus pirate connected on the I2c port detects the peripherals correctly. With the following code, Fpwrite sends 4 bytes 'F0'  instead of sending the 'A' at the slave address 20 (a PCF8574). The result is the same on the bus pirate as sniffer and on an oscilloscope. I have the same result if I use FileWrite instead of FpWrite.   I2c_Address: integer;   test: string;   I2c_Address := $20;   test := 'A';   // handle has been opened correctly, no error reported   if FpIOCtl(handle,I2C_SLAVE, pointer(I2c_Address)) < 0 then ...   // Slave address is set correctly, no error reported ... ...   Fpwrite(handle,test,1); Any ideas? Thanks! ---------------------------------------------------------------------- marcov · 2014-06-13 07:37 Write test[1], "test"  is the address where the pointer is stored, since an ansistrings are dynamic you might also want fpwrite for EINTR and repeat if that occurs. ---------------------------------------------------------------------- avra · 2014-06-13 09:59 You have a working I2C code for DS1307 RTC here: http://forum.lazarus.freepascal.org/index.php/topic,17500.msg96610.htm l#msg96610 There is a hardware abstraction lib for Raspberry Pi Linux. You can take a look here: http://forum.lazarus.freepascal.org/index.php/topic,20991.msg127025.ht ml#msg127025 http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#Accessing_external_ hardware ---------------------------------------------------------------------- jpelletier · 2014-06-14 07:19 I added some code for checking.   WriteLn('Write: Handle = ',I2c_Handle);   Write := FpWrite(I2c_Handle, 'test', 4);   if Write = -1 then Perror('I2cWrite',fpgeterrno); Write: Handle = 20 // Handle corresponds with the one returned by fpopen I2cWrite: No such device or address // output of PError