A parallel link sends n bits at once on n wires plus a clock. Wires drift out of step with each other (skew), so fast, long parallel links are hard, and every wire costs a pin. A serial link sends the same n bits one after another on one wire, so it takes n bit times but needs very few pins. The UART (universal asynchronous receiver-transmitter) is a simple serial link with no clock wire: both ends agree beforehand on the baud rate, the number of bit times per second, and on the frame format.
The line idles high. The start bit pulls it low, and that falling edge tells the receiver to begin. The data bits follow, least significant bit (bit 0) first, then an optional parity bit, then a high stop bit that returns the line to idle. A typical receiver runs a sampling clock at 16 times the baud rate. It counts 8 ticks from the falling edge to reach the middle of the start bit, then samples every 16 ticks, in the middle of each bit. A UART can raise an interrupt on each received byte; as in Chapter 4, the routine should store the byte and set a volatile flag.
BIT TIME AND BYTE RATE
Tbit=B1,Rbyte=nframeB
Holds for a line running at a constant baud rate with frames back to back. B is the baud rate in bits per second, Tbit the bit time in seconds, nframe=1+data bits+parity bits+stop bits, and Rbyte the best possible bytes per second. Gaps between frames lower it.
DIVISOR FOR A BAUD RATE
B=16Dfclk,D=round(16Btargetfclk)
Holds for a baud generator that divides the peripheral clock by an integer D≥1 to make the 16-times sampling clock (a typical design; some parts store D−1). fclk is in Hz, B and Btarget in baud.
BAUD ERROR AND WHAT IT MAY BE
ε=BtargetBactual−Btarget,9.5∣εtotal∣<0.5
For an 8N1 frame (8 data bits, no parity, 1 stop bit). ε is a rate error as a fraction; εtotal is the difference between the two ends' errors. The stop bit is sampled 9.5 bit times after the falling edge, so the sample point drifts 9.5∣εtotal∣ bit times. Under half a bit needs ∣εtotal∣<5.3%; keep each end under about 2% to leave room for the 1/16-bit uncertainty in finding the edge.