Qwiic Micro - SAMD21 Development Board - SPI not working

My goal is to use SPI to communicate to another device.

Following: https://learn.sparkfun.com/tutorials/sp … okup-guide

pins D2 to D5 are used for SPI but I don’t get an SCL signal on D4.

Following the definition in:

https://github.com/sparkfun/Arduino_Boa … /variant.h

I don’t get why the pins for SPI are define completely different:

#define PIN_SPI_MOSI (14u)

#define PIN_SPI_MISO (15u)

#define PIN_SPI_SCK (11u)

#define PIN_SPI_SS (7u)

#define PERIPH_SPI sercom0

#define PAD_SPI_TX SPI_PAD_2_SCK_3

#define PAD_SPI_RX SERCOM_RX_PAD_1

Additionally this is also not compatible with the information provided in this table: https://learn.sparkfun.com/tutorials/ad … ful-charts

According to this table sercom0 can only have the following pins: D4 A3, D3 A4, D1 D8, D0 D9

I would be very happy, if somebody can tell me, what to do to get SPI working on pins D2 to D5 (MOSI, MISO, SCL, CS) as shown on the pinout diagram.

Thank you very much, Dominic

Has team sparkfun checked this matter yet?

I don’t have a QWIIC micro - SAM21 DB, but the definitions in variant.h are not a pad or a pin. They are an offset to g_APinDescription, which is defined in variant.cpp in the same folder.

Be aware an index starts counting at 0 (zero). Also looked at the schematics.

   offset(.h)   port (.cpp)      board-pin (schema)
MISO -> 14U ->  PA05  connected to D3 (as can be seen on the backside of the board as well)
MOSI -> 15U ->  PA06  connected to D2 (as can be seen on the backside of the board as well)
SCK  -> 11U ->  PA07  connected to D4 (as can be seen on the backside of the board as well)
SS   ->  7u ->  PA04  connected to D7

It is using Sercom0 for SPI. Looking at the datasheet, the Sercom0 pads can be multiplexed to the PA-portnumbers referenced above for the SAM21D.

For TX it is using Sercom0 - pad 2, which is multiplexed to PA06 and thus MOSI (Master OUT) or with the new name COPI (Controller Out, Peripheral In)

For RX it is using Sercom0 - pad 3, which is multiplexed to PA05 and thus MISO (Master IN) or with the new name CIPO (Controller In, Peripheral Out)

So look at the back of the board, do NOT use D5. ( I could not the D5 reference you mentioned) Also, use SPI ( not SPI1). Although the SAM21D can handle 4 wire SPI, the driver is expecting 3-wire with the SS (Chipselect) handled within the sketch (as can be seen within the examples)

Thank you Paul,

the explanation with the variant.cpp makes absolutely sense. Yes, I used SPI and not SPI1. But I still don’t get, how sercom0 can be muxed to those pads?

Following the documentation (https://learn.sparkfun.com/tutorials/ad … amd-boards & https://learn.sparkfun.com/tutorials/ad … ful-charts) SCL for example can only be on pad 1 or 3 with is for sercom0 D3/A4 or D0/D9 but it should be D4. Or is there an error in the table?

My problem is, that there is no communication, and I also can’t measure any signals on that port (SCL / D4). I should be able to measure a clock signal there, right?

Thank you for your help, Dominic

The pads from the SAM21D can be connected to different pins that are printed on the board. Each board can be (often is) different. In case of your first reference, the pins that are called out are those for Redboard-turbo. See the board picture above on the same page but also look at the graphical datasheet for that board https://github.com/sparkfun/RedBoard_Tu … oDev_1.pdf

The pad-to-pin connections on the QwiicMicro are different. Look at the information that is under ‘documents’ on https://www.sparkfun.com/products/15423 . There are the schematics but even more important look at https://cdn.sparkfun.com/assets/7/e/f/d … asheet.pdf. All I can see is that the library and all documentation is correct.

What kind of device are you connecting?

How do you connect? (drawing, picture ?)

Maybe you have a volt meter, maybe LED and resistor that you can connect to the SCK-pin when you do a SPI transfer.

Hi Paul,

I’m connecting to an ADS1120 from TI. I designed my PCB so that I use SPI like in the PDF (https://cdn.sparkfun.com/assets/7/e/f/d … asheet.pdf):

D2 → MOSI

D3 → MISO

D4 → SCK

D5-> CS

and additionally

D7-> Data ready interrupt

In setup() I do the following:

pinMode(5, OUTPUT);

digitalWrite(CS, HIGH);

SPI.begin();

SPI communication to setup the ADS

pinMode(7, INPUT);

attachInterrupt(digitalPinToInterrupt(DRDY), readData, FALLING);

But unfortunately it’s not working.

I used an USB oscilloscope but can’t find any signal on SCK (D4)

Meanwhile I manually wired the pins (MOSI, MISO and SCK) of my PCB to the SPI SMD pads on the backside of the SAMD-Board and changed the code from SPI to SPI1 and that actually works.

But it’s not really a solution, as I designed my PCB already to fit D2 to D4 and I don’t like to reproduce it again.

Do you have any idea why SPI with pins D2 to D4 is not working for me?

Thanks a lot, Dominic

Good to know it works with SPI1 with the same program.

Looks to me that your SAMD has a broken SERCOM0. I tried to see whether you could use one of the other SERCOMs, but the others depend on PA11 which is not connected to this board.

As it looks like an interesting board for me to explore further, I have ordered one which I should get tomorrow and then get try as well.

I have just tested a BME280 in SPI mode on the Qwicc micro. After connecting the wires from the BME280 to D2, D3, D4 and D5 according to the graphical interface and uploading the BME280 sketch it all worked as expected. I am afraid it looks like you have an issue with SERCOM0 on your board.

Hi Paul,

thank you very much for your time and all your helpful answers and information.

I would have never thought, to search the mistake in a partially defect SAMD, especially as this board was brand new.

But your conclusion is absolutely true. I managed to get a new board meanwhile as well and with this one everything is also working as it should!

Thanks again and BR,

Dominic