Summary of Transmitting and receiving data using UART protocol PIC Microcontroller
This tutorial explains initializing and using UART (serial) communication on PIC microcontrollers to transmit and receive data using two pins. It describes key UART registers (TXSTA, RXSTA, SPBRG), gives baud rate formulas for low and high speed modes, and states that SPBRG = 129 yields 9600 bps with a 20 MHz crystal. The article assumes familiarity with UART concepts and refers readers to the PIC datasheet for detailed bit descriptions.Parts used in theUART or serial communication using PIC microcontroller:
- PIC microcontroller (with UART support)
- 20 MHz crystal oscillator
- TXSTA register (transmit status and control)
- RXSTA register (receive status and control)
- SPBRG register (baud rate generator)
- Two UART data pins (TX and RX)
UART or serial communication is one of the important protocol used by the Microcontrollers to transmit and receive data from the external devices. Almost every controller is equipped with this protocol to make transmission and reception easier just using two pins. This tutorial will teach you to initialize and send data by using UART protocol PIC microcontroller.
I assume that you are familiar with the concept of UART and proceed to explain the steps to initialize and use it in PIC controller. If you are familiar with the concept of UART kindly go through this link before proceeding.
REGISTERS USED IN UART:
TXSTA REGISTER: This register have the status and control bits of the Transmission in the controller.
RXSTA: This register holds the status and control bits of the Reception in the microcontroller.
SPBRG: This register holds the value which decides the baud rate of the serial communication. The formula governing the calculation varies based on the modes high speed and low speed.
LOW SPEED:
(Asynchronous) Baud Rate = FOSC/(64 (X + 1))
(Synchronous) Baud Rate = FOSC/(4 (X + 1))
HIGH SPEED:
Baud Rate = FOSC/(16 (X + 1))
Where X is the value of SPBRG register.
Since we are using standard 9600 bps, we are about to use 129 in the SPBRG register. According to the datasheet it results in giving 9600 bps 20MHZ crystal. You can find brief explanation of the bits in these registers in the data sheet of this controller.
For more detail: Transmitting and receiving data using UART protocol PIC Microcontroller
Quick Solutions to Questions related toUART or serial communication using PIC microcontroller:
- What registers are used for UART transmission and reception in PIC microcontrollers?
The article lists TXSTA for transmission and RXSTA for reception. - How is the baud rate set for UART on a PIC microcontroller?
The baud rate is set using the SPBRG register with formulas provided for low and high speed modes. - What SPBRG value gives 9600 bps with a 20 MHz crystal?
The article states using 129 in the SPBRG register yields 9600 bps with a 20 MHz crystal. - What is the baud rate formula in low speed asynchronous mode?
Baud Rate = FOSC/(64 (X + 1)) where X is SPBRG. - What is the baud rate formula in low speed synchronous mode?
Baud Rate = FOSC/(4 (X + 1)) where X is SPBRG. - What is the baud rate formula in high speed mode?
Baud Rate = FOSC/(16 (X + 1)) where X is SPBRG. - How many pins are typically used for UART communication?
The article notes UART transmission and reception use two pins. - Where can I find detailed explanations of UART register bits for a PIC?
The article advises checking the PIC controller datasheet for brief explanations of the bits.
Related projects
Leveraging Blockout Banners for Effective Electronics and Tech Product Displays
Blockout banners have become a popular and effective tool for displaying electronics and tech products in various settings, from trade shows and...
LCD & Display Projects · PIC18F4520Interfacing PIC18F4520 microcontroller with an HD44780 LCD
Introduction Being able to display data from a microcontroller visually has many advantages. It allows for menus, status indicators, and instructions to...
LCD & Display ProjectsVideo Project Development in the Midst of an Impromptu Online Semester
Receiving robot parts in the mail was an unexpected conclusion to the Winter 2020 semester for students. However, when faced with a...
LCD & Display Projects · PIC16F628AFrequency Counter by PIC16F628
In this project we are building a basic and low cost frequency counter circuit . It can measure from 16Hz to 100Hz...
LCD & Display ProjectsWHAT IS A PIC MICROCONTROLLER? WHAT CAN IT DO?
PIC microcontrollers ( Programmable Interface Controllers), are electronic circuits that can be programmed to carry out a vast range of tasks. They...
LCD & Display Projects · PIC16F877ASerial Data Received from PC and Displayed on 16×2 Using USART of Pic16f877 Microcontroller
Here is a simple tutorial on how to receive serial data from PC(Personal Computer) Hyperterminal and display it on 16x2 lcd using...

