Skip to content

I2CTarget.request() always blocks (even with timeout=-1) #7241

@s-ol

Description

@s-ol

CircuitPython version

error present in:

Adafruit CircuitPython 8.0.0-beta.3, RP2040 Stamp with rp2040
Adafruit CircuitPython 8.0.0-beta.4 on 2022-10-30; RP2040 Stamp with rp2040

problem absent in:

Adafruit CircuitPython 8.0.0-beta.1 on 2022-10-01; RP2040 Stamp with rp2040

Code/REPL

import board
from i2ctarget import I2CTarget

i2c_pins = {'scl': board.GP21, 'sda': board.GP20}
i2c = I2CTarget(**i2c_pins, addresses=(0x33,))

while True:
  print("start")
  req = i2c.request() # also happens with timeout=-1, timeout=0.000001
  if not req:
    continue

Behavior

It blocks in the first iteration:

start

then nothing happens until interrupted with CTRL+C:

Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
KeyboardInterrupt:

OTOH in beta.1, it will keep on looping:

start
start
start
start
start
start
start
start
start

Description

I noticed that on two identical boards I assembled a few weeks apart, i2c works on one but not the other. One board was on 8.0.0b3 and I tried updating it to 8.0.0b4 but it still didn't work. The other board is on 8.0.0b1 and works as expected (and as the documentation states).

Additional information

This can be worked around (poorly) by specifying a relatively low but nonzero timeout value, e.g. i2c.request(timeout=0.005), and wrapping the call in try/exept.

However going too low with the timeout (0.00001 for example) again causes it to just block, which is odd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions