Skip to content

Rpi port i2ctarget fixes#10933

Merged
tannewt merged 2 commits intoadafruit:mainfrom
FoamyGuy:rpi_i2c_fixes
Apr 13, 2026
Merged

Rpi port i2ctarget fixes#10933
tannewt merged 2 commits intoadafruit:mainfrom
FoamyGuy:rpi_i2c_fixes

Conversation

@FoamyGuy
Copy link
Copy Markdown
Collaborator

This supercedes #10474. It contains the original commit from 10474 and a new commit that resolves the changes that were requested on that PR.

This also resolves #10423. While looking into this and testing the refactored fix I found this issue and the reproducer code in it and took a quick shot at resolving it with help from claude.

The root cause of 10423 is read_byte was checking the RX FIFO status (RFNE) once and returning 0 immediately if empty. At I2C bus speeds (even 400kHz), the CPU runs much faster than bytes arrive on the wire. So after reading the first 1-2 bytes, the CPU would check the FIFO, find it momentarily empty (the next byte hasn't clocked in yet), return 0, and the shared-bindings read() loop would break — splitting a single 4-byte transfer into two 2-byte reads.

I tested with the reproducer code in the issue and with this fix the pico side is now able to successfully read messages larger than 1 or two bytes. The 4 from the original code work fine and I tested 16 bytes and found it working as well.

MarkEbrahim and others added 2 commits July 11, 2025 18:30
The Rasperry Pi Pico, based on the RP2040, has a register that maintains
the status of I2C interrupt flags called IC_INTR_STAT. The bits of this
register are set by hardware and cleared by software. Before this commit,
the I2CTarget library did not clear the restart bit (R_RESTART_DET) in
this register after an I2C transaction ended, causing the is_restart
field of the i2ctarget_i2c_target_request_obj_t struct to always be true
after the first I2C transaction. This commit causes the restart and stop
bits to get cleared when the I2C transaction ends.

Signed-off-by: Amaar Ebrahim <amaaraebrahim@gmail.com>
@FoamyGuy FoamyGuy changed the title Rpi i2c fixes Rpi port i2ctarget fixes Apr 10, 2026
Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up! One question before we merge.

Copy link
Copy Markdown
Member

@anecdata anecdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed testing results for #10423

Config: M4 I2C Controller writing large packets to an M4 I2C Target and a RP2350 I2C Target. RP2350 I2C Target now reads successfully. Thanks FoamyGuy !

Copy link
Copy Markdown
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the fix!

@tannewt tannewt merged commit f9e6afc into adafruit:main Apr 13, 2026
170 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I2CTarget transactions are spread across multiple requests on raspberrypi

4 participants