-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero-length read and write should be allowed by I2C HAL #678
Comments
That's the thing, the hardware does not support it. For the details I'll let you have a look at the datasheet but the TL;DR is that the hardware handles the transfer of the address but the only way to make it send the address is to send at least 1 byte of data, hence the impossibility to send 0-length transaction. |
We could do something like micropython does, and implement the zero-length transaction in software, transparent to the caller: |
This would require to either make the i2c driver explicitly require a time reference or make it rely on the assumption that another time reference (at known frequency) is available somewhere. |
Yes, it's probably a bad idea to do this implicitly like in micropython. This transparency may be nice for the caller, but it's far from zero-cost. (In the end, all I'm saying is that we shouldn't just close this ticket with reference to hardware capabilities, but handle it as a valid feature request.) |
Indeed, I agree this is a valid usecase and should not be dismissed. On the other hand, we do not intend to compensate for hardware limitations by emulating bitbanging etc. A wrapper for I2C that take the I2C peripheral, the pins and a time reference to use it would be good to me. As in:
|
As discussed in rp-rs#678, the hardware does not support zero-length read/write transactions.
Thanks for the prompt response! That makes sense, after studying the register interface for a little bit. I've opened a PR to add these details to the documentation for the relevant I2C errors. |
Masters can probe if an address is responding by sending a "zero-length" transaction, containing only the address bits, read/write bit, and the first slave ACK.
This is a de-facto standard in I2C. It's formalized in at least one spec that I'm aware of, as "acknowledge polling":
Right now, the RP2040 I2C HAL validates that the TX and RX buffers are non-empty, which prevents such transactions:
rp-hal/rp2040-hal/src/i2c/controller.rs
Lines 109 to 122 in a12bcda
As long as the RP2040 hardware supports it, I think this is an unnecessary restriction that should be removed.As discussed below, this is a hardware limitation, but zero-length transactions could be implemented in software.
The text was updated successfully, but these errors were encountered: