SAMD21 Arduino SERCOM Serial1 & Serial2 not working - Page 1
Forum section: electronics / general

author: stan001
author_rank: Contributor
timestamp: August 13, 2020, 12:43:40 am
content: Hi all,I have some issues getting SERCOM Serial to work ...SerialUSB is working fine ...I2C is working fine ...I made a board with "almost" similar pinout as Arduino Zero ...UART0 is PA11/PA10 ( Rx/Tx )UART1 is PB09/PB08 ( Rx/Tx )I want to access the Serial1 or Serial2 but both I read both the Sparkfun & Adafruit documentation link below, still could NOT get it working...Looking at the codes, I hv setup the Sercom4 with pad1 & pad0I also hv setup the pinPeripheralpinPeripheral(15, PIO_SERCOM_ALT);pinPeripheral(16, PIO_SERCOM_ALT);No compilation or upload errors , just no output ...I have open up bothvariant.cppandvariant.handSERCOM.hfiles at the SAMD coresI connect both the Serial1 and Serial2 Tx pins to a FTDI USB Serial port to check the output ....https://learn.sparkfun.com/tutorials/adding-more-sercom-ports-for-samd-boards#helpful-chartshttps://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports?view=allSAMD21 pinoutSERCOM on SAMD21Code:#define PIN_SERIAL2_RX (16ul)#define PIN_SERIAL2_TX (15ul)#define PAD_SERIAL2_TX (0x1ul)#define PAD_SERIAL2_RX (0x0ul)// PB09 , PB08, SERCOM4 , Pad1, Pad0Uart Serial2(&sercom4,16ul, 15ul, SERCOM_RX_PAD_1,UART_TX_PAD_0);void SERCOM4_Handler(){Serial2.IrqHandler();void setup() {Serial.begin(57600);while (!Serial) {; // wait for serial port to connect}Serial1.begin(57600);Serial2.begin(57600);pinPeripheral(15, PIO_SERCOM_ALT);pinPeripheral(16, PIO_SERCOM_ALT);pinPeripheral(0, PIO_SERCOM);pinPeripheral(1, PIO_SERCOM);delay(500);Serial.println("SAMD21 Serial");Serial1.println("SAMD21 Serial1");Serial2.println("SAMD21 Serial2");}}

author: westfw
author_rank: Super Contributor
timestamp: August 13, 2020, 01:48:45 am
content: QuoteThe pin numbers used in the Serial2 object need to be Arduino board pin numbers, not chip pin numbers.

author: stan001
author_rank: Contributor
timestamp: August 13, 2020, 02:41:05 am
content: Quote from: westfw on August 13, 2020, 01:48:45 amThanks...Yes, those are the Arduino numbers from variant.cppCode:* | 15 | A1 | PB08 | A1 | EIC/EXTINT *ADC/AIN PTC/Y SERCOM4/PAD TC4/WO* | 16 | A2 | PB09 | A2 | EIC/EXTINT *ADC/AIN PTC/Y SERCOM4/PAD

author: westfw
author_rank: Super Contributor
timestamp: August 13, 2020, 08:16:25 am
content: Ahh. Sorry; I was beguiled by the other sercom landing on the chip pins 15 and 16...Does anything change if you move the Serial.begin() calls AFTER the pinPeripheral() calls?(Hmm. Probably not. Serial.begin() will actually reset the pinPeripheral type back to the default of Analog.)You can try this to see if it tells you anything interesting:https://github.com/WestfW/ArduinoZero-PMUX-report(It'sa little stale, but it should work on SAMD21 chips...)Hmm. The following is working fine on my Sparkfun SAMD21 board. It's essentially your code...(output on "analog pin 1", right?)Code:#include <wiring_private.h>/** For Sparkfun SAMD21 boards, use SerialUSB device*/#define mySerial SerialUSBUart Serial2(&sercom4, 16ul, 15ul, SERCOM_RX_PAD_1, UART_TX_PAD_0);void SERCOM4_Handler(){Serial2.IrqHandler();}void setup() {mySerial.begin(9600);while (!mySerial);Serial2.begin(9600);pinPeripheral(15, PIO_SERCOM_ALT);pinPeripheral(16, PIO_SERCOM_ALT);}void loop() {while (mySerial.read() < 0); // wait for character to run again.mySerial.println("\nRunning again!\n");Serial2.println("testing 1 2 3");}

author: stan001
author_rank: Contributor
timestamp: August 14, 2020, 05:22:42 am
content: Quote from: westfw on August 13, 2020, 08:16:25 amThanks for this, it was really helpful to verify how those pins were configured ....