fix: RP2040 I2C fundamental issues #2031
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is more to open a discussion about the current I2C implementation and the issues with it.
I was experiencing severe stability issues with
I2cSlave
, which I was not experiencing with therp-rs
embedded-hal
crate. The maximum speed possible seems to be 5KHz (as per the current example in the repo, so I assume this problem is tribal knowledge?). This is probably because the current slave implementation doesn't setIC_RX_FULL_HLD_BUS_EN
- which essentially enables clock stretching.The current
I2cSlave
interface seems to be incompatible with clock stretching. I have brought over the "event iterator" interface fromrp-rs
and made it async. This is really sad because the existing interface seemed much nicer to use than the event iterator one.The combination of my changes to
I2c
andI2cSlaveEventIterator
bring things up to 400KHz on my prototype. Unfortunately it also looks like this completely breaksI2cSlave
.Also:
rp-rs
, the system clock is used as for the timing calculations. The peripheral clock makes more sense, so I'm not entirely sure what's correct here.write_read
method added toI2c
(which is required for idiomatic i2c)