Software Serial interface library

Serial interfaces are used on various devices. However, small microcontrollers have often one or two serial interfaces, which is sometime not enough. The library proposes on this page is used to add an extra interface to any microcontroller. It has been developped on TheUno.

You can download the full article and source codes using the following link:

Software Serial interface library - Revision 1.0, 2013-08-04

1. Theory of operation

The following schema show a data byte transmitted on a simple serial interface.

It consists in a start bit, four to eight data bits, an optional parity bit used to detect errors and one, one-half or two stop bit(s). The baud rate of the interface determines the duration of the bits. Classical baud rates values are 2400, 4800, 9600, 19200, 115200.

The software serial interface proposed on this page is using a Tx state machine to produce the data on the interface and a Rx state machine to sample the data from the distant device. Three samples are made for each bit as shown on the following figure.

2. Software

Three functions are available in the library:

- SOFTWARESERIAL_Init() to initialize the interface;
- SOFTWARESERIAL_SendData() to send data on the interface;
- SOFTWARESERIAL_ReadData() to get data received from the interface.

Buffers are used in the library in both directions to handle data. Tx and Rx pins can be modified easily to match your own requirements.


This software serial interface can be used to connect a serial device to your application. Note that the performances of the library are limited. I have successfully tested the interface at 4800 baud. Errors can be observed at 9600 baud when the data bytes are sent very closely.

A GPS application based on this serial interface is available on this page.