Go Down

Topic: SWseriale simple software serial library (Read 157 times) previous topic - next topic

dadez87

Arduino models equipped with Atmel ATmega328P microcontroller unfortunately have only 1 hardware serial port available.
For this reason, I decided to create a "high efficiency, low CPU load" software serial library which uses  Pin 3 (RX) and Pin 4 (TX), in order to manage an additional serial port.
The library uses an external interrupt (INT1) on Pin 3, in order to catch the "start bit" transition (from 5V to 0V), plus an 8 bit timer (Timer2) in order to create the timing for reading and writing information bits on the serial bus.
Since this library only has few instruction codes (less than 250 C code lines), it is lighter than the usual Arduino Software Serial library.
The transmission is managed using interrupts (with few microseconds execution time) at each bit timing, so the calculation load of the CPU is very small, and also the main program execution is not locked during sending and transmission operations.
Both sending and receiving operations use Timer2 for the bit timing: it is not possible to send and receive at the same time. Therefore, the communication can be only half-duplex.

How to use the library to send and receive data:
1) Include "SWseriale.h" to your program (#include "SWseriale.h")
2) Include function call "SWseriale.begin()" into the Setup() function of Arduino sketch
3) Read serial data using functions "SWseriale.available()" and "SWseriale.read()"
4) Send serial data using function "SWseriale.write()"

The library is available on GitHub, on my page (dadez87): https://github.com/dadez87/SWseriale


CrossRoads

"Arduino models equipped with Atmel ATmega328P microcontroller unfortunately have only 1 hardware serial port available. "
"Both sending and receiving operations use Timer2 for the bit timing: it is not possible to send and receive at the same time. Therefore, the communication can be only half-duplex."

What do some of the other software serial libraries do for comparison? Software Serial, NewSoft Seria, Neosoft serial AltSoft serial,  names like those.

I prefer the '1284P for its dual hardware serial -> faster speeds, and full duplex.


Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy