1

I have a connected a Raspberry Pi Zero (1.3, no W, running Raspbian 10 (buster) lite) as an I2C slave (clock:GPIO18,data:GPIO19) to a Raspberry Pi 3b (running Ubuntu 20.04.1) as an I2C master(clock:GPIO3,data:GPIO2).

  • The wiring is Dupont style connectors of approximately 20cm length connected directly between the GPIO headers.
  • The only configuration done is to uncomment the dtparam=i2c_arm=on in the config.txt of the boot/firmware directory on both the raspberry pi 3B and the Zero.
  • Packages installed are python3-pigpio and dependencies on the Pi Zero, and python3-smbus on the Pi 3b.

There is barely any load on either of the nodes:

samveen@pi3:~$ cat /proc/loadavg
0.00 0.00 0.00 1/171 2538
...
pi@pi0:~$ cat /proc/loadavg
0.20 0.21 0.18 1/81 720

The connection works when tested with the python3-pigpio I2C slave example and a simple python3-smbus script on the master:

    #!/usr/bin/env python3
    import smbus
    import time

    DEVICE_BUS = 1
    DEVICE_ADDR = 0x09
    bus = smbus.SMBus(DEVICE_BUS)

    def sendData(slaveAddress,reg,data):
        intsOfData = list(map(ord, data))
        bus.write_i2c_block_data(DEVICE_ADDR, reg, intsOfData)

    message=""
    for c in '0123456789abcdef01234567890abcdef0':
        message+=c
        print("sending {} bytes".format(len(message)))
        sendData(DEVICE_ADDR,0x00,message)
        time.sleep(2)

Observations:

  • The communication is rock solid up while message length is 16 bytes or less.
  • Messages longer than 16 bytes do not deliver reliably: the first 16 bytes get delivered fine, but anything past that is non-deterministically received. Out of the 32 messages sent per run of the above script, the best run had only 3 of the 16 longer-that-16-byte messages received correctly.

Question:

  • What can I do to improve the I2C communication between the 2, so that I have completely reliable messaging?

References:

2
  • 1
    Isn't the hardware slave I2C buffer 16 bytes? I suggest you limit messages to that size.
    – joan
    Oct 18, 2020 at 12:13
  • @joan would you point me to the correct documentation for this? (my hope's that you're the best person to answer all pigpio questions :D). also the possibility of how I can extend the 16 byte buffer into a 32 byte buffer? As in which portion of the sources, ligpigpio or pigpiod or the python lib code? I am not in control of message length (final communication endpoint on the master end will not be my code).
    – Samveen
    Oct 18, 2020 at 12:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.