Serial communication

Back to let’s code

In telecommunication and data transmission, serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus. This is in contrast to parallel communication, where several bits are sent as a whole, on a link with several parallel channels.

Parallel versus serial communication

Types of Serial Communications

Serial communication can be further classified as:

  • Synchronous − Devices that are synchronized use the same clock and their timing is in synchronization with each other.
  • Asynchronous − Devices that are asynchronous have their own clocks and are triggered by the output of the previous state.

It is easy to find out if a device is synchronous or not. If the same clock is given to all the connected devices, then they are synchronous. If there is no clock line, it is asynchronous. For example, UART (Universal Asynchronous Receiver Transmitter) module is asynchronous.

The asynchronous serial protocol has a number of built-in rules. These rules are nothing but mechanisms that help ensure robust and error-free data transfers. These mechanisms, which we get for eschewing the external clock signal, are:

Synchronization bits The synchronization bits are two or three special bits transferred with each packet of data. They are the start bit and the stop bit(s). True to their name, these bits mark the beginning and the end of a packet respectively. There is always only one start bit, but the number of stop bits is configurable to either one or two (though it is normally left at one).
Data bits The amount of data in each packet can be set to any size from 5 to 9 bits. Certainly, the standard data size is your basic 8-bit byte, but other sizes have their uses. A 7-bit data packet can be more efficient than 8, especially if you are just transferring 7-bit ASCII characters.
Parity bits Parity bits are a simple form of error detecting code. The user can select whether there should be a parity bit or not, and if yes, whether the parity should be odd or even. The parity bit is 0 if the number of 1’s among the data bits is even. Odd parity is just the opposite. If an odd number of bits (including the parity bit) are transmitted incorrectly, the parity bit will be incorrect, thus indicating that a parity error occurred in the transmission.
Baud rate The term baud rate is used to denote the number of bits transferred per second [bps]. Note that it refers to bits, not bytes. It is usually required by the protocol that each byte is transferred along with several control bits. It means that one byte in serial data stream may consist of 11 bits. For example, if the baud rate is 300 bps then maximum 37 and minimum 27 bytes may be transferred per second.

 

Synchronization Bits

Diagram of a serial communication data structure

How to use serial communication on Arduino 

The following code is an example code for serial communication. ETM online repository has an serial communication example code. It returns whatever it receives as an input.

After the Arduino sketch has been uploaded to Arduino, open the Serial monitor Search at the top right section of Arduino IDE. Make sure the the baud rate on in your window is same as the rate in the code.

Writing To Console with Arduino | SOLVED

Type anything into the top box of the Serial Monitor and press send or enter on your keyboard. This will send a series of bytes to the Arduino.