Two I2C reads with no STOP in between #19
-
|
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
I found a workaround: I can always read the maximum length that a register can be (64 Bytes), independently of the reported byte count N. I get a bunch of extra zero-bytes that can be thrown away after the read is complete. It is quite wasteful, as most registers are only 4...8 bytes, but it does seem to work. Alternately, I could do two register reads: First, read only a single byte (the byte count). Then read the same register number again with the determined length. That should work unless the register length changes in the meantime, which should be very rare. |
Beta Was this translation helpful? Give feedback.
-
|
Code for the wasteful workaround (reading max. number of bytes): |
Beta Was this translation helpful? Give feedback.
-
|
Hello. Reading a maximum number of bytes and discarding the ones that are not useful is what SMBus.read_block_data does. On the other hand, it is not so wasteful. I2C write/reads commands are issued every 2 ms or more due to USB polling interface. See Internal details. So reading 8 bytes and reading 60 takes almost the same time depending on the I2C bus speed. To read 64, you must issue two read commands to the MCP2221. So it's a little wasteful, but really not much. |
Beta Was this translation helpful? Give feedback.

I found a workaround: I can always read the maximum length that a register can be (64 Bytes), independently of the reported byte count N. I get a bunch of extra zero-bytes that can be thrown away after the read is complete. It is quite wasteful, as most registers are only 4...8 bytes, but it does seem to work.
Alternately, I could do two register reads: First, read only a single byte (the byte count). Then read the same register number again with the determined length. That should work unless the register length changes in the meantime, which should be very rare.