← index #13536Issue #13280
Off-topic · high · value 4.031
QUERY · ISSUE

RP2040 I2C bus breaks if pins are changed at runtime

openby desultoryopened 2024-01-27updated 2024-02-12

MicroPython v1.22.1 on 2024-01-05; Raspberry Pi Pico with RP2040

If I attempt to re-init the bus on another set of pins, things break and cannot recover until I do a full hardware reset:

>>> from machine import Pin, I2C
>>> a = I2C(1, freq=400000, scl=27, sda=26)
>>> a.readfrom_mem(118, 0xA1, 1)
b'K'
>>> a = I2C(1, freq=400000, scl=3, sda=2)
>>> a.readfrom_mem(118, 0xA1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO
>>> a = I2C(1, freq=400000, scl=27, sda=26)
>>> a.readfrom_mem(118, 0xA1, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 5] EIO

I'm not sure how else I can recover from this other than unplugging it and plugging it back in, soft resets do not correct the issue.

CANDIDATE · ISSUE

I2C readfrom_mem throws EPERM on Portenta C33

closedby sebromeroopened 2023-12-27updated 2024-01-31
bugport-renesas-ra

I'm on MicroPython v1.22.0 on 2023-12-27; Arduino Portenta C33 with RA6M5 and I just ran
a simple I2C read ~that worked fine under 1.21 (after merging https://github.com/micropython/micropython/pull/12978)~. It now throws an exception EPERM. It does however still work with SoftI2C.
~I wonder what changed in the mean time in the Renesas port~ 🤔
To reproduce it, run the following with the values adjusted for you I2C peripheral:

from machine import I2C, Pin, SoftI2C

buses = [I2C(0), SoftI2C(scl=Pin('P408') , sda=Pin('P407'))]

for bus in buses:
    print("Trying bus", bus)
    try:
        data = bus.readfrom_mem(0x21, 0x1c, 0x1) 
        print(data)
        print("Success on bus", bus)
    except Exception as e:
        print(f"Read failed on bus {bus}: {e}")

With my setup it prints the following:

Trying bus I2C(0, freq=400000, scl=P408, sda=P407)
Read failed on bus I2C(0, freq=400000, scl=P408, sda=P407): [Errno 1] EPERM
Trying bus SoftI2C(scl=P408, sda=P407, freq=500000)
b'\xb8'
Success on bus SoftI2C(scl=P408, sda=P407, freq=500000)

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied