0

Metro M4 Express Secondary SPI (legacy Arduino UNO pin confi
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M4 Express Secondary SPI (legacy Arduino UNO pin confi

by jrlitzenberger on Wed Dec 05, 2018 7:50 pm

Fellow Metro M4 trailblazers,

Alright so I am having way too much fun. I have dug pretty deep into the SERCOM.cpp, SERCOM.h, variant.cpp, variant.h, SPI.cpp, and SPI.h code. The ultimate goal is to be able to use the legacy arduino uno spi pins. I have built a isolated spi shield that a lot of my customers have in hand and now I'm trying to update them with a way better microprocessor solution. (short story short). So I'm hardware locked-in at the moment.

What I have been able to get working in the arduino environment is...

Change the SPI pins, except for some reason the pin muxing is not working properly. My understanding is the pins are mapped this way
Code: Select all | TOGGLE FULL SIZE
PA16 ----- SERCOM1.0 + 3.1 -------  D13 (Desired SCK)
PA17 ----- SERCOM1.1 + 3.0 ------- D12 (Desired MISO)
PA18 ----- SERCOM1.2 + 3.2 ------ D10 (Desired SS)
PA19 ----- SERCOM1.3 + 3.3 ------- D11 (Desired MOSI)
One issue. If I look in SERCOM.h there is no proper enumeration value to setup SCK on SERCOM1.0

Code: Select all | TOGGLE FULL SIZE
typedef enum
{
   SPI_PAD_0_SCK_1 = 0,
   SPI_PAD_2_SCK_3,
   SPI_PAD_3_SCK_1,
   SPI_PAD_0_SCK_3
} SercomSpiTXPad;
It can only support SERCOMn.1 and SERCOMn.3 So this would force the use of SERCOM3 but that is being consumed by Uart Serial1. I have tried commenting out the UART (inside variant.cpp) and tried using SERCOM3 for the SPI bus but it still did NOT work.

Anyways, I'm only able to get SCK on D12 no matter what I set from SercomSpiTXPad. All the other signals are proper. Whats funny is I'm modifying an example for the SCP1000 that is provided as an SPI example. It even calls out the proper pin definitions, which is a little silly.

Code: Select all | TOGGLE FULL SIZE
/*
 SCP1000 Barometric Pressure Sensor Display

 Shows the output of a Barometric Pressure Sensor on a
 Uses the SPI library. For details on the sensor, see:
 http://www.sparkfun.com/commerce/product_info.php?products_id=8161
 http://www.vti.fi/en/support/obsolete_products/pressure_sensors/

 This sketch adapted from Nathan Seidle's SCP1000 example for PIC:
 http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip

 Circuit:
 SCP1000 sensor attached to pins 6, 7, 10 - 13:
 DRDY: pin 6
 CSB: pin 7
 MOSI: pin 11
 MISO: pin 12
 SCK: pin 13

 created 31 July 2010
 modified 14 August 2010
 by Tom Igoe
 */

// the sensor communicates using SPI, so include the library:
#include <SPI.h>
#include "wiring_private.h"

//Sensor's memory register addresses:
const int PRESSURE = 0x1F;      //3 most significant bits of pressure
const int PRESSURE_LSB = 0x20;  //16 least significant bits of pressure
const int TEMPERATURE = 0x21;   //16 bit temperature reading
const byte READ = 0b11111100;     // SCP1000's read command
const byte WRITE = 0b00000010;   // SCP1000's write command

// pins used for the connection with the sensor
// the other you need are controlled by the SPI library):
const int dataReadyPin = 6;
const int chipSelectPin = 10;  //was 7

SPIClass mySPI (&sercom1, 12, 13, 11, SPI_PAD_0_SCK_3, SERCOM_RX_PAD_0);  //PA17, PA16, PA19

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

 
  // start the SPI library:
  mySPI.begin();

  pinPeripheral(11, PIO_SERCOM);
  pinPeripheral(12, PIO_SERCOM);
  pinPeripheral(13, PIO_SERCOM);

  // initalize the  data ready and chip select pins:
  pinMode(dataReadyPin, INPUT);
  pinMode(chipSelectPin, OUTPUT);

  //Configure SCP1000 for low noise configuration:
  writeRegister(0x02, 0x2D);
  writeRegister(0x01, 0x03);
  writeRegister(0x03, 0x02);
  // give the sensor time to set up:
  delay(100);
}

So what the heck? Has anyone gotten a SPI interface to work on the Metro M4 express using the single row header?

BIG NOTE for Adafruit!!! Create a PDF version of your schematic. I don't really care to download Eagle or use a schematic viewer. The schematic that is included in the documentation is un-readable.

I appreciate any help on this issue.

Thanks,

John
Last edited by adafruit_support_mike on Fri Dec 07, 2018 4:29 am, edited 1 time in total.
Reason: added CODE tags

jrlitzenberger
 
Posts: 5
Joined: Wed Dec 05, 2018 1:50 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by westfw on Wed Dec 05, 2018 10:48 pm

Isn't the big .png file (https://cdn-learn.adafruit.com/assets/assets/000/053/093/original/adafruit_products_schem.png?1524085993) usable?
It's a pretty dense schematic...

Here (this is the 6/17 version - I think that's the most recent, at the moment.)
Attachments
Adafruit Metro M4 Express.pdf
(94.65 KiB) Downloaded 5 times
User avatar
westfw
 
Posts: 1459
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by jrlitzenberger on Thu Dec 06, 2018 11:21 am

Awesome! Did I miss a link somewhere in the "Adafruit Metro M4 Express featuring ATSAMD51"? Thanks for responding to my comments on the schematic, any thoughts on my actual issue?

jrlitzenberger
 
Posts: 5
Joined: Wed Dec 05, 2018 1:50 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by westfw on Fri Dec 07, 2018 1:45 am

Did I miss a link somewhere?

No; I didn't find a .pdf file either (though there is usually one.) I just printed it from the EAGLE source, since I had it handy and wanted to see if the PDF file had better readability than the large PNG file (it does.)

any thoughts on my actual issue?

I've noticed before that the SERCOM pinmux options are not quite as flexible as Atmel occasionally implies :-(
It looks to me like SERCOM3 should have worked - did you figure out where to set the PINMUX to SERCOMALT instead of just SERCOM?
User avatar
westfw
 
Posts: 1459
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by adafruit_support_mike on Fri Dec 07, 2018 4:36 am

jrlitzenberger wrote:BIG NOTE for Adafruit!!! Create a PDF version of your schematic. I don't really care to download Eagle or use a schematic viewer. The schematic that is included in the documentation is un-readable.

That issue falls in the general category of "consider my preferences when giving me stuff for free."

The number of people with different preferences regarding stuff they get for free is enormous, and for us, the potential workload is overwhelming. The only way to win is not to play.

That's the beauty of Open Source though: all the files are available, and anyone who really wants a specific format can can build, publish, and maintain that collection of files for themselves. We'll be happy to link to any such resource.

adafruit_support_mike
 
Posts: 54144
Joined: Thu Feb 11, 2010 2:51 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by jrlitzenberger on Fri Dec 07, 2018 2:14 pm

Mike,

Sure. Probably should have worded it differently. I work for a certain company that thrives off of giving out demo boards, application notes, Firmware, and Software completely for free in hopes that we get a win. My comment was merely to aid in that very process that I'm very familiar with. Arm your potential customers with everything they need to be successful with no guarantee that it will generate any sort of revenue.

As for linking to a pdf version, westfw posted a wonderful pdf that I was able to print and read with ease.

Adafruit Metro M4 Express.pdf
(94.65 KiB) Downloaded 2 times


Thanks,

John

jrlitzenberger
 
Posts: 5
Joined: Wed Dec 05, 2018 1:50 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by jrlitzenberger on Fri Dec 07, 2018 2:21 pm

any thoughts on my actual issue?

I've noticed before that the SERCOM pinmux options are not quite as flexible as Atmel occasionally implies :-(
It looks to me like SERCOM3 should have worked - did you figure out where to set the PINMUX to SERCOMALT instead of just SERCOM?[/quote]

This is what I have found/modified in the variant.cpp file.

// 32..34 - Secondary SPI
// ----------------------
{ PORTA, 16, PIO_SERCOM, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, //same as d13
{ PORTA, 17, PIO_SERCOM, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3 }, //same as d12
{ PORTA, 19, PIO_SERCOM, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, //same as d11

So there doesn't appear to be an PIO_SERCOM_ALT requirement if I understand the pin definition correctly. I also double checked this in the datasheet. I'm going to go ahead and try PIO_SERCOM_ALT and see what I get.

jrlitzenberger
 
Posts: 5
Joined: Wed Dec 05, 2018 1:50 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by jrlitzenberger on Fri Dec 07, 2018 5:27 pm

I've noticed before that the SERCOM pinmux options are not quite as flexible as Atmel occasionally implies :-(
It looks to me like SERCOM3 should have worked - did you figure out where to set the PINMUX to SERCOMALT instead of just SERCOM?


So this is what I had to do... And ultimately Mr. westfw suggestion to try PIO_SERCOM_ALT is what got everything to work.

I noticed in variant.cpp for the metro M4 the secondary spi pins were assigned to the wrong port pins. So I changed that. I also notice that there is no way with the enumerated SercomSpiTXPad definition to be able to use sercom1. Please feel free to correct me if I'm wrong but I tried all combinations to get the clock on the "correct" pin.

I changed variant.cpp the following lines...

// 32..34 - Secondary SPI
// ----------------------
{ PORTA, 16, PIO_SERCOM_ALT, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_2 }, //same as d13
{ PORTA, 17, PIO_SERCOM_ALT, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_3 }, //same as d12
{ PORTA, 19, PIO_SERCOM_ALT, PIO_SERCOM, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_1 }, //same as d11

Now they are defined with the correct porta pin numbers, and I also defined PIO_SERCOM_ALT to be the default. This allows sercom3 to be used and aligns with the SercomSpiTXPad enumeration definition.

/*
Uart Serial1( &sercom3, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;

void SERCOM3_0_Handler()
{
Serial1.IrqHandler();
}
void SERCOM3_1_Handler()
{
Serial1.IrqHandler();
}
void SERCOM3_2_Handler()
{
Serial1.IrqHandler();
}
void SERCOM3_3_Handler()
{
Serial1.IrqHandler();
}
*/

commented out Serial1 on sercom3.

I then changed variant.h

/*
* SPI Interfaces
*/
#define SPI_INTERFACES_COUNT 1

//#define PIN_SPI_MISO (24u)
//#define PIN_SPI_MOSI (26u)
//#define PIN_SPI_SCK (25u)
#define PIN_SPI_MISO (33u)
#define PIN_SPI_MOSI (34u)
#define PIN_SPI_SCK (32u)
//#define PERIPH_SPI sercom0
#define PERIPH_SPI sercom3
#define PAD_SPI_TX SPI_PAD_3_SCK_1
#define PAD_SPI_RX SERCOM_RX_PAD_0

Now the SPI interface works on legacy spi pins on the Adafruit Metro M4. If anyone is ever interested.

Thanks. Hopes this helps someone else!

jrlitzenberger
 
Posts: 5
Joined: Wed Dec 05, 2018 1:50 pm

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by westfw on Fri Dec 07, 2018 7:15 pm

And ultimately Mr. westfw suggestion to try PIO_SERCOM_ALT is what got everything to work.

Great! I'm glad my "hint" was useful.
And thanks for the followup - one of the frustrating thing about casting half-baked ideas off into the internet is not knowing whether they worked out or not.
User avatar
westfw
 
Posts: 1459
Joined: Fri Apr 27, 2007 1:01 pm
Location: SF Bay area

Re: Metro M4 Express Secondary SPI (legacy Arduino UNO pin c

by danhalbert on Fri Dec 14, 2018 12:39 pm

Re schematic images:

If you click on the image here : https://learn.adafruit.com/adafruit-met ... /downloads
you're taken to this page: https://learn.adafruit.com/assets/53093
which has links on the right side for multiple png sizes of schematic images. That's true for pretty much all boards.

danhalbert
 
Posts: 1273
Joined: Tue Aug 08, 2017 12:37 pm

Please be positive and constructive with your questions and comments.