Well, I found a bug in the Seeed XIAO RP2040 board package that borked the I2C.
Here’s a summary:
The RP2040 has two I2C ports, i2c0 and I2c1. Not all pins can be assigned to a given port. It’s in the RP2040 data sheet.
The XIAO RP2040 designates package pins 5 and 6 to be SDA and SCL for I2C using i2c0. These are Arduino pins D4 and D5 (connected to RP2040 GIO Pins P6 and P7) respectively.
Now, here’s the flaw in the ointment: There are two I2C modules on the RP2040, ic0 and ic1. The Arduino Wire object uses ic0 and Wire1 uses ic1.
The Seeed package software defines SDA and SCL to be GIO pins P6 and P7, but these pins can NOT be used with ic0, so I2C for those connections with Wire is doomed. Period.
I tried to imagine (and even tested some ideas) ways to implement user-level software workarounds, but came to the conclusion that library changes would be necessary.
As an outsider, I am not able to peer into the minds of the actual code implementers. (See Footnote). However, I came up with what I think are minimum library changes to make my test program work. Note that I haven’t tested EVERYTHING that might be affected by my changes but, so far, I think my approach is valid.
Here’s the changes: I edited lines 61-65 in the file
Seeduino\hardware\rp2040\1.9.3\variants\Seed_XIAO_RP2040\pins_arduino.h
As follows
#define SDA (28u) /* Change from (6u) davekw7x */
#define SCL (29u) /* Change from (7u) davekw7x */
#define PIN_WIRE1_SDA (6u) /* Change from (26u) davekw7x */
#define PIN_WIRE1_SCL (7u) /* Change from (27u) davekw7x */
And now all is well (at least to the extent that I have tested). I2C looks good on the 'scope, and the target device works as expected.
Some output from the attached slightly-more-edifying test program:
I2C Test Compiled by davekw7x on Dec 20 2021 at 12:01:40
Board is Seeed XIAO RP2040
I changed definitions for SCL, SDA, PIN_WIRE1_SCL, and PIN_WIRE1_SDA
in 'variants\Seed_XIAO_RP2040\pins_arduino.h'
For Wire
#define SDA (28u) /* Change from (6u) davekw7x */
#define SCL (29u) /* Change from (7u) davekw7x */
For Wire1
#define PIN_WIRE1_SDA (6u) /* Change from (26u) davekw7x */
#define PIN_WIRE1_SCL (7u) /* Change from (27u) davekw7x */
With these modifications, here are the default 'Arduino' pin connections
for the Seeed XIAO RP2040
For Wire
SCL is 'Arduino' D3 = GPIO29, and SDA is 'Arduino' D2 = GPIO28
For Wire1
SCL is 'Arduino' D5 = GPIO7, and SDA is 'Arduino' D4 = GPIO6
I2C probe of 0x48 on Wire1 returned 0 at 350 ms
After trying to write bytes to 0x48 on Wire1: err = 0 at 350 ms
Bottom line IWFMYMMV (It Works For Me; Your Mileage May Vary).
Would appreciate feedback from Seeed support people, as I couldn’t find a way to submit an “official” bug report.
Regards,
Dave
I2CForForum.zip (1.5 KB)