smbus2
smbus2 copied to clipboard
read_i2c_block_data response contains length instead of last byte of data
I need help understanding a response I'm getting from read_i2c_block_data(). I'm using I2C bus on RPI.
When I block read certain offset from the device, read_i2c_block_data() gets the following content of msg.data.contents.block:
0f 0d 05 50 00 36 00 34 00 03 80 00 01 00 03 c5 00
^length ^PEC
The smbus2 library cuts the first byte, and gives my python code 13 bytes, as this is the size my script requested. So my script receives:
0d 05 50 00 36 00 34 00 03 80 00 01 00
In other word, I don't receive the last byte of data (03
), and instead I receive the size byte (0d
).
In order to receive the whole message, I need to actually read 14 bytes, and remove the length from my script. Which is unnecessary, but not that bad until I get to 32-byte block. For 32-byte one, there is no way for me to retrieve the last byte. So the smbus2 library effectively allows me to retrieve message of max 31 bytes.
Where is the issue? Is the library implementation flawed? or is it unexpected that the buffer contains the 0f
at start?