I’m connecting a SAMD51 Thing Plus to a Raspberry Pi Compute Module over i2c. When the Pi performs an I2C operation the SAMD51 ceases to respond. I’ve ran the same code with an Uno and had no issues. I’m at a loss for what to do next, any advice?
I2C is wired into directly into SDA(D20), SCL(D21) for the SAMD51, and A4(SDA), A5(SCL) for the Uno. On the Pi I have it wired directly into the hardware I2c bus and configured to show up as dev/I2C-1,
I’ve created a sketch just to demonstrate this issue:
#include <Wire.h>
// I2C address
#define ADDR 0x08
void setup() {
// Serial.begin(9600); // uno
Serial.begin(115200); // thingplus
Wire.begin(ADDR);
Wire.onRequest(requestHandler);
Serial.println("Setup complete");
}
void loop() {
Serial.println(millis());
delay(1000);
}
void requestHandler() {
Serial.println("Req: responding 6 bytes");
// response message
Wire.write("ping ");
}
Compile, upload and serially connect to SAMD51:
arduino-cli compile -v --fqbn SparkFun:samd:samd51_thing_plus ./sketches/i2ctest && \
arduino-cli upload -v -p /dev/ttyACM0 --fqbn SparkFun:samd:samd51_thing_plus ./sketches/i2ctest && \
sleep 2 && \
cat /dev/ttyACM0
After uploading the program to the SAMD51 I verify over serial that the time is being printed then I run i2cdetect on the Pi:
$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
As you can see, no devices show up and at this point the SAMD51. As soon as I run i2cdetect the Thing Plus stops printing timestamps. The result is the same for i2cdetect, i2cget or a C program I wrote to handle I2C operations on the Pi.
Here you can see what happens when I run i2cget for the SAMD51:
$ i2cget -y 1 0x08
Error: Read failed
Once again the Thing plus stops logging serially, the message in the request handler, “Req, responding 6 bytes” is never printed.
Whereas when I run the program on UNO, everything is nominal.
After switching to serial at 9600 I compile, upload and listen to serial:
arduino-cli compile -v --fqbn arduino:avr:uno ./sketches/i2ctest && \
arduino-cli upload -v -p /dev/ttyACM0 --fqbn arduino:avr:uno ./sketches/i2ctest && \
sleep 2 && \
cat /dev/ttyACM0
On the Pi we run I2c detect to find the device at address 0x08:
$ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- 08 -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- 1a -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
After running detect, the Uno still sends timestamps.
Running i2cget also works as expected:
$ i2cget -y 1 0x08
0x50
The Uno successfully logs, “Req, responding 6 bytes” and continues to output timestamps.