Skip to content

RP2040 initial 0 byte I2C write has potentially problematic behavior  #7955

Open
@caternuson

Description

CircuitPython version

Adafruit CircuitPython 8.0.5 on 2023-03-31; Adafruit Feather RP2040 with rp2040
>>>

Code/REPL

import time
import board
i2c = board.I2C()
i2c.try_lock()
i2c.writeto(82, b"")
time.sleep(0.1)
i2c.writeto(82, b"")

Behavior

Code runs fine without any errors. The issue is seen in the scope trace of the resulting traffic. See below.

Description

This behavior seems to be benign in most cases. However, it is potentially the underlying cause of the issue that drove this change:
adafruit/Adafruit_CircuitPython_Nunchuk#34

See that nunchuk PR for a specific example of an actual issue with exception message, etc. However, this issue is being opened generically, mainly to raise awareness of this RP2040 specific behavior in case it is also potentially affecting other use cases.

Additional information

The underlying issue is seen via scope traces of the I2C traffic.

The first writeto looks like this:
scope1

The second writeto looks like this:
scope2

The issue being this large gap seen in the first call:
scope3

As noted by @jepler , the RP2040 does not use the I2C peripheral for 0 byte writes. Instead, it falls back to bitbanging. This may be a clue to what is driving this behavior. See ports/raspberrypi/common-hal/busio/I2C.c.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions