Universal Asynchronous Receiver Transmitter (UART)

Serial Communication

Basics of Serial Communication

  • Computers transfer data in two ways:


Difference between serial and Parallel communication

Sr. NoFactorSerialParallel
1No. of bits transmitted per one clock pulseOne bit'n' bits
2No. of line required to transmit 'n' bitsOne line'n' lines
3Speed of data transferSlowFast
4Cost of transmissionLow as only one line is requiredHigher as n lines are required
5ApplicationLong distance communicationSmall disatnce communication
  • Serial data communication uses two methods
  • Synchronous method transfers a block of data at a time

synchronous transmission.png

Asynchronous – Start & Stop Bit

asynchronous transmission.png

  • Asynchronous serial data communication is widely used for character-oriented transmissions
    • Each character is placed in between start and stop bits, this is called framing.
  • The start bit is always one bit, but the stop bit can be one or two bits
  • The start bit is always a 0 (low) and the stop bit(s) is 1 (high)
Asynchronous serial communicationSynchronous serial communication
transmitter and  receiver are not synchronized by clock.transmitter and  receiver are synchronized by clock.
Character may arrive at any rate at receiverCharacter is received at constant rate.
Data transfer is character orientedData transfer takes place in blocks.
Start and stop bits are required to establish communication of each character.Start and stop bits are not required to establish communication of each character, however ,synchronization bits are required to transfer the data block.
Used in low-speed transmissionsUsed in high-speed transmission
  • Data Transfer RateThere are special IC’s made by many manufacturers for serial communications.
    • UART (universal asynchronous Receiver transmitter)
    • USART (universal synchronous-asynchronous Receiver-transmitter)
  • The rate of data transfer in serial data communication is stated in bps (bits per second).
  • Another widely used terminology for bps is baud rate.
  • Serial port of 8051 is full duplex, means it can transmit and receive simultaneously.

Interfacing of PIC18Fxxx Microcontroller to PC using Serial communication

  • A personal computer has a serial port known as communication port or COM Port used to connect a modem for example or any other device, there could be more then one COM Port in a PC. Serial ports are controlled by a special chip called UART (Universal Asynchronous Receiver Transmitter).
  • RS 232  standard describes a communication method where information is sent bit by bit on a physical channel. The RS stands for Recommended Standard.The information must be broken up in data words. The length of a data word is variable.
  • It is one of the popularly known interface standard for serial communication between DTE & DCE. This RS-232-C is the commonly used standard when data are transmitted as voltage .This standard was first developed by Electronic industries association(EIA). For the RS-232C, a 25 pin D type connector is used . DB-25P male and DB-25S female. RS-232 standard was first introduced in 1960’s by Telecommunications Industry Association(TIA).
  • As the RS-232 standard is developed earlier to TTL devices ,a USART such as 8251 is not directly compatible with these signal levels .Because of this ,voltage transistors called line drivers and line receivers are used to interface TTL logic with RS-232 signals . The line driver MC 1488 is used  to convert RS-232 to TTL.The microcontroller is connected to the PC using the DB9 connector.


Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART)

The Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module is one of the two serial I/O modules. (Generically, the USART is also known as a Serial Communications Interface or SCI.) The EUSART can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as CRT terminals and personal computers. It can also be configured as a halfduplex, synchronous system that can communicate with peripheral devices, such as A/D or D/A integrated circuits, serial EEPROMs, etc. The Enhanced USART module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on Sync Break reception and 12-bit Break character transmit. These make it ideally suited for use in Local Interconnect Network bus (LIN bus) systems.
The EUSART can be configured in the following modes:

  • Asynchronous (full duplex) with: - Auto-wake-up on character reception - Auto-baud calibration - 12-bit Break character transmission
  • Synchronous – Master (half duplex) with selectable clock polarity
  • Synchronous – Slave (half duplex) with selectable clock polarity

The pins of EUSART with   PORTC. In order to configure RC6/TX/CK and RC7/RX/DT as an EUSART:

  • bit SPEN (RCSTA<7>) must be set (= 1)
  • bit TRISC<7> must be set (= 1)
  • bit TRISC<6> must be set (= 1)

USART Transmitter Section


USART Receiver Block


The operation of the Enhanced USART module is performed using following registers:

  • Serial port Baud Rate Generator(SPBRG)
  • Transfer Buffer Register(TXREG) and Receive Buffer Register (RCREG)
  • Transmit Status and Control (TXSTA)
  • Receive Status and Control (RCSTA)
  • Peripheral Interrupt Register(PIR1)
  • Baud Rate Control (BAUDCON) 

TXSTA: Transmit Status And Control Register

7 CSRC: Clock Source Select bit
Asynchronous mode: 
Don’t care.
Synchronous mode: 
1 = Master mode (clock generated internally from BRG)
0 = Slave mode (clock from external source) 
6TX9: 9-Bit Transmit Enable bit
1 = Selects 9-bit transmission
0 = Selects 8-bit transmission 
5TXEN: Transmit Enable bit(1)
1 = Transmit enabled
0 = Transmit disabled 
4SYNC: EUSART Mode Select bit
1 = Synchronous mode
0 = Asynchronous mode 
3 SENDB: Send Break Character bit
Asynchronous mode:
1 = Send Sync Break on next transmission (cleared by hardware upon completion)
0 = Sync Break transmission completed
Synchronous mode: Don’t care.
2 BRGH: High Baud Rate Select bit
Asynchronous mode:
1 = High speed
0 = Low speed
Synchronous mode:
Unused in this mode.
1 TRMT: Transmit Shift Register Status bit
1 = TSR empty
0 = TSR full 
0TX9D: 9th Bit of Transmit Data Can be address/data bit or a parity bit.

Note 1: SREN/CREN overrides TXEN in Sync mode.

RCSTA: Receive Status And Control Register

7SPEN: Serial Port Enable bit
1 = Serial port enabled (configures RX/DT and TX/CK pins as serial port pins)
0 = Serial port disabled (held in Reset) 
6 RX9:  9-Bit Receive Enable bit
1 = Selects 9-bit transmission
0 = Selects 8-bit transmission 
5SREN: Single Receive Enable bit
Asynchronous mode: Don’t care. 
Synchronous mode – Master:
1 = Enables single receive
0 = Disables single receive
This bit is cleared after reception is complete. 
4CREN: Continuous Receive Enable bit
Asynchronous mode: 
1 = Enables receiver
0 = Disables receiver
Synchronous mode:
1 = Enables continuous receive until enable bit, CREN, is cleared (CREN overrides SREN)
0 = Disables continuous receive 
3ADDEN: Address Detect Enable bit
Asynchronous mode 9-Bit (RX9 = 1):
1 = Enables address detection, enables interrupt and loads the receive buffer when RSR<8> is set
0 = Disables address detection, all bytes are received and ninth bit can be used as parity bit
Asynchronous mode 9-Bit (RX9 = 0): Don’t care
2FERR: Framing Error bit  
1 = Framing error (can be cleared by reading RCREG register and receiving next valid byte)
0 = No framing error 
1OERR: Overrun Error bit  
1 = Overrun error (can be cleared by clearing bit, CREN)
0 = No overrun error 
0 RX9D: 9th Bit of Received Data This can be address/data bit or a parity bit and must be calculated by user firmware.

BAUDCON: Baud Rate Control Register

Baud Rate

Definition:-The rate at which the number of bits are transmitted from Personal computer to Microcontroller and vice-versa
PC and microcontroller supports various types of Baud rates eg. 19200,9600,4800,2400,1200 etc


7ABDOVF: Auto-Baud Acquisition Rollover Status bit 
1 = A BRG rollover has occurred during Auto-Baud Rate Detect mode (must be cleared in software)
0 = No BRG rollover has occurred 
6RCIDL: Receive Operation Idle Status bit 
1 = Receive operation is Idle
0 = Receive operation is active 
5 RXDTP: Data/Receive Polarity Select bit 
Asynchronous mode: 
1 = Receive data (RX) is inverted (active-low)
0 = Receive data (RX) is not inverted (active-high)
Synchronous mode: 
1 = Data (DT) is inverted (active-low)
0 = Data (DT) is not inverted (active-high)
4TXCKP: Clock and Data Polarity Select bit 
Asynchronous mode:
1 = Idle state for transmit (TX) is a low level
0 = Idle state for transmit (TX) is a high level
Synchronous mode: 
1 = Idle state for clock (CK) is a high level
0 = Idle state for clock (CK) is a low level 
3 BRG16: 16-Bit Baud Rate Register Enable bit 
1 = 16-bit Baud Rate Generator – SPBRGH and SPBRG
0 = 8-bit Baud Rate Generator – SPBRG only (Compatible mode), SPBRGH value ignored 
2 Unimplemented: Read as ‘0’ 
1 WUE: Wake-up Enable bit
Asynchronous mode:
1 = EUSART will continue to sample the RX pin – interrupt generated on falling edge; bit cleared in hardware on following rising edge
0 = RX pin not monitored or rising edge detected
Synchronous mode: Unused in this mode
0  ABDEN: Auto-Baud Detect Enable bit 
Asynchronous mode: 
1 = Enable baud rate measurement on the next character. Requires reception of a Sync field (55h); cleared in hardware upon completion.
0 = Baud rate measurement disabled or completed
Synchronous mode:
Unused in this mode.
Configuration BitsBRG/EUSART ModeBaud Rate Formula
0008-Bit/AsynchronousFOSC/[64 (n + 1)]
0018-Bit/AsynchronousFOSC/[16 (n + 1)]
01016-Bit/AsynchronousFOSC/[16 (n + 1)]
01116-Bit/AsynchronousFOSC/[4 (n + 1)]
10x8-Bit/SynchronousFOSC/[4 (n + 1)]
11x16-Bit/SynchronousFOSC/[4 (n + 1)]

SPBRG value Calculation

For a device withcrystal frequency(Fosc) of 10 MHz, desired baud rate of 9600, Asynchronous mode, Calculate the value to be loaded in SPBRG register
X= [156250 / Desired Baud Rate ] -1
  = [156250 /9600 ]-1
 = 15.27 =~15

For a device with crystal frequency(Fosc) of 4 MHz, desired baud rate of 9600, Asynchronous mode, Calculate the value to be loaded in SPBRG register
X= [62500 / Desired Baud Rate ] -1  .....by default BRGH=0 Hence (Fosc/4)/16
  = [62500 /9600 ]-1
 = 5.51 =~5

Video Tutorial on UART in PIC

The Video URL you entered () does not match any of the video websites supported by this macro. Please check the address you entered or improve the macro to make it support this website.


Video and CODE Explanation

#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF, LVP=OFF
void  sendUSART (void);
unsigned char text[]="\n\rHELLO";
unsigned int i=0;
void main(void)

 SPBRG=12;  //BAUDRATE=4800
  sendUSART ();

void  sendUSART (void)

serial reception

#include <P18f4520.h>

#pragma config OSC=HS
#pragma config PWRT=OFF
#pragma config WDT=OFF
#pragma config DEBUG=OFF, LVP=OFF
unsigned char data;

void main()
  TRISD = 0x00;
  TRISCbits.TRISC7=1; //Make UART RX pin input
     RCSTA=0X90;  //Serial port enabled
 SPBRG=12;   //Fill SPBRG register to set the baud rate
 SPBRGH  = 0;      //4800bps




  • Created and Developed by Prof. Sujit Wagh, SKNCOE
  • WikiNote Foundation

Last modified: Tuesday, 17 September 2019, 2:18 PM