...
UART is a protocol that is used to communicate between microcontrollers
It is typically implemented with the following 3 physical logic levels:
TTL
RS-232
RS-422
RS-485 (Outside the scope of this document, not hard to pick up)
For those who have used Arduino, UART is the protocol that is used to facilitate ‘Serial’ communication
...
Note, the TX wires of one microcontroller are wired to the RX wires of the other microcontroller. A similar situation occurs on the RTS and CTS wires. Always verify that the TX and RX wires are swapped.
...
USART vs UART
Some connections called USART (Universal Synchronous/Asynchronous Receiver/Transmitter) add a clock signal to the signals seen above. The clock signal regulates the rate of data transmission and removes the need for both sides to agree on a baud rate.
The sending device or an external source will transmit a clock signal that will allow the devices to read specific bits. The clock signal will be labeled CLK or Clock.
Theory of Operation
Serial protocols can be characterized into 2 types, synchronous and asynchronous. As you may have guessed by the acronym, the asynchronous in UART refers to the fact that the protocol is asynchronous The synchronous version is called USART (see difference in USART vs. UART). It is outside the scope of this document to discuss the advantages and disadvantages of each type, it is discussed more fully here: Asynchronous vs Synchronous Protocols
The sample rate of the protocol is referred to as the baud rate. Standard baud rates include 9600, 38400, 115200, etc.
Typically, a data packet can be anywhere from 8-12 bits wide. The elements are typical as follows
Start & stop bits:
As discussed in the Async vs Sync protocol document, the line is pulled low to indicate the start of transmission. A single bit is appended to the start and end of the packet.
Data:
The data can be anywhere from 5-9 bits wide. The exact number varies per application, but typically 8.
Parity bit(s):
A parity bit may be appended to the end of the message to ensure accuracy of the message. A parity bit operates by setting the extra appended bit to either 0 or 1 to preserve the parity of the payload.
Consider a protocol that has a single ‘even’ parity bit that has a message of
10101010
. Since there are 4 high bits (1’s) in the payload, the parity of 1’s is even as 4 is even, therefore the message with the appended parity bit is101010100
.Consider a protocol that has a single ‘even’ parity bit that has a message of
10101011
. Since there are 5 high bits (1’s) in the payload, the parity of 1’s is odd as 5 is odd, therefore the message with the appended parity bit is101010111
to make the parity of 1’s even.
...
Application Notes
CTS/RTS and other signals do exist (technically not UART, but I don’t want to get into why), but are not required in the majority of applications. Instances where these signals are used include programming and resetting microcontrollers, or communicating if a device has data ready or not. TL;DR, you can get away with just TX & RX
You don’t need to have both TX and RX, there is no sort of handshaking etc, so you can have a device that is only capable of transmitting and a device only capable of listening etc.
The most popular instance of UART being used in my opinion is a USB-UART bridge as it is a cheap way to implement USB while using UART on the microcontroller end and letting a chip do the fancy work.
Don’t use this protocol for anything with super high data transfer conditions, you’ll start to cap out at a nominal frequency of ~15kHz, which is nothing compared to a synchronous protocol where rates of 5MHz can be used without breaking a sweat.
In my opinion, UART is one of the easiest protocols to implement.
Common mistakes
Ensure that TX and RX are swapped as per above
on our blue USB-TTL cables, the green wire is tx, and the white is rx
The baud rate typically needs to be within +- 5% of the original baud rate, otherwise it will be mismatched and you will be unable to read anything.
Always check the tolerances on the clock of your MCU before using it in an async protocol application. If you don’t you may end up falling for baud rate mismatch. Note that typically an internal oscillator won’t cut it.