Hello,
I was wondering if anyone could help me with my one last issue before I am able to submit my project to my college professor.
After being able to get my SAM D21 NINA-W10 board fully working, I am wondering if it is possible to change one thing for my final board. Previously, I was able to change the GPIO pins for my NINA module, however, I am wondering if it is possible to change the SPI pins? I want to be able to demonstrate what I have learned to my professor, and present my understanding of the SAMD multiplexing system.
To review, I was able to change the GPIO pins used by the NINA-W10 module and I was able to shift the SPI to other SPI port on my board, however, I want to learn how to create one.
To continue, I found that Adafruit has a helpful guide about how to add SPI ports.
After running this code:
#include <SPI.h>
#include “wiring_private.h” // pinPeripheral() function
SPIClass mySPI (&sercom3, 6, 1, 7, SPI_PAD_3_SCK_1, SERCOM_RX_PAD_2);
void setup() {
Serial.begin(115200);
// do this first, for Reasons
mySPI.begin();
// Assign pins 11, 12, 13 to SERCOM functionality
pinPeripheral(1, PIO_SERCOM);
pinPeripheral(6, PIO_SERCOM_ALT);
pinPeripheral(7, PIO_SERCOM_ALT);
}
uint8_t i=0;
void loop() {
Serial.println(i);
mySPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
mySPI.transfer(i++);
mySPI.endTransaction();
}
I was able to see the SPI waves on my oscilloscope, however, I wanted to have this in my boards variants file so I could use it as the SPI Port for the NINA module. Also, the pins that I want to use are PA20, PA21, PA22, PA23 (SERCOM 3).
I then went into the variants files that I created for my board, and in the variants.h, I deleted the previous SPI1 for the Nina module and replaced it with:
//SPI1
#define PIN_SPI1_MISO (6u)
#define PIN_SPI1_MOSI (7u)
#define PIN_SPI1_SCK (1u)
#define PIN_SPI1_SS (0u)
#define PERIPH_SPI1 sercom3
#define PAD_SPI1_TX SPI_PAD_3_SCK_1
#define PAD_SPI1_RX SERCOM_RX_PAD_2
static const uint8_t SS1 = PIN_SPI1_SS;
static const uint8_t MOSI1 = PIN_SPI1_MOSI;
static const uint8_t MISO1 = PIN_SPI1_MISO;
static const uint8_t SCK1 = PIN_SPI1_SCK;
#define SPIWIFI_SS PIN_SPI1_SS
#define SPIWIFI_ACK NINA_ACK
#define SPIWIFI_RESET NINA_RESETN //This change was on purpose
In addition, I changed the functions of these pins in the variants.cpp:
{ PORTA, 22, PIO_DIGITAL, (PIN_ATTR_NONE), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
{ PORTA, 23, PIO_SERCOM, (PIN_ATTR_NONE), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
{ PORTA, 20, PIO_SERCOM_ALT, (PIN_ATTR_NONE), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
{ PORTA, 21, PIO_SERCOM_ALT, (PIN_ATTR_NONE), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_NONE },
However, despite doing all this I got the error “no module detected.” I am 100% confident that the issue is with the SPI bus change because when I go back to the original SPI bus, everything works.
Another way to put this is that I want to create an SPI port that is the exact same as the SPI breakout port on the MKR boards 10, 11, and 12 pins. In addition, I need this SPI port to be in the variants file.
Also, I created a variants board file for my board but it is the exact same as the MKRWiFi1010 variants files.
I would love to hear anyone’s thoughts. If you have any questions or information I forgot to include, I will respond ASAP.
Thanks,
- Kevin