Arduino Boards Manager

Although I verified that changes make an I2C interface work as expected, that’s not the end of things.

I now discover that the SPI stuff is totally borked.

Lines 71-75 of pins_arduino.h for the XIAO RP2040 variant look like this:

// SPI
#define PIN_SPI_MISO  (16u)
#define PIN_SPI_MOSI  (19u)
#define PIN_SPI_SCK   (18u)
#define PIN_SPI_SS    (17u)

Now, GPIO pins 16-19 aren’t brought out to the XIAO header, so this could never work. The SS can be reassigned by the user when invoking SD.begin(), but the other stuff is fixed in the SPI interface software.

I modified the arduino_pins.h and I modified my SD test program from a previous thread so that I could test a microSD card plugged into my XIAO Expansion Board, which uses PIN_D2 as the Chip Select for the SD Card.

Comments from the attached example:

/*  
 * As of April 6, 2022, The Seeed XIAO RP2040 Board package, version 2.7.2,
 * has incorrect assignments for PIN_SPI_MISO, PIN_SPI_MOSI, and PIN_SPI_SCK,
 * with the result that SPI functions will not work.
 * I changed lines 71-75 to make assignments consistent with XIAO RP2040
 * pinout diagrams.
 * 

Here are those lines in the distribution
// SPI
#define PIN_SPI_MISO  (16u)
#define PIN_SPI_MOSI  (19u)
#define PIN_SPI_SCK   (18u)
#define PIN_SPI_SS    (17u)

To get SPI to work as expected and as indicated on the 
XIAO RP2040 pinout diagram, I changed those lines to

// SPI
#define PIN_SPI_MISO  (4u) // davekw7x: PIN_D9  --- was (16u)
#define PIN_SPI_MOSI  (3u) // davekw7x: PIN_D10 --- was (19u)
#define PIN_SPI_SCK   (2u) // davekw7x: PIN_D8  --- was (18u)
#define PIN_SPI_SS    (1u) // davekw7x: PIN_D7  --- was (17u)

 *
 */

Bottom line: I guess that, when the Seeed guys copied the mbed Raspberry pi pico file to the XIAO rp2040 pins_arduino.h, they forgot to check the SPI pins.

I attached my SD test sketch in case anyone is interested. This is the same as the sketch that tested the XIAO, with the only significant change that uses PIN_D2 as the chip select. The output from this one looks like the one in the other thread.

Original XIAO sketch is here:

Regards,

Dave

XIAO_Rp2040_Daves_SD_Test.zip (2.2 KB)

1 Like