UART serial
On this page
Two people can pass a message by holding a lamp on or off for one second at a time, if both count the seconds at the same speed. UART serial is this agreement between two chips: one wire carries the bits one after another, at a speed that both sides were set to beforehand.
See it
A sensor sends text at 9,600 baud. The computer that listens is set to 19,200 baud by mistake. What appears on the screen?
The line is the sender at 9,600 baud. The first bit after the start bit is the least significant bit of the character. Each dot is a moment when the receiver samples the line, counted on its own clock from the start bit. When the two clocks agree, every dot sits in the middle of a bit. When they do not, the dots drift, and a dot that lands in the wrong bit is marked with an exclamation mark.
The idea
A UART link has one wire for each direction, called TX (transmit) and RX (receive), and a shared ground. While nothing is sent the line rests at 1.
Each character travels as a frame of 10 bits: a start bit that is always 0, eight data bits with the least significant bit first, and a stop bit that is always 1. This format is written 8N1. The baud rate is the number of bits sent each second.
at 9,600 baud one bit lasts 104 µs and a frame of 10 bits lasts 1.04 ms
The receiver starts its own timing when the line falls for the start bit, then samples the middle of each bit. It works only if both sides count at nearly the same speed. In this simple picture the clocks may differ by about 5%. Real links need a margin: keep the error under 2%.
One worked number
A device sends the letter A, which is code 65, at 9,600 baud in the 8N1 format. What levels appear on the wire, in order, and how long does the frame last?
Show the worked solution, 3 steps
- Write the code in binary
65 = 64 + 1, so the eight bits are 0100 0001.
- Put the bits in the order of the wire
The least significant bit goes first, so read the byte from right to left: 1 0 0 0 0 0 1 0. Add the start bit before and the stop bit after: 0, then 1 0 0 0 0 0 1 0, then 1.
- Find the time
One bit lasts 1 ÷ 9,600 s = 104 µs. Ten bits last 1.04 ms. The figure opens on this frame.
The mistake to avoid
A second trap: TX does not connect to TX. What one side transmits the other must receive, so TX goes to RX in each direction, and the two grounds must be joined.
Check yourself
A link runs at 115,200 baud in the 8N1 format. How many bytes of data can it carry each second?
A GPS receiver is connected to a logger. The logger shows a steady flow of characters, but they are all wrong. What do you check first?
The letter C is code 67, which is 0100 0011 in binary. Which two data bits follow the start bit on the wire?
Where you meet it
- Service portsThe port a technician uses to read the messages of a controller, a router or a drive is nearly always a UART.
- GPS and modemsA GPS receiver and a mobile network modem both pass their data to the main chip as text on a UART.
- Energy meters and drivesThe meters on a plant network send UART frames on a pair of wires made for long cables.
- A frame is a start bit (0), eight data bits with the least significant first, and a stop bit (1).
- Time for one bit = 1 ÷ baud rate. Ten bits carry one byte.
- There is no clock wire. Both sides must be set to the same baud rate and format.
- Wrong characters point to the settings. No characters point to the wiring: TX goes to RX.
Discussion
No comments yet. Questions, results from your own build, a better way to explain it: all welcome.
My notes on this page
Kept on this device only. Nothing is sent anywhere.
Tip: select words in the lesson, or tap a figure or an equation, to put a note right there.
Notes on earlier wording
The lesson has changed and these words are no longer in it. Your notes are kept, with the words you chose.