ItsyBitsy M4 - using SERCOM5 for 2nd UART

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
TheFallen
 
Posts: 94
Joined: Mon Feb 08, 2010 1:28 pm

ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by TheFallen »

Hi,

I've been using: https://learn.adafruit.com/using-atsamd ... new-serial# to try and create 2nd hardware serial port on my ItsyBitsy M4. I'm only interested in monitoring incoming serial characters so TX is unconnected.

My code has some extra functions but the basics of it are:

Code: Select all

#include <Arduino.h>
#include "wiring_private.h"

Uart Serial5 (&sercom5, 10, 12, SERCOM_RX_PAD_2, UART_TX_PAD_0);
void SERCOM5_Handler() { Serial5.IrqHandler(); }

void setup(void) {

  delay(10);

  Serial.begin(115200);

  Serial5.begin(115200);
  pinPeripheral(10, PIO_SERCOM); // compiles, uploads but then hangs
  // or
 //pinPeripheral(10, PIO_SERCOM_ALT); // runs but doesn't see characters

}

void loop() {

  if(Serial5.available() == 10) Serial.println("Got 10 chars!");
  else if(Serial5.available() > 0) Serial.println("Got some chars!");
  else Serial.println("No chars!");

  delay(1000);
}

I'm completely stumped by this and welcome any suggestions. Thanks!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by adafruit_support_mike »

The SAMD51's SERCOMs are a bit different from the SAMD21's, and there are some big differences in the pin multiplexer.

The SAMD51 groups SERCOM pins into what the datasheet calls IOSETs, listed in section 6.2.6. Each IOSET has four PADs, and each PAD can do certain things in a SERCOM's configuration. IIRC, only PAD0 can work as a TX pin.

Right now the best reference for working with the SAMD51's SERCOMs is the code in the board support package:

https://github.com/adafruit/ArduinoCore ... es/arduino

You'll want to check the SERCOM and Uart .c and .h files, plus the variant file for one of the M4 boards:

https://github.com/adafruit/ArduinoCore ... ariant.cpp

TheFallen
 
Posts: 94
Joined: Mon Feb 08, 2010 1:28 pm

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by TheFallen »

I'm not seeing the problem? You say that the SAMD51 SERCOMs are different to the ones on the SAMD21 but list something they have in common? They both use IOSETs, that's a SERCOM feature. I think there's a minor difference on the M4's not having TX on PAD 2 or 3, only PAD 0 but as I'm not interested in TX and am using PAD 0 that shouldn't be a problem.

I thought you might be on to something regarding the pin definitions in 'variant.cpp' as I remembered that some pins have PIO_SERCOM but looking though them again only default SERCOM pins have PIO_SERCOM on them. And comparing the entries between pins below, they look pretty identical.

Arduino Zero 'variant.cpp' :

Code: Select all

  { PORTA, 18, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM3_CH0, TC3_CH0, EXTERNAL_INT_2 }, // TC3/WO[0]
  { PORTA, 16, PIO_TIMER, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER), No_ADC_Channel, PWM2_CH0, TCC2_CH0, EXTERNAL_INT_0 }, // TCC2/WO[0]
ItsyBitsy M4 'variant.cpp':

Code: Select all

  { PORTA,  20, PIO_TIMER_ALT, (PIN_ATTR_DIGITAL|PIN_ATTR_PWM|PIN_ATTR_TIMER_ALT), No_ADC_Channel, PWM1_CH4, TCC1_CH4, EXTERNAL_INT_4 }, // D10
Looking the Adafruit version of 'SERCOM.cpp' there's only one difference between SAMD21 and SAMD51 chips, it changes where the peripheral clock is coming from. So while it's a bit different I'd hardly say it bears on what I'm trying to do. There is one difference between the ItsyBitsy M4 and Arduino Zero, the Zero uses all of the SERCOMs, could it be that the board variant doesn't initialise all the SERCOMs?

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by adafruit_support_mike »

The M4 variant defines the SERCOMs, but only initializes the ones it uses for Serial1, SPI, and I2C.

I'd suggest looking through the SAMD21 and SAMD51 datasheets for a more detailed comparison of the two SERCOMs.

User avatar
rs2845
 
Posts: 14
Joined: Fri Feb 23, 2018 8:16 pm

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by rs2845 »

TheFallen wrote:
I'm also trying to use SERCOM5 (SERCOM5.3 => SERCOM_RX_PAD_3 and SERCOM5.2 => UART_TX_PAD_2) for an additional UART on an ItsyBitsy M4 and am also not able to get it running.

Did you ever get this to work?

User avatar
bobtrex
 
Posts: 22
Joined: Sat Sep 01, 2018 12:28 pm

Re: ItsyBitsy M4 - using SERCOM5 for 2nd UART

Post by bobtrex »

I am using Sercom 5 ok.

Regards

Code: Select all

 // Example for ItsyBitsy M4 Sercom0 Serial for A1/Rx + A4/Tx

#include <Arduino.h>   // required before wiring_private.h
#include "wiring_private.h" // pinPeripheral() function
 
Uart Serial2 (&sercom0, A1, A4, SERCOM_RX_PAD_1, UART_TX_PAD_0);
void SERCOM0_0_Handler() {
  Serial2.IrqHandler();
}
void SERCOM0_1_Handler() {
  Serial2.IrqHandler();
}
void SERCOM0_2_Handler() {
  Serial2.IrqHandler();
}
void SERCOM0_3_Handler() {
  Serial2.IrqHandler();
}
 
Uart Serial3 (&sercom5, 13, 12, SERCOM_RX_PAD_1, UART_TX_PAD_0);
//Uart Serial3 (&sercom5, 11, 10, SERCOM_RX_PAD_3, UART_TX_PAD_2);

void SERCOM5_0_Handler() {
  Serial3.IrqHandler();
}
void SERCOM5_1_Handler() {
  Serial3.IrqHandler();
}
void SERCOM5_2_Handler() {
  Serial3.IrqHandler();
}
void SERCOM5_3_Handler() {
  Serial3.IrqHandler();
} 
 
void setup() {
  Serial.begin(115200);
 
  Serial2.begin(9600);
  
  Serial3.begin(9600);
  
  // Assign pins 10 & 11 SERCOM functionality
  pinPeripheral(A1, PIO_SERCOM_ALT);
  pinPeripheral(A4, PIO_SERCOM_ALT);
   // Assign pins 4 & 5 SERCOM functionality
  pinPeripheral(13, PIO_SERCOM_ALT);
  pinPeripheral(12, PIO_SERCOM_ALT); 

}
 
uint8_t i=0;
void loop() {
  byte inbyte;
  //Serial.print(i);
 // Serial2.write(i++);
 //Serial2.println("hi");
//  if (Serial2.available()) {
//  Serial.print("Serial 2 -> 0x"); Serial.print(Serial2.read(), HEX);
//  }
//  Serial.println();
//  Serial3.write(i++);
  if (Serial3.available()) {
  // Serial.print("no chars =:");Serial.println(Serial3.available());
 //   Serial.print("Serial 3 -> 0x"); Serial.print(Serial3.read(), HEX);
      Serial.print(Serial3.read());
  }
  
 // delay(1000);
}


Locked
Please be positive and constructive with your questions and comments.

Return to “Itsy Bitsy Boards”