I am attempting to set up SPI (MOSI,MISO,CLK,CS) on either set of D3-6 or D10-13.
I am connecting it to a sd card breakout.
I have followed the instructions listed on:
https://learn.sparkfun.com/tutorials/ad … ing-an-spi
I am able to get this working using the D10-13 pins with the “mini” version of the SAMD21 breakoutboard, but need to get this working on the dev.
I have tried doing something such as:
#include <SPI.h>
#include "wiring_private.h"
SPIClass SPI2 (&sercom2, 3, 5, 4, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_1);
void setup() {
SerialUSB.begin(9600);
SPI2.begin();
pinPeripheral(3, PIO_SERCOM_ALT);
pinPeripheral(4, PIO_SERCOM_ALT);
pinPeripheral(5, PIO_SERCOM);
while (!SerialUSB) {
; // wait for serial port to connect. Needed for native USB port only
}
I taken out the SD.h items as I know that part works on the mini variant.
I have also tried updating the variant.h file in the “SparkFun_SAMD21_Dev” folder to replicate the part of the “mini” version to look like this:
/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1
#define PIN_SPI_MISO (12u)
#define PIN_SPI_MOSI (11u)
#define PIN_SPI_SCK (13u)
#define PIN_SPI_SS (10u)
#define PERIPH_SPI sercom1
#define PAD_SPI_TX SPI_PAD_0_SCK_1
#define PAD_SPI_RX SERCOM_RX_PAD_3
static const uint8_t SS = PIN_SPI_SS;
static const uint8_t MOSI = PIN_SPI_MOSI;
static const uint8_t MISO = PIN_SPI_MISO;
static const uint8_t SCK = PIN_SPI_SCK;
Whats interesting is when I do change it this way I can see my SD card flicker like it is commuinicating but any SD function fails.
My questions are:
-
Does anyone have a successful way of adding all 4 SPI pins to the dev variant?
-
I believe I may be missing a pin from the tutorial, the CS/SS pin. Is there a way to add this the same way it works on the mini variant?
-
I have attempted to use the “legacy SPI” header, but there is no CS/SS pin there for me to use. Am I missing something, is CS/SS not always needed?