Serial vs. Parallel
Serial interfaces stream data bit-by-bit (meaning one bit at a time). These interfaces typically use one to four wires to transfer the bits and are exceptionally less expensive to implement.
Parallel interfaces use buses of data to transfer multiple bits at a time. Parallel interfaces require more wires and space than serial interfaces to compensate for the increased throughput (usually starting at eight or sixteen wires).
Types of Serial Interfaces
There are dozens of serial protocols available to suit particular needs and requirements of different embedded systems. Some of the more well known examples include USB (universal serial bus), SPI and Ethernet. Types of serial interfaces can be separated into two groups, synchronous and asynchronous.
Synchronous serial interfaces usually require one or more extra wires. This is because each device on a synchronous serial bus is synchronized on a single clock. This is often faster and more straightforward.
Asynchronous serial interfaces transfer data without support from an external clock signal. This is the most common type of serial interface because it takes up less pin real estate on embedded devices. Due to the lack of an external clock, data transmission is less reliable. To make up for this, asynchronous serial communication has built in rules or mechanisms to help ensure more reliable and accurate data transmissions. Due to these rules/mechanisms asynchronous communication is highly configurable, but in order for two devices to communicate, they must be configured the same. Some of these mechanisms include:
- Data bits
- Synchronous bits
- Parity bits
- Baud rate
The baud rate specifies the speed at which data is sent over a serial line. The speed is usually measured in bits-per-second (bps). Although baud rates can be set to almost any reasonable value (speeds above 115200 will generate considerably more errors), the most common baud rates used include 9600, 1200, 2400, 4800, 19200, 38400, 57600, 115200.
Data blocks are send in a frame of bits or a packet. These packets are created by appending parity bits and synchronization to the data. The amount of data contained within a packet can be anywhere between 5 and 9 bits (usually 8 bits/ a byte unless using 7 bit ASCII characters). The two serial devices communicating must agree upon a set packet size. Each device must also coordinate on the endianness. Endianness is the order in which the bits are sent. Usually the bits are sent least-significant bit first (lsb), but they can also be sent most-significant bit first (msb).
Synchronization bits are start and stop bit/s (usually 2 to 3 bits) transferred with the data. These bits are used to specify the beginning and end of each packet. The start bit is indicated by an idle line of data going from 1 to 0 and the stop bit/s transition back to the idle state by holding the line at 1.
Parity bits are used as a simple form of low-level error checking, which can be useful when communicating over noisy mediums. The parity bit is created by adding up all 5-9 bits in the packet and determining if it is even or odd. If the sum of the bits is even, the parity bit is set to 1. If the sum is odd, the parity bit is set to 0.
On the physical layer, a serial bus consists of two wires; one for receiving data and one for sending. Serial devices have two pins; one for receiving (RX) and one for sending (TX). A serial interface where each of the two devices can send and receive from the other is either full-duplex (devices can send and receive simultaneously) or half-duplex (only one device can send or receive at a time).