SPI on SAMD21 Mini

I have dozens of the SAMD21 Mini Breakout boards and we have used them for many projects. They have worked fine. At the end of last week, I was working on some software for a spectral analyzer and all of a sudden the SPI display stopped working. I have spent many days debugging. I eventually thought I must have damaged the display and didn’t have a replacement on hand, so built a new system with a different SPI display. And then it too didn’t work. I had a different system with a very small SPI OLED display and that worked. I looked at the code and it happened to be using software SPI and not hardware SPI. A bunch more digging and here is what I have found.

In Arduino IDE 2.1.0 with all updated libraries and board support packages (including SparkFun SAMD 1.8.3), when I specify a “SparkFun SAMD21 Mini Breakout” as my target, it instead automatically switches to “SparkFun SAMD21 Dev Breakout”. I don’t recall this happening previously, but I can’t be sure. Now, there is no way to upload code to the SAMD21 Mini which is compiled as a SAMD21 Mini. Instead it is compiled as a SAMD21 Dev.

The PID/VID for the Mini and the Dev are the same. So I’m not sure how Arduino or anything else could distinguish them.

% cd ~/Library/Arduino15/packages/SparkFun/hardware/samd/1.8.3
% egrep 'dev|mini' boards.txt | egrep 'pid|vid'
samd21_dev.vid.0=0x1B4F
samd21_dev.pid.0=0x8D21
samd21_dev.vid.1=0x1B4F
samd21_dev.pid.1=0x0D21
samd21_dev.build.vid=0x1B4F
samd21_dev.build.pid=0x8D21
samd21_mini.vid.0=0x1B4F
samd21_mini.pid.0=0x8D21
samd21_mini.vid.1=0x1B4F
samd21_mini.pid.1=0x0D21
samd21_mini.build.vid=0x1B4F
samd21_mini.build.pid=0x8D21

The SPI pins are defined differently for Mini and Dev. Looking at the Dev graphical datasheet, I don’t even see pins 22,23,24. Not sure what is going on here - are those the pins on the “Legacy SPI header”? Per the graphical datasheet, both Mini and Dev should have same pin numbers for SPI.

% cd ~/Library/Arduino15/packages/SparkFun/hardware/samd/1.8.3/variants
% grep 'define PIN_SPI' SparkFun_SAMD_Mini/variant.h SparkFun_SAMD21_Dev/variant.h 
SparkFun_SAMD_Mini/variant.h:#define PIN_SPI_MISO         (12u)
SparkFun_SAMD_Mini/variant.h:#define PIN_SPI_MOSI         (11u)
SparkFun_SAMD_Mini/variant.h:#define PIN_SPI_SCK          (13u)
SparkFun_SAMD_Mini/variant.h:#define PIN_SPI_SS           (10u)
SparkFun_SAMD21_Dev/variant.h:#define PIN_SPI_MISO         (22u)
SparkFun_SAMD21_Dev/variant.h:#define PIN_SPI_MOSI         (23u)
SparkFun_SAMD21_Dev/variant.h:#define PIN_SPI_SCK          (24u)

Looking at the variant.h file on github at https://github.com/sparkfun/Arduino_Boa … /variant.h, it hasn’t been modified since 2018. So it must have been working properly for years.

I updated from Arduino IDE 2.0.4 to Arduino IDE 2.1.0 on April 17. I have been using it without problem, but it might be that I’ve been working with other microcontrollers all that time, and this is the first time I’ve gone back to working on the SAMD21 Dev. So maybe it is a bug in Arduino IDE 2.1.0.

So I’m at a loss. How do I coerce Arduino IDE into compiling my code using the SAMD21 Dev definitions? Any other advice on getting SPI to work again? It feels like I’m making some simple stupid mistake, but I can’t figure out what.

Thanks,

Jim

I tried substituting the Mini board definitions in place of the Dev board.

% cd ~/Library/Arduino15/packages/SparkFun/hardware/samd/1.8.3/variants
% sudo mv SparkFun_SAMD21_Dev SparkFun_SAMD21_Dev.SAVE
% sudo ln -s SparkFun_SAMD_MINI SparkFun_SAMD21_Dev
% ls -l
drwxrwxrwx   8 jwright  staff  256 Nov 12  2020 SparkFun_9DoF_M0/
drwxrwxrwx   8 jwright  staff  256 Nov 12  2020 SparkFun_LilyMini/
drwxrwxrwx   8 jwright  staff  256 Nov 12  2020 SparkFun_ProRF/
drwxrwxrwx   8 jwright  staff  256 Nov 12  2020 SparkFun_ProRF_1W/
drwxrwxrwx   8 jwright  staff  256 Apr  5  2021 SparkFun_Qwiic_Micro/
drwxrwxrwx   9 jwright  staff  288 Nov 12  2020 SparkFun_RedBoard_Turbo/
lrwxr-xr-x   1 root     staff   18 Jun 20 11:09 SparkFun_SAMD21_Dev@ -> SparkFun_SAMD_Mini
drwxrwxrwx   8 jwright  staff  256 Jun 20 10:05 SparkFun_SAMD21_Dev.SAVE/
drwxrwxrwx   7 jwright  staff  224 Apr  5  2021 SparkFun_SAMD51_MicroMod/
drwxrwxrwx   7 jwright  staff  224 Nov 12  2020 SparkFun_SAMD51_Thing_Plus/
drwxrwxrwx   8 jwright  staff  256 Nov 12  2020 SparkFun_SAMD_Mini/

I quit and restarted Arduino IDE. Now it identifies my board as SparkFun SAMD21 Dev Breakout. Progress. I can compile the code, and if I print the MISO/MOSI/SCK defines, I can see they now have appropriate values.

However, SPI still doesn’t work. I have a logic analyzer on all the SPI pins, and it just isn’t doing the right thing. No clock, and no data. The chip select line toggles some but that is it.

I am using a cheap ILI9341 display, and the Adafruit library. What had been working for months was:

#define TFT_CS                          10
#define TFT_DC                          6

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

That still doesn’t work. It should be using the native hardware SPI on the board, and it did in the past. If instead I do this, it works.

#define TFT_MOSI                        11
#define TFT_MISO                        12
#define TFT_SCK                         13
#define TFT_CS                          10
#define TFT_DC                          6
#define TFT_RST                         7

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST, TFT_MISO);

I believe that is using software SPI. Note that I am using all the same pins that hardware SPI ought to be using - I didn’t change my wiring at all. At least it works so I can continue to try to make progress on my real task, but it leaves open the question of why hardware SPI on the SparkFun SAMD21 Mini no longer works when using Arduino.

Maybe something in the IDE is broken. You might try going back to an older version too see if that works.

Grabbed Arduino IDE 2.0.4. Using that, hardware SPI for the ILI9341 display works, and hardware SPI for the SD card adapter also works. Neither display nor SD work with hardware SPI with Arduino IDE 2.1.0. So apparently a bug in the new IDE release.

I submitted a bug report. They ask that I check the nightly builds, and the current nightly build (nightly-20230620) works. I submitted the report, and hopefully the problem will remain fixed. https://github.com/arduino/arduino-ide/issues/2108

Hey!

That is quite odd. I treid to test the [SAMD21 Mini Breakout with the [SerLCD’s SPI pins. The example code seemed to work fine using the following on Windows 10:

  • Arduino IDE v2.1.0

  • Arduino SAMD (32-bits ARM Cortex-M0+) Boards v1.8.13

  • SparkFun SAMD (32-bits ARM Cortex-M0+) Boards v1.8.9

Looking further into the [issue that you filed on GitHub, it looks like this might be resolved in a future Arduino IDE release. Let us know if this issue comes up in future release. If it does, we can try to see if there is something we can do to help with the SAMD21 board definitions.](Hardware SPI does not work with Arduino IDE 2.1.0 · Issue #2108 · arduino/arduino-ide · GitHub)](https://www.sparkfun.com/products/16398)](https://www.sparkfun.com/products/13664)