Using SoftwareSerial library (Arduino IDE) on Seeeduino XIAO

Hi
I am trying to move a sketch from Arduino Nano over to Seeeduino XIAO and I have noticed that the SoftwareSerial library does not behave the same on XIAO as it does on Arduino Nano when reading data.
Below I have included a table of pairs of data I am reading from Arduino and from XIAO generated from the same source. The 0x7E is a byte sent to determine that the next byte is a code of a sensor and I would expect the value pairs between the 2 microprocessors to be the same.
image
The code I have used to produce the above is as follow

#include <Streaming.h>
#include <SoftwareSerial.h
#define PIN_SPORT 9
SoftwareSerial sport = SoftwareSerial(PIN_SPORT, PIN_SPORT, true);
void setup(){
sport.begin(57600);
Serial.begin(115200);
Serial << “Initialised…” << endl;
}
void loop(){
if (sport.available()){
byte data = sport.read();
Serial << String(data, HEX) << " ";
if (data == 0x7E){
//while (sport.available() && sport.peek() != 0x7E){
while (!sport.available());
// Make sure all bytes are read before the next sensor inidcation byte is reached
data = sport.read();
Serial << String(data, HEX) << " ";
//}
}
Serial << endl;
}
}

Apologies for the luck of indentation but I cannot make the text look proper when generating this message in the forum.

I have been scratching my head for about 3-4 days now looking at the SoftwareSerial library code but cannot find any obvious reasons as to why I would be getting different results, unless if it has to do with the interrupt generated in the library for reading data.

Some more ideas and advice would be very much appreciated, as it seems very strange to me if the library does not work, making Software Serial not working at all in XIAO

Many thanks

Michael

I know nothing of the XIAO. but some observations:

 sport.begin(57600);

I have never seen SoftwareSerial work (read) at more than 38400 baud.

SoftwareSerial sport = SoftwareSerial(PIN_SPORT, PIN_SPORT, true);

If you are not using the RX or TX pin set it to -1.

SoftwareSerial sport = SoftwareSerial(PIN_SPORT, -1, true);

Code autoformatted fine for me.

include <Streaming.h>
#include <SoftwareSerial.h
#define PIN_SPORT 9
SoftwareSerial sport = SoftwareSerial(PIN_SPORT, PIN_SPORT, true);

void setup()
{
   sport.begin(57600);
   Serial.begin(115200);
   Serial << "Initialised…" << endl;
}

void loop()
{
   if (sport.available())
   {
      byte data = sport.read();
      Serial << String(data, HEX) << " ";
      if (data == 0x7E)
      {
         //while (sport.available() && sport.peek() != 0x7E){
         while (!sport.available());
         // Make sure all bytes are read before the next sensor inidcation byte is reached
         data = sport.read();
         Serial << String(data, HEX) << " ";
         //}
      }
      Serial << endl;
   }
}

Thanks for coming back to me,

I have been using SoftwareSerial on Arduino Nano at 57600 for quite a few years now on some of my larger RC planes to be able to transmit telemetry data on my FrSky transmitter successfully. I now want to use the same concept on some of my smaller planes, and due to the size of the nano, I am trying out the Seeeduino XIAO, were I encountered the issue. Reducing the baud rate, will not be possible unfortunately because the receiver that communicates with the microcontroller has this set to 57600.

The telemetry information are transmitted from the microcontroller over to the receiver in the plane through single wire Serial communication (using inversion hence the true flag on the instantiation of the sport object as well as the reason both TX and RX are set on the same pin.

So as far as I know the concept really work, proved by the Nano working, I just see a different behavior on how SoftwareSerial works in the Seeeduino Xiao, which I can't really explain by looking directly at the library code.

Hi everyone,

After a lot of investigation, I have now come to the conclusion that the SoftwareSerial library is slower in XIAO in comparison to the Arduino (at least the nano where I have tested this).

Not sure I understand why, as my understanding is that XIAO has a bit more powerful CPU from Arduino.

Any thoughts?

The XIAO is based on a SAMD21 so it has multiple hardware UART, SPI, and I2C controllers. I doubt anyone has ported a soft serial library to it because hardware UARTs are available.

More details about SAMD21 SERCOMs in the link below.

https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports