Communication methods

Serial and parallel, synchronous and asynchronous, baud rate, bit rate, bandwidth, latency and protocols.

A12.1Networks and the webA level25 min

Do this lesson in the simulator

At GCSE (F10.3) you met bandwidth as "how much data a connection carries each second", and worked out transfer times. At A level you need to be more precise. This lesson looks at how bits actually travel down a link: one at a time or several at once, with or without a shared clock. Then it separates four words that GCSE blurred together: baud rate, bit rate, bandwidth and latency, and ends with why every link needs a protocol.

Serial and parallel

In serial transmission the bits are sent one after another down a single wire (plus a ground return). In parallel transmission several bits are sent at the same moment, each down its own wire: eight wires can carry a whole byte at once.

Parallel sounds faster, and over a few centimetres it can be. Over longer distances serial wins, for three reasons:

Problem with parallel Why it happens
Skew the bits of one byte set off together but arrive at slightly different times, because no two wires are exactly the same length or have exactly the same electrical properties. At high speed a bit can arrive in the time slot of the next byte.
Crosstalk a changing signal on one wire induces an unwanted signal in the wires beside it, corrupting their data. The more wires packed together, the worse it gets.
Cost and size many wires, wider connectors and bigger cables cost more than one pair.

Because serial has no skew between wires, it can be clocked much faster, which is why USB, SATA, PCI Express and Ethernet are all serial. Parallel is still used over very short distances, such as the buses inside a processor or between a processor and its memory.

Synchronous and asynchronous

The receiver must know when to read each bit. There are two ways to agree on that.

In synchronous transmission the sender and receiver share a clock signal (or keep their clocks locked together), and data flows continuously in step with it. There is no gap between bytes, so it suits a steady, large flow of data. Inside a computer, the processor and memory work synchronously with the system clock.

In asynchronous transmission there is no shared clock. The line rests in an idle state (a 1) until the sender has something to send. Each character is then wrapped in a frame:

  • a start bit (a 0), the opposite of the idle state, so the receiver sees the line change and knows a character is starting. It uses this edge to synchronise its own clock for this one character;
  • the data bits, commonly 8, sent least significant bit first on a UART;
  • a stop bit (a 1), which returns the line to idle and gives the receiver time to get ready for the next start bit.

Both ends must agree the rate beforehand, but their clocks only need to stay in step for the ten bits of one frame. The price is overhead: 10 bits on the wire for every 8 bits of data.

An asynchronous frame for the letter Hidle0000100101startdata, least significant bit firststopidle
The letter H (72, binary 01001000) as an asynchronous frame: start bit, the data bits reversed, stop bit
def frame(ch):
    data = format(ord(ch), "08b")      # 'H' is 72, which is 01001000
    return "0" + data[::-1] + "1"      # start bit, data least significant bit first, stop bit

for ch in "HB":
    print(ch, ord(ch), format(ord(ch), "08b"), "->", frame(ch))

Run this in the simulator

Baud rate and bit rate

Baud rate is the number of signal changes per second: how many times a second the line may change to a new state (a new voltage, frequency or phase). Each of those states is called a symbol.

Bit rate is the number of bits transmitted per second.

If the line has only two states, each signal change carries one bit and the bit rate equals the baud rate. But a signal can have more than two states. With four voltage levels, each level stands for two bits (00, 01, 10, 11), so every change carries 2 bits:

bit rate = baud rate × bits per signal change

Levels per symbol Bits per symbol Baud rate Bit rate
2 1 1200 1200 bps
4 2 1200 2400 bps
16 4 1200 4800 bps

This is how a bit rate can be higher than the baud rate. In general, n bits per symbol needs 2n distinguishable states.

import math

def bit_rate(baud, levels):
    bits_per_symbol = int(math.log2(levels))
    return baud * bits_per_symbol

for levels in [2, 4, 16, 64]:
    print(levels, "levels at 1200 baud:", bit_rate(1200, levels), "bps")

# asynchronous framing: 10 bits on the wire per character
baud = 9600
print("characters per second at 9600 baud:", baud // 10)

Run this in the simulator

Bandwidth and latency

At A level, bandwidth means the range of frequencies a transmission medium can carry, measured in hertz. A copper pair might carry frequencies up to a few megahertz; optical fibre carries a vastly wider range. The more frequencies a channel can carry, the faster its signal can change and the more distinct symbols it can use, so bit rate is directly proportional to bandwidth: double the bandwidth and, other things equal, you can double the bit rate. In everyday speech people say "bandwidth" for the bit rate itself, which is what GCSE did.

Latency is the time delay between something being sent and it arriving, or between an action and its effect. It comes from the time signals take to travel, time spent in router queues, and processing at each device. It is separate from bit rate: a satellite link can carry a lot of data per second and still have high latency, because the signal travels about 72,000 km up and back down.

Protocols

A protocol is a set of rules that govern communication between devices. Both ends must follow the same rules or the data is meaningless. A protocol for an asynchronous serial link has to fix, among other things:

  • the baud rate, and how many levels each symbol uses;
  • the number of data bits, and whether the least or most significant bit goes first;
  • the polarity of the start and stop bits, and how many stop bits;
  • whether there is a parity bit for error checking, and whether it is odd or even.

A setting written as "9600 8N1" means 9600 baud, 8 data bits, no parity, 1 stop bit. If one end is set to 9600 and the other to 115200, each frame is read at the wrong moments and the receiver sees garbage. Protocols that are published and agreed by many manufacturers become standards, which is what lets devices from different companies work together.

Task: frame a byte

The LED can be a one-wire serial line: white for 1, off for 0.

Write frame(ch). Its input ch is a single character with a code from 0 to 255. It returns a string of exactly 10 characters, each 0 or 1: a start bit 0, the 8 data bits of the character's code least significant bit first, then a stop bit 1.

For each character of Hi!, in order:

  1. print the character, a space and its frame, for example H 0000100101;
  2. put each of the 10 bits on the LED in turn, led("white") for 1 and led("off") for 0, with wait(0.05) after each.

Then print bits sent: <n>, where n is the number of bits you put on the LED, counted by your loop. Last, print how long 1200 characters take at 9600 baud with a 2-level signal, using the length of one frame: time for 1200 characters: <seconds> s, where seconds is the result of the division printed as Python prints it.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

BAUD = 9600

def frame(ch):
    data = format(ord(ch), "08b")
    return data

for ch in "Hi!":
    print(ch, frame(ch))

Challenges

  1. Add an even parity bit between the data and the stop bit. How many characters per second does 9600 baud carry now?
  2. Write unframe(bits) that checks the start and stop bits and returns the character, or None if the framing is wrong.
  3. A line uses 8 voltage levels at 4800 baud. Work out its bit rate, then check it with bit_rate.