5.UART Serial Communication Module Design and Simulation
5.UART Serial Communication Module Design and Simulation
5.UART Serial Communication Module Design and Simulation
com
ISSN : 2248-9622, Vol. 5, Issue 3, ( Part -5) March 2015, pp.01-04
Abstract
UART (Universal Asynchronous Receiver Transmitter) is a kind of serial communication protocol; mostly used
for short-distance, low speed, low-cost data exchange between computer and peripherals. During the actual
industrial production, sometimes we do not need the full functionality of UART, but simply integrate its core
part. UART includes three kernel modules which are the baud rate generator, receiver and transmitter. The
UART implemented with VHDL language and simulated using XILINX ISE12.1 to achieve compact, stable and
reliable data transmission. It’s significant for the design of SOC. The simulation results are completely
consistent.
Keywords- UART; asynchronous serial communication; VHDL; XILINX ISE12.1.
Start, Parity and Stop bits. If the sender and receiver M =32MHz/16*9600Hz=208
are configured identically, these bits are not passed
to the host. When the UART receives serial data, it is very
If another word is ready for transmission, the critical to determine where to sample the data
Start Bit for the new word can be sent as soon as the information. The ideal time for sampling is at the
Stop Bit for the previous word has been sent. middle point of each serial data bit. In this design, the
Because asynchronous data are “self- receive clock frequency is designed to be 16 times
synchronizing”, if there are no data to transmit, the the baud rate, therefore, each data width received by
transmission line can be idle. The UART frame UART is 16 times the receive clock cycle.
format is shown in Fig. 1.
B. Receiver Module
During the UART reception, the serial data and
the receiving clock are asynchronous, so it is very
important to correctly determine the start bit of a
frame data. The receiver module receives data from
RXD pin. RXD jumps into logic 0 from logic 1 can
Figure 1. UART Frame Format be regarded as the beginning of a data frame. When
the UART receiver module is reset, it has been
II. IMPLEMENTATION OF UART waiting the RXD level to jump. The start bit is
In this paper, the top to bottom (Top to Down) identified by detecting RXD level changes from high
design method is used. The UART serial to low. In order to avoid the misjudgment of the start
communication module is divided into three sub- bit caused by noise, a start bit error detect function is
modules: the baud rate generator, receiver module added in this design, which requires the received low
and transmitter module, shown in Fig. 2. Therefore, level in RXD at least over 50% of the baud rate to be
the implementation of the UART communication able to determine the start bit arrives. Since the
module is actually the realization of the three sub- receive clock frequency is 16 times the baud rate in
modules. The baud rate generator is used to produce the design, the RXD low level lasts at least 8
a local clock signal which is much higher than the receiving clock cycles is considered start bit arrives.
baud rate to control the UART receive and transmit; Once the start bit been identified, from the next bit,
The UART receiver module is used to receive the begin to count the rising edge of the baud clock, and
serial signals at RXD, and convert them into parallel sample RXD when counting. Each sampled value of
data; The UART transmit module converts the bytes the logic level is deposited in the register rbuf [7, 0]
into serial bits according to the basic frame format by order. When the count equals 8, all the data bits
and transmits those bits through TXD. are surely received, also the 8 serial bits are
converted into a byte parallel data.
The serial receiver module includes receiving,
serial and parallel transform, and receive caching,
etc. In this paper we use finite state machine to
design, shown in Fig. 3.
R_SAMPLE (sampling), and R_STOP (receiving into the register txdbuf [7: 0]. The transmitter only
stop bit). needs to output 1 bit every 16 bclkt (the transmitting
R_START Status: When the UART receiver is clock frequency generated by the baud rate
reset, the receiver state machine will be in this state. generator) cycles. The order follows 1 start bit, 8 data
In this state, the state machine has been waiting for bits, 1 parity bit and 1 stop bit. The parity bit is
the RXD level to jump over from logic 1 to logic 0, determined according to the number of logic 1 in 8
i.e. the start bit. This alerts the beginning of a new data bits. Then the parity bit is output. Finally, logic
data frame. Once the start bit is identified, the state 1 is output as the stop bit. Fig. 4 shows the transmit
machine will be transferred to R_CENTER state. In module state diagram.
Fig. 3, RXD_SYNC is a synchronization signal of
RXD. Because when sampling logic 1 or logic 0, we
do not want the detected signal to be unstable. So
we do not directly detect RXD signal, but detect the
synchronization signal RXD_SYNC.
R_CENTER Status: For asynchronous serial
signal, in order to detect the correct signal each
time, and minimize the total error in the later data
bits detection. Obviously, it is the most ideal to
detect at the middle of each bit. In this state, the task
is to find the midpoint of each bit through the start
bit. The method is by counting the number of bclkr
(the receiving clock frequency generated by the
baud rate generator) (RCNT16 is the counter of
bclkr). In addition, the start bit detected in the
R_START may not be a really start bit, it may be an Figure 4. Transmit Module State Diagram
occasional interference sharp pulse (negative pulse).
This interference pulse cycle is very short. This state machine has 5 states: X_IDLE (free),
Therefore, the signal that maintains logic 0 over 1 / X_START (start bit), X_WAIT (shift to wait),
4 bit time must be a start bit. X_SHIFT (shift), X_STOP (stop bit).
R_WAIT Status: When the state machine is in X_IDLE Status: When the UART is reset, the
this state, waiting for counting bclkr to 15, then state machine will be in this state. In this state, the
entering into R_SAMPLE to sample the data bits at UART transmitter has been waiting a data frame
the 16th bclkr. At the same time determining sending command XMIT_CMD. XMIT_CMD_P is a
whether the collected data bit length has reached the processed signal of XMIT_CMD, which is a short
data frame length (FRAMELEN). If reaches, it pulse signal. Since XMIT_CMD is an external signal,
means the stop bits arrives. The FRAMELEN is outside FPGA, its pulse width is unable to be limited.
modifiable in the design (using the Generic). In this If XMIT_CMD is valid, it is still valid after sending
design it is 8, which corresponds to the 8-bit data one UART data frame. Then the UART transmitter
format of UART. will think by mistake that a new data transmit
R_SAMPLE Status: Data bit sampling. After command has arrived, and once again start the frame
sampling the state machine transfers to R_WAIT transmit. Obviously the frame transmit is wrong.
state unconditionally, waits for the arrival of the Here we limit the pulse width of XMIT_CMD.
next start bit. XMIT_ CMD_P is its processed signal. When
R_STOP Status: Stop bit is either 1 or 1.5, or 2. XMIT_CMD_P = '1 ', the state machine transferred
State machine doesn’t detect RXD in R_STOP, but to X_START, get ready to send a start bit.
output frame receiving done signal (REC_DONE X_START Status: In this state, sends a logic 0 signal
<= '1 '). After the stop bit, state machine turns back to the TXD for one bit time width, the start bit. Then
to R_START state, waiting for the next frame start the state machine transferred to X_WAIT state.
bit. XCNT16 is the counter of bclkt.
X_WAIT Status: Similar with the R_WAIT of
C. Transmit Module UART receive state machine.
The function of transmit module is to convert
the sending 8-bit parallel data into serial data, adds X_SHIFT Status: In this state, the state machine
start bit at the head of the data as well as the parity realizes the parallel to serial conversion of outgoing
and stop bits at the end of the data. When the UART data. Then immediately return to X_WAIT state.
transmit module is reset by the reset signal, the X_STOP Status: Stop bit transmit state. When
transmit module immediately enters the ready state the data frame transmit is completed, the state
to send. In this state, the 8-bit parallel data is read machine transferred to this state, and sends 16 bclkt
cycle logic 1 signal, that is, 1 stop bit. The state The simulation report shows that this module uses 78
machine turns back to X_IDLE state after sending logic elements(<1%, 13 pins (4%), and meets
the stop bit, and waits for another data frame timing requirement.
transmit command.