Skip to content

Rp2040 i2ctarget support #6758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 15, 2022
Merged

Rp2040 i2ctarget support #6758

merged 2 commits into from
Aug 15, 2022

Conversation

gamblor21
Copy link
Member

For #4536 adding support for I2C Target for the RP2040 based on work by @kstillson and @im-redactd.

Test code from my KB2040

import board
from i2ctarget import I2CTarget

target = I2Ctarget(board.D7, board.D6, [0x41])

while True:
    request = target.request()
    if request is not None:
        if request.is_read:
            print("Write request ")
            request.write(b'B')
        else:
            r = request.read()
            if r == "T":
                print("Read a T")

And test controller code

import board
import time

i2c = board.I2C()

while True:
    i2c.try_lock()

    print("Sending T")
    i2c.writeto(0x41, b'T')
    time.sleep(1)

    t_bytes = bytearray(1)
    i2c.readfrom_into(0x41, t_bytes)
    print("Read ", t_bytes)
    i2c.unlock()
    time.sleep(5)

@microdev1 microdev1 added enhancement rp2040 Raspberry Pi RP2040 labels Aug 14, 2022
Copy link
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.

Thank you!

@tannewt tannewt merged commit 3fbddfd into adafruit:main Aug 15, 2022
@wattsie
Copy link

wattsie commented Aug 17, 2022

Awesome work all...
I am about a week or two away from finishing 3d printing and wiring up eight RP2040's to a single Pi4 over the i2c bus.
Look forward to testing this code.
Cheers.

@tannewt
Copy link
Member

tannewt commented Aug 17, 2022

Awesome work all... I am about a week or two away from finishing 3d printing and wiring up eight RP2040's to a single Pi4 over the i2c bus. Look forward to testing this code. Cheers.

Beware that (I think) this CP API uses I2C clock stretching and that Pi's are notorious for not supporting clock stretching. Clock stretching is used while waiting for python to respond.

@wattsie
Copy link

wattsie commented Aug 19, 2022

Awesome work all... I am about a week or two away from finishing 3d printing and wiring up eight RP2040's to a single Pi4 over the i2c bus. Look forward to testing this code. Cheers.

Beware that (I think) this CP API uses I2C clock stretching and that Pi's are notorious for not supporting clock stretching. Clock stretching is used while waiting for python to respond.

Thanks I will check/test it out...

Any idea if the Pico has a limited of a single target address?
I see the constructor is being passed an array, but it the count is greater than one it fails with a warning.

Cheers.

@gamblor21
Copy link
Member Author

Any idea if the Pico has a limited of a single target address? I see the constructor is being passed an array, but it the count is greater than one it fails with a warning.

The Pico does limit it to one. The atmel-samd port can support more then one, but ESP and RP2040 only support a single address.

In theory you could set up both I2C chip peripherals as I2C targets and have two addresses that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement rp2040 Raspberry Pi RP2040
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants