SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By Kimlorentz
#186984
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

variant.cpp
variant.h
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.
Code: Select all
// 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.
You do not have the required permissions to view the files attached to this post.
By ljbeng
#193730
Anyone get Serial3 to work on Pin 5,2? I need 2 hardware serial and the SD card on a mini breakout so I don't want to use Serial2 from example above. Serial1 in this example is working, Serial3 is not....
Code: Select all
// Serial3
#define PIN_SERIAL3_RX       (45ul)               // Pin description number for PIO_SERCOM on D5
#define PIN_SERIAL3_TX       (44ul)               // Pin description number for PIO_SERCOM on D2
#define PAD_SERIAL3_TX       (UART_TX_PAD_2)      // SERCOM pad 2
#define PAD_SERIAL3_RX       (SERCOM_RX_PAD_3)    // SERCOM pad 3

Uart Serial3(&sercom2, PIN_SERIAL3_RX, PIN_SERIAL3_TX, PAD_SERIAL3_RX, PAD_SERIAL3_TX);

void setup()
{
  Serial1.begin(9600);
  Serial3.begin(9600);          // Begin Serial2
}

void loop()
{ 
    Serial1.println("hello1");
    Serial3.println("hello3");
    delay(200);
}

void SERCOM2_Handler()
{
  Serial3.IrqHandler();
}