Skip to content

raspberrypi i2ctarget transactions are spread across multiple requests #10423

Open
@anecdata

Description

@anecdata

CircuitPython version and board name

Adafruit CircuitPython 10.0.0-alpha.6-2-gc6e4d72cd3 on 2025-05-21; Pimoroni Pico Plus 2 W with rp2350b
(adafruit-circuitpython-pimoroni_pico_plus2w-en_US-20250521-main-PR10366-c6e4d72.uf2)

Code/REPL

raspberrypi i2ctarget code (only reads):

import board
from i2ctarget import I2CTarget

I2C_ADDRESS = 0x40

# Pico Plus 2 W
with I2CTarget(scl=board.GP5, sda=board.GP4, addresses=(I2C_ADDRESS,)) as device:
    while True:
        req = device.request(timeout=-1)  # Zero means wait forever, a negative value means check once
        if not req:
            continue
        with req as r:
            inbuf = r.read(-1)  # n – Number of bytes to read (negative means all)
            print(f"READ {len(inbuf)} {inbuf}")

I2C Controller code (only writes):

import time
import board

I2C_ADDRESS = 0x40

# UnexpectedMaker FeatherS3
i2c = board.STEMMA_VERTICAL_I2C()

while True:
    outbuf = bytearray(b'abcd')
    print(f"WRITE {outbuf} ", end="")
    while not i2c.try_lock():
        pass
    try:
        i2c.writeto(I2C_ADDRESS, outbuf)
        print(f"written")
    except Exception:
        print(f"not written")
    i2c.unlock()

    time.sleep(2)

Behavior

I2C Controller output:

WRITE bytearray(b'abcd') written
WRITE bytearray(b'abcd') written
WRITE bytearray(b'abcd') written
WRITE bytearray(b'abcd') written

i2ctarget output:

READ 2 bytearray(b'ab')
READ 2 bytearray(b'cd')
READ 1 bytearray(b'a')
READ 3 bytearray(b'bcd')
READ 1 bytearray(b'a')
READ 3 bytearray(b'bcd')
READ 1 bytearray(b'a')
READ 3 bytearray(b'bcd')

Description

Using post-alpha.6 firmware that incorporates the i2ctarget request deinit fix for raspberrypi. i2ctarget code works as expected on atmel-samd, even with very large transaction payloads. raspberrypi handles 1 or 2 bytes OK, but anything larger gets split across multiple requests unpredictably. The end result is that it's impossible to delineate separate transactions.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbusiorp2Both RP2 microcontrollers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions