I added Serial 2 and Serial 3 support to the SAMD21 mini Breakout board. I have testet them and are working.
Serial 2
RX = pin 10 TX = pin 12
Serial 3
RX = pin 5 TX = pin 2
By using normal Serial2.begin and Serial3.begin the serial ports are ready for use.
If you dont want to edit the variant files you can only get Serial2 to work.
Here is code for using Serial2 without edit files.
// Serial2 pin and pad definitions (in Arduino files Variant.h & Variant.cpp)
#define PIN_SERIAL2_RX (34ul) // Pin description number for PIO_SERCOM on D12
#define PIN_SERIAL2_TX (36ul) // Pin description number for PIO_SERCOM on D10
#define PAD_SERIAL2_TX (UART_TX_PAD_2) // SERCOM pad 2
#define PAD_SERIAL2_RX (SERCOM_RX_PAD_3) // SERCOM pad 3
// Instantiate the Serial2 class
Uart Serial2(&sercom1, PIN_SERIAL2_RX, PIN_SERIAL2_TX, PAD_SERIAL2_RX, PAD_SERIAL2_TX);
void setup()
{
Serial.begin(115200);
Serial2.begin(9600); // Begin Serial2
}
void loop()
{
if (Serial.available())
{
byte byteRead2 = Serial.read();
Serial2.write(byteRead2);
}
if (Serial2.available()) // Check if incoming data is available
{
byte byteRead = Serial2.read(); // Read the most recent byte
Serial.write(byteRead); // Echo the byte back out on the serial port
}
}
void SERCOM1_Handler() // Interrupt handler for SERCOM1
{
Serial2.IrqHandler();
}
everything abowe void setup must be there, and void SERCOM1_Handler() must NOT be removed.