🎁📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 2 Day orders by 11am Monday, December 16 📦❄️📬🎁
0

SERCOM1 on M4 Express - wrong pins?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

SERCOM1 on M4 Express - wrong pins?

by GGaunt on Sat Nov 30, 2019 7:52 pm

Hi. I am trying to use SPI on SERCOM1 on a Metro M4 Express board as I would like to re-use a shield I developed for the ATMEGA328 version. As a starter I have picked up your sketch at: https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi

However, when I flash the board and hook it up to my scope, I get a clock signal on Pin 12 (at 8MHz frequency), what looks like data on Pin 13, and nothing at all on Pin 11. Whereas I was expecting the clock on 13 and the data on 11.

I promise you I have copied your code verbatim into the Arduino IDE. I have also tried in PlatformIO with the same results.

Have I misunderstood something?

Very grateful for any help

Gavin

Here's the code:
Code: Select all | TOGGLE FULL SIZE
#include <SPI.h>
#include "wiring_private.h" // pinPeripheral() function
 
SPIClass mySPI (&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);

void setup() {
  Serial.begin(115200);

  // do this first, for Reasons
  mySPI.begin();

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

uint8_t i=0;
void loop() {
  Serial.println(i);
  mySPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
  mySPI.transfer(i++);
  mySPI.endTransaction();
}

GGaunt
 
Posts: 5
Joined: Sun Jan 28, 2018 3:51 pm

Re: SERCOM1 on M4 Express - wrong pins?

by GGaunt on Sun Dec 01, 2019 7:20 pm

The sketch works as expected on my ItsyBitsy M0 - clock on 13, data on 11, just not on the Metro M4
And yet the pin mappings from the D51 datasheet for SERCOM1, match those for the D21 (see image)
Attachments
Screenshot 2019-12-01 at 23.16.56.png
Screenshot 2019-12-01 at 23.16.56.png (114.88 KiB) Viewed 42 times

GGaunt
 
Posts: 5
Joined: Sun Jan 28, 2018 3:51 pm

Re: SERCOM1 on M4 Express - wrong pins?

by GGaunt on Sun Dec 01, 2019 7:50 pm

A-ha! Reviewing the schematic on the website, it seems that PA16-19 are mapped to different 'Arduino' pins on the Metro M4 board.
On the Metro M4, PA16 - which with this sketch is the SERCOM1 MOSI data line - is mapped to pin 13, and PA17 - the clock - is mapped to pin 12, thus breaking the backward compatibility with the M0 and ATMEGA328 Metro boards.

It think it would be worth reviewing the text on the 'Creating a new SPI' page, as I was convinced that it was going to work in the same way on a D51 based Metro board
Attachments
Screenshot 2019-12-01 at 23.30.05.png
Screenshot 2019-12-01 at 23.30.05.png (50.83 KiB) Viewed 41 times

GGaunt
 
Posts: 5
Joined: Sun Jan 28, 2018 3:51 pm

Please be positive and constructive with your questions and comments.