Advantage of HardareSerial over Serial?

Status
Not open for further replies.

SimonWakley

Active member
Hi, Is here any advantage using HardwareSerial over just using the straight SerialN I only need standard 8N1 and I can assign the pins to the alt serial posts as needed. Thanks.
Teensy3.6 I have ethernet and 4 serial ports working, mostly just curious.

#define RS232B Serial1
//HardwareSerial RS232B = HardwareSerial(); // Set up for using secondary Serial 1 pins 26&27
 
Serial1 is simply defined as an instance of HardwareSerial, so I don't see any benefit.

If you wish to lose the c++ stuff, then you can go directly to the code that it calls in serial1.c, which is the C interface.

If you look in HardwareSerial.h you will see the C++ class simply calls off to the C functions. However you will of course lose the Stream/Print capabilities that the C++ code inherits from.
 
In the very early days of Teensy, which was also fairly early in the history of Arduino before any official Arduino board had more than 1 serial port and none had native USB (Arduino Duemilanove was new on the market, Arduino Uno & Mega didn't exist yet), the earliest versions of Teensyduino recommended creating your own name for the hardware serial port. At the time, Teensy and Sanguino where the only Arduino compatible products with more than 1 way to communicate with "serial", and there just wasn't a firm convention on how to deal with such things.

When Arduino Mega appeared on the market, and the convention of Serial1, Serial2, Serial3 for the other ports became the norm.

At Kurt explained, there's really no difference. Even now, if you *really* want to create your own instance of the C++ object, you can. But it's ultimately still the same code.

Years ago I updated the examples and documentation to recommend the now well-established names. But perhaps there's still some of that old code or info somewhere?
 
Status
Not open for further replies.
Back
Top