rpi-hal
rpi-hal copied to clipboard
24c02 I2C TEST READ ERROR BUT WRITE WORKING GOOD IN RPI-HAL V5.1
test code ` program project1; uses rpi_hal,pfio,sysutils; var s:string;
begin
RPI_HW_Start([InitHaltOnError,InitGPIO,InitSPI,InitI2C]); writeln('a'); I2C_string_write(RPI_I2C_busgen,$50,$20,#$01+#$02+#$34+#$56,NO_ERRHNDL); writeln('b'); I2C_string_read(RPI_I2C_busgen,$50,$20,2,NO_ERRHNDL,s); writeln(s);
end. `
pi@raspberrypi:~/btest $ sudo ./project1 2019-10-03 10:24:57 WRN SPI_Dev_Init[0x00/00]: /dev/spidev0.0 2019-10-03 10:24:57 WRN SPI_Dev_Init[0x00/01]: /dev/spidev0.1 a b 2019-10-03 10:24:57 ERR I2C_bus_WrRd[0x01/0x50]: failed to read device: (121) Remote I/O error
read 24c02 is error , but write 0x01023456 is OK 。
pi@raspberrypi:~/btest $ i2cdump -y 1 0x50 No size specified (using byte-data access) 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00: 01 02 00 00 81 24 03 00 00 01 68 ff ff ff ff ff ??..?$?..?h..... 10: ff 0b 0c 0e ff ff ff ff ff ff ff ff ff ff ff ff .???............ 20: 01 02 34 56 ff ff ff ff ff ff ff ff ff ff ff ff ??4V............
something more
1) when it need to write more then 8 byte data , it will cover the front address reg , d8(d0) d1 d2 d3 d4 d5 d6 d7 FF FF FF ...........
i think when length( xxxx ) + start address not 8*n , it must be cut .
0 7 8 11 15 66 77 88 99 d0 d1 d2 d3 /cut/ d4 d5 d6 d7 d8 FF FF FF
BUT .............
2) I2C_string_write(........... // I2C_string_read(............ I2C_string_write(............. //failed to read device: (121) Remote I/O error I2C_string_read(.................. @^#&^@!&#@! // it 's working ~~~~~~~~~ :D
something likes chip not end in busy (ACK/NACK) or wait it timeout ?
I2C_string_write(........... //working! sleep(1); I2C_string_read(............ //working! sleep(1); I2C_string_write(............. //working! sleep(1); I2C_string_read(.................. //working!
so................. it's all my problem ?
you can set in /boot/config.txt
dtparam=i2c_baudrate=400000