Question, adding a hardware serial UART interface to Arduino MKR GSM 1400

I have a project where i need more than one UART interface on my Arduino MKR GSM 1400. Since you can’t use SoftwareSerial with SAMD21 boards i tried to add a hardware serial interface following this tutorial but can’t get it to work.

What i tried ist it to add a UART sercom3 on Pin 0 and 1 with the following code.

Before the setup:

#include <Arduino.h>
#include "wiring_private.h"
Uart Serial_plc(&sercom3, 0, 1, SERCOM_RX_PAD_1, UART_TX_PAD_0);

void SERCOM3_Handler()

In the setup:

Serial_plc.begin(9600, SERIAL_8E1);
    Serial.println("DEBUG: error opening Serial_plc");
  pinPeripheral(0, PIO_SERCOM); //Assign RX function to pin 0
  pinPeripheral(1, PIO_SERCOM); //Assign TX function to pin 1

Has anyone tried to add a hardware serial interface to an Arduino MKR GSM 1400 and can help me out?

Hi season90,

TX should be on digital pin 0 (PA22), as that's on SERCOM3/PAD[0]. Likewise, RX should be on digital pin 1 (PA23):

Uart Serial_plc(&sercom3, 1, 0, SERCOM_RX_PAD_1, UART_TX_PAD_0);

I'd also suggest calling the pinPeripheral() functions before testing the Serial_plc in the while() loop.

Hi MartinL,

Thank you for your solution! The UART interface is working now.

I followed this tutorial from the Arduino homepage. Could it be that there is the same mistake in the code (example “Create a new Serial instance”)?

Hi season90,

The Arduino tutorial is correct, it's just that it's based on the older Arduino Zero rather than the MKRGSM1400.

Although the two board appear to present the same Arduino analog and digital pins: D0, D1, D2, etc..., in reality they're connected to different microcontroller port pins: PA00, PA01, PA02, etc...

The connection between Arduino pins and microcontroller port pins is provided by the MKRGSM1400 schematic diagram:

The functionality of each port pin is provided by the "PORT Function Multiplexing" table in section 7. of the SAMD21 datasheet:

From the schematic it's possible to see that digitial D0 is connected PA22 and D1 to PA23 respectively. The table shows that PA22 can connect to SERCOM3/PAD[0] and PA23 to SERCOM3/PAD[1].

However, further down in the SAMD21 datasheet, SERCOM peripheral section 26.8.1, CTRLA register, TXPO bitfield, it specifies that the transmit pin can only connect to either PAD[0] or PAD[2], therefore only PA22 on PAD[0] can become the TX pin, leaving PA23 on PAD[1] as the RX.