M0/SAMD21 SPI on SERCOM2

Hi',

I'm working on a personal project based on Arduino M0. I'm using a SD card and a TFT display (ILI9341).
They both work with SPI and it seems that there is some incompatibility when they are both on the same bus.

I give many try but can't figure this out.
The other solution which could be nice is to setup an available SERCOM to get another hardware SPI.

I already use secondary serial (on SERCOM5), everything went fine but SPI on SERCOM2 is driving me crazy.
There are, as you probably know, some very good articles (like this one : SERCOM Adafruit) but nothing at all even after spending hours and hours double checking everything.

I try with the 2 components individually as they both can handle another SPI hardware but none of them work alone on SERCOM2.
With default SPI, my 2 examples sketchs work fine.

Does someone know what could be the culprit ?

Attached, the 2 projects I'm using to test.
No way to use software SPI :smiley:

graphicstest.ino (1.35 KB)

wipe.ino (675 Bytes)

In my reading of the Arduino M0 variant files the correct definition of your SPI interface is

SPIClass mySPI (&sercom2, 3, 5, 4, SPI_PAD_2_SCK_3, SERCOM_RX_PAD_1);

because MISO is on pin 3 which is SERCOM2.PAD[1], MOSI is on pin 4 which is SERCOM2.PAD[2] and SCKL is on pin 5 which is SERCOM2.PAD[3].

Have you tried with that?

I double check and some boards seem to have D2 and D4 reversed !
So you may have right (and I was hoping a lot) but I'm using a Robodyn M0 and SERCOM2.2 is D4.
There was a mistake on pinPeripheral but no more chance.

My priority is to use SERCOM1 (MOSI = D11, MISO = D12, CLK = D13) :

Here is my code :

#include "SPI.h"
#include "wiring_private.h" // pinPeripheral() function
SPIClass mySPI (&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(&mySPI, TFT_CS, TFT_DC);


void setup() {
  mySPI.begin();

  // Assign pins 11, 12, 13 to SERCOM functionality
  pinPeripheral(11, PIO_SERCOM);
  pinPeripheral(12, PIO_SERCOM);
  pinPeripheral(13, PIO_SERCOM);

  tft.begin();
}

Here is my last sketch.
Could someone check outputs with an oscilloscope ?

MISO = 12
SCK = 13
MOSI = 11

graphicstest-m0.ino (2.18 KB)

I try something very simple, put a LED on SCK and MOSI
With default hardware SPI, LED is flickering
With SERCOM1, LED stays off

So no signal on ports D11 & D13, this is really annoying.
Any clue ?

So you may have right (and I was hoping a lot) but I'm using a Robodyn M0 and SERCOM2.2 is D4.

Why are you writing you have an Arduino M0 if you have an incompatible clone? Please don't waste our time!

quichedood:
I double check and some boards seem to have D2 and D4 reversed !

That is one of the differences between the Arduino.org M0, and the Arduino.cc Zero. The M0 is no longer produced, the Zero is the current board.

pylon:
Why are you writing you have an Arduino M0 if you have an incompatible clone? Please don't waste our time!

Well don't need to be so angry, Arduino clone are not "incompatible" clone, they are based on the same chip.
So OK you're right there could be some differences but as you can see this is probably not the problem here.

To be clear I'm working on my own PCB (based on a SAMD21G18A) but tests are made on an Arduino (an M0 clone) because that's much easier.

Maybe I'm missing something, that's why I'm here.
Hope you don't waste too much time on my thread :wink:

BJHenry:
That is one of the differences between the Arduino.org M0, and the Arduino.cc Zero. The M0 is no longer produced, the Zero is the current board.

Yes, pylon point this out, I had never payed attention before.
Unfortunately this doesn't seem to be the only thing.

The wired thing is that I can't see any CLK or MOSI signal on defined pins.
Does these examples could work on "Zero" and not on "M0" ? I would be pretty surprised