What is a UART?

AKA Serial Port, RS-232, COM Port, RS-485

This type of functionality has been referred to by many different names: Serial Port, RS-232 Interface, COM Port, but the correct name is actually UART (Universal Asynchronous Receiver Transmitter). A UART is one of the simplest methods of talking to your FPGA. It can be used to send commands from a computer to an FPGA and vice versa.

A UART is an interface that sends out usually a byte at a time over a single wire. It does not forward along a clock with the data, which is why it is called asynchronous as opposed to synchronous. UARTs can operate in either Half-Duplex (two transmitters sharing a line) or Full-Duplex (two transmitters each with their own line). UARTs have several parameters that can be set by the user. These are:

    Baud Rate            (9600, 19200, 115200, others)
    Number of Data Bits  (7, 8)
    Parity Bit           (On, Off)
    Stop Bits            (0, 1, 2)
    Flow Control         (None, On, Hardware)

These settings need to be the same on both sides of the interface (the receiver and transmitter) for communication to work correctly. When the settings are incorrect, strange and unusual characters can appear on the screen. Let’s look at each of these settings individually.

Baud Rate is the rate at which the serial data is transmitted. 9600 Baud means 9600 bits per second. Number of Data Bits is almost always set to eight. A Parity Bit can be appended after the data is sent. Parity is always computed by doing an XOR Operation on all of the data bits. A Stop Bit always set to 1, and there can be 0, 1, or 2 Stop Bits. Flow Control is not typically used in present day applications and will likely be set to None.

As mentioned previously, there is no clock that gets sent along with the data. In any interface that does not have a clock, the data must be sampled to recover it correctly. It needs to be sampled at least eight times faster than the rate of the data bits. This means that for an 115200 baud UART, the data needs to be sampled at at least 921.6 KHz (115200 baud * 8). A faster sampling clock can be used.

Click Here to see a completed UART in VHDL and Verilog!



A Trick For Debugging UARTs

Often time when debugging UARTs it is difficult to know if your computer serial port is not working or if it’s your FPGA code. Here’s a trick: Take your 9-pin cable and jumper pins 2 and 3 together. You can use a paperclip or whatever you have handy. Pins 2 and 3 are TX and RX. If you connect them together, any command you send from the computer will be received by the computer. You have created serial loopback!

Open your terminal program, try to connect to your serial cable. Hit any key on your keyboard. Baud rate and things don’t matter because it’s a loopback. If you see the character you sent out received on the terminal, your serial cable works! If not, you have a problem with your cable or with your serial program. I have had good luck using Tera Term in the past and recommend that. If you are having trouble with your serial cable, try this USB to RS-232 Cable at Amazon. I’ve used it and it works great with Windows.

FPGA-101