Issues with Transmitting/Receiving on Software Serial2 using Itsy Bitsy SAMD51 M4

Hello everyone,

I'm currently working with an Itsy Bitsy SAMD51 M4 board and facing a challenge with implementing a software Serial2 communication using SERCOM0. Despite following the typical setup procedures, I'm unable to transmit or receive any data on Serial2. I've wired RX to TX to simplify the problem, the exact same code works fine for the default hardware serial1. Below is my current code setup:

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

// Define RX and TX pins
#define PIN_RX A5
#define PIN_TX A4

// Declare the second UART (Serial2) using SERCOM0
Uart Serial2(&sercom0, PIN_RX, PIN_TX, SERCOM_RX_PAD_1, UART_TX_PAD_0);

// SERCOM0 Handler
void SERCOM0_0_Handler() { Serial2.IrqHandler(); }
void SERCOM0_1_Handler() { Serial2.IrqHandler(); }
void SERCOM0_2_Handler() { Serial2.IrqHandler(); }
void SERCOM0_3_Handler() { Serial2.IrqHandler(); }

void setup() {
  Serial.begin(115200); // Initialize the built-in serial port
  Serial2.begin(19200); // Initialize Serial2 (19200 baud for RS-485)
  pinPeripheral(PIN_RX, PIO_SERCOM); // Assign RX & TX pins to SERCOM functionality
  pinPeripheral(PIN_TX, PIO_SERCOM);
}

void loop() {
  char data[6] = {'H','E','L','L','O','\n'};
  int i = 0;
  i = (i + 1) % 6;
  Serial2.write(data[i]); // Write data to Serial2

  if (Serial2.available()) {
    uint8_t data = Serial2.read(); // Read data from Serial2
    Serial.print("Received from Serial2: 0x");
    Serial.println(data, HEX);
  }
  delay(100);
}

That would be hardware serial, not software. Please explain.

I'm not sure what pinPeripheral() does, but maybe try moving those lines before the .begin()

There's no "hardware serial" for a second UART, so I'm defining the software interface to talk to SERCOM0

no change

You are clearly somewhat confused. SERCOM is a hardware feature of these chips which can be configured to act as a UART or an I2C or SPI bus. No software serial is involved. If you can figure out how to configure a SERCOM, it is a hardware UART.

Right, but I'm defining the software interface to treat it as a UART and that's not working

I'll say it one more time only. It's a hardware interface, not software. It just needs to be configured correctly.

Super helpful! This has gotten me way closer to solving my problem, thanks so much. But seriously, what would you call creating a UART object to talk to the hardware interface?

No need for sarcasm. Yes, in the Arduino world, hardware often has a software layer around it to make code more portable between Arduino models. You could argue that every UART port is software because your code does not directly interact with the hardware, but that's not a very useful definition because it doesn't distinguish between hardware UARTs and purely software UARTs.

I notice Adafruit have a page here that describes how to configure SERCOM to be additional hardware UART ports. But it only talks about SAMD21, not SAMD51:

https://learn.sparkfun.com/tutorials/adding-more-sercom-ports-for-samd-boards/all

Have you asked this question on Adafruit's forum?

I'm using this Overview | Using ATSAMD21 SERCOM for more SPI, I2C and Serial ports | Adafruit Learning System which does include information on how to for SAMD51. I'll make a post on their forums next.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.