MAE 3185 - Introduction to Mechatronics

Logo

View the Project on GitHub Abhiricky1992/UTA-MAE3185-Notes

Working

Let’s first focus on the idea of “bit-by-bit transfer of information” for a while. For both devices to understand what each bit means, or to make sens of what a collection of bits mean, there has to be a set of rules that both devices must follow. A similar idea was used in Morse Code, where each character of the alphabet and the numbers were converted into a set of short and long pulses. These short and long pulses, dots and dashes, can then be transmitted and received through some medium, i.e. light, sound or voltage.

UART operates in a similar fashion. It defines how the bits of information should be grouped together into a packet. Then, the packet can be transmitted and received in the form of different voltage values at different times. Since each device, communicating through UART, has individual TX and RX pins, the TX pin is configured as a GPIO output while the reception pin is configured as a GPIO input. Now, the voltage in a wire connected between a TX pin and an RX pin can be changed by the TX pin and can be read by the RX pin.

UART Packet

Each UART packet contains a start bit, 5-9 data bits, an optional parity bit and 1 or 2 stop bits.

Start
bit

5 - 9
Data bits

0 or 1
Parity
bits

1 or 2
Stop bits

Note that there can be many versions of a UART packet since the total number of bits in a packet is not fixed. Thus, both the devices communicating through UART must know the packet configuration in advance. The UART packet configuration is generally defined by three values as: <nDataBits><nParityBits><nStopBits>. For example, the 8N1 configuration means that the packet would contain 8 data bits, no parity bit and 1 stop bit. The 8N1 configuration is the most commonly used packet configuration.

Now that we understand how a UART packet is defined, let’s take a look at an example. Following diagram shows a TX and an RX pin of two devices. The black line between them represents the voltage in the wire. The voltage in the wire over time is shown in the graph below. The text box allows you to enter a character, which is converted to a binary number as per the ASCII encoding. This binary number is transmitted through a UART packet with 8N1 configuration.

TX

RX

Baud Rate

Note that so far in our discussion of UART protocol, we have not discussed when the RX pin should measure the voltage of the wire. As mentioned previously, UART is an asynchronous protocol, thus there is no clock signal instructing a device of when to measure the voltage. This issue is resolved by defining a Baud Rate, which specifies how many bits should be transferred per second. In other words, it defines the length of time for which the voltage corresponding to one bit will be maintained in the wire. Thus, the RX pin starts measuring wire voltage with a predefined time interval once it receives a start bit, i.e. once the wire voltage switches from HIGH to LOW. Following table lists the most commonly used baud rates, bit duration and the corresponding data rates for 8N1 configuration of the packet.

Baud Rate (bits/s) Bit Duration (μs) Data Rate (bits/s)
9600 104.167 7680
19200 52.083 15360
38400 26.042 30720
57600 17.361 46080
115200 8.681 92160

Calculation of the data rate in the table above is quite straight forward. For 8N1 configuration, a packet contains 10 bits in total. Out of which, only 8 bits are data bits. Thus, there is only 8 bits of information transferred per 10 bits of transmission. Thus, if the baud rate was 9600 bits/s then the data rate would be 9600*0.8 = 7680 bits/s.