UART Proj
UART Proj
1
Contents
1 Introduction 3
2 Background 3
5 Test Bench 9
7 Simulation Results 13
8 Schematic 14
9 Synthesis Design 15
10 Conclusion 16
2
1 Introduction
The Universal Asynchronous Receiver-Transmitter (UART) is a widely used communication protocol for
serial data transmission between devices. It enables asynchronous communication, meaning that data is
sent one bit at a time, with the timing determined by the baud rate rather than a shared clock. UART is
fundamental in many embedded systems and digital devices for transmitting and receiving data without
the need for complex synchronization.
In UART, data transmission typically involves a start bit, followed by a sequence of data bits, an
optional parity bit for error checking, and a stop bit to signify the end of the data frame. The protocol
allows devices to communicate over a single wire, using standard baud rates to control the speed of
transmission. Its simplicity, combined with low resource requirements, makes it ideal for embedded
applications such as sensor data communication, microcontroller interfacing, and debugging.
While UART generally handles unsigned binary data, its fundamental principle of serial data trans-
mission is central to many digital systems. The protocol’s simplicity and reliability make it an essential
tool in the development of systems where straightforward, low-overhead communication is needed.
2 Background
The Universal Asynchronous Receiver-Transmitter (UART) is a serial communication protocol widely
used for transmitting data between devices. UART operates asynchronously, meaning that data is
transmitted one bit at a time without the need for a shared clock signal. This simplifies communication
in embedded systems, as devices do not need to be synchronized with each other beyond the agreement
on a common baud rate.
The UART protocol involves a simple frame structure, typically consisting of a start bit, data bits,
an optional parity bit for error checking, and stop bits to indicate the end of the transmission. The data
bits can range from 5 to 9 bits, with the start bit signaling the beginning of the data transfer and the
stop bit marking the end of the transmission.
In UART communication, the timing for sending and receiving bits is determined by the baud rate,
which must be the same on both transmitting and receiving devices to ensure proper data reception.
The simplicity and reliability of UART make it particularly well-suited for low-speed, short-distance
communication, such as interfacing microcontrollers with sensors, external devices, and other embedded
systems.
While UART is primarily used for unsigned binary data, it is commonly used for communication
in various applications, including debugging, serial data transfer, and control systems. The protocol’s
straightforward design and widespread support in embedded systems make it a versatile choice for many
communication needs.
• Receiver: The counterpart of the transmitter, it receives the serial data, converts it back into
parallel form, and passes it to the receiving system.
• Shift Register: Used in both the transmitter and receiver, this component shifts the data bits
one by one into or out of the system at the correct baud rate.
• Baud Rate Generator: Controls the timing for data transmission and reception, ensuring that
both devices communicate at the same speed (baud rate).
• Start, Data, and Stop Bits: The start bit indicates the beginning of the transmission, the data
bits represent the transmitted data, and the stop bit(s) signal the end of the transmission.
• Parity Bit (optional): Used for error detection, the parity bit can be even or odd, and it ensures
that the number of ones in the transmitted data follows the specified parity scheme.
3. Data Reception: On the receiving end, the receiver listens for a start bit, which indicates the
beginning of incoming data. The receiver shifts each bit one by one, storing them in a shift register.
4. Data Conversion: After receiving all the data bits (and the optional parity bit), the receiver
converts the serial data back into parallel format, making it accessible to the receiving device.
5. Error Detection (optional): If a parity bit is used, the receiver checks it against the received
data to detect any errors in transmission. If errors are found, the data may be discarded or flagged
for retransmission.
6. Output Data: After the data is shifted and error checking is completed (if applicable), the receiver
outputs the parallel data for use by the receiving device.
The UART protocol is simple, yet effective, for reliable, low-speed serial communication. It is used
in a variety of applications, such as microcontroller communication, sensor data acquisition, and serial
debugging. The protocol’s flexibility with respect to baud rate, data bits, parity, and stop bits makes it
adaptable to a wide range of devices and systems.
10
11
12
13
14
15
16
17
18
19
20
21
22 tx_serial <= 1; // Idle state is high
23 tx_done <= 0; // Reset tx_done
24 bit_index <= 0; // Reset bit index
25 end else begin
26 current_s tate <= next_state ; // Update current state on
clock edge
27 end
28 end
29
42 START : begin
43 next_state = DATA ; // Trans ition to DATA after start
bit
44 end
45
46 DATA : begin
47 if ( baud_tick ) begin
48 if ( bit_index == 7) begin
49 next_state = STOP ; // Move to STOP after the
last data bit
50 end
51 end
52 end
53
54 STOP : begin
55 if ( baud_tick ) begin
56 next_state = IDLE ; // Return to IDLE after stop bit
57 end
58 end
59
76 START : begin
77
78 end
79
80
81
82
83
84 end
85 end
86
87
88
89
90
91 end
92 end
93
94 end
95
96
The following RTL code implements the Uart protocol for the baud generator for 50Mhz Clock
Frequency with 9600 Baud Rate in System Verilog:
Listing 2: baud generator for 50Mhz Clock Frequency with 9600 Baud Rate
1
2 CLOCK_FREQ
50000000
3
10
11
12
13
14
15
16
17 <=
18
19
20
21
22 end
23 end
24
25 endmodule
The following RTL code implements the Uart protocol for the Receiver Module in System Verilog:
Listing 3: Receiver Module for Uart Protocol
1 module uart_rx1 (
2 input wire clk ,
3 input wire rst ,
4 input wire rx_s erial ,
5 input wire baud_tick ,
6 output reg [7:0] data_out ,
7 output reg rx_done
8 );
9
42 START : begin
43 if ( baud_tick ) begin
44 next_state <= DATA ; // Move to data state after
start bit
45 bit_index <= 0; // Reset bit index
46 $display (" Time : %0 t | Start bit received ", $time );
47 end else begin
48 next_state <= START ; // Wait for baud tick
49 end
50 end
51
52 DATA : begin
53 if ( baud_tick ) begin
54 shift_reg <= { rx_serial , shift_reg [7:1]}; // Shift
in the received bit
55 $display (" Time : %0 t | Received Data Bit % b: % b",
$time , bit_index , rx_s erial);
56 if ( bit_index == 7) begin
57 next_state <= STOP ; // Move to STOP state
58
59
60
61
62 end
63
64
65 end
66 end
67
68
69
70
71
72
73
%
74 end
75
76 end
77
78
79
80 end
81 end
82
83
84
85
86 endmodule
The following RTL code implements the Uart protocol in System Verilog:
10
11
12
13
14
15
16
17
18
19
20
21
22 . BAUD_RATE ( BAUD_RATE ),
23 . CLOCK_FREQ ( CLOCK_FREQ )
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
5 Test Bench
The following test bench verifies the functionality of the Receiver Module Testbench :
10
11
12
13
14
15
16
17
18
19
20
21 . rst( rst),
22 . rx_s erial( rx_serial),
23 . baud_tick ( baud_tick ),
24 . data_out( data_out),
25 . rx_done ( rx_done )
26 );
27
38 // Clock generation
39 always #10 clk = ~clk; // 50 MHz clock
40
61 // Testbench procedure
62 initial begin
63 // Initializ e signals
64 clk = 0;
65 rst = 1;
66 rx_serial = 1; // Idle state for serial line
67 #50 rst = 0; // Release reset
68
85 // End simulation
86 #100;
87 $finish ;
88 end
89 endmodule
The following test bench verifies the functionality of the Uart Protocol Testbench
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 end
25
26
27
28 . BAUD_RATE ( BAUD_RATE ),
29 . CLOCK_FREQ ( CLOCK_FREQ )
30
31
32
33
34
35
36
37
38
39
40
41
42
43 task apply _reset ();
44 begin
45 rst = 1;
46 #100; // Hold reset for 100 ns
47 rst = 0;
48 end
49 endtask
50
75 // Testbench logic
76 initial begin
77 $display (" Starting UART Protocol Testbench ...");
78
79 // Apply reset
80 apply_res et ();
81
88 // Si mulation complete
89 $display (" Simulation Complete : All tests passed .");
90 #100 $finish ;
91 end
92 endmodule
6 Advantages and Disadvantages
6.1 Advantages
• Simplicity: UART communication is straightforward to implement, requiring only a minimal
number of control signals (start, data, stop bits) and a shared baud rate for communication.
• Low Cost: UART uses a simple design with fewer components compared to more complex com-
munication protocols, making it cost-effective for many embedded systems.
• No Need for Synchronization: Since UART is asynchronous, devices don’t need to share a
clock signal, simplifying the hardware and making it easier to implement across different systems.
6.2 Disadvantages
• Limited Speed: UART is typically slower compared to other communication protocols like SPI
or I2C, making it less suitable for high-speed data transmission.
• Short Range: The distance over which UART can reliably transmit data is limited due to the
absence of a clock signal, especially at higher baud rates.
• Limited Scalability: UART is designed for point-to-point communication, which means it is
not ideal for connecting multiple devices in a network without additional multiplexing or bus
management techniques.
• No Built-In Synchronization: Since it operates asynchronously, the baud rate must be carefully
matched between transmitting and receiving devices. Mismatched baud rates can result in data
loss or corruption.
• Requires Manual Error Handling: Although the optional parity bit allows for error detection,
UART does not have built-in mechanisms for error correction, meaning retransmission or other
corrective actions must be implemented manually.
7 Simulation Results
8 Schematic Design