EUSART Setup Basics in Xpress

The purpose of this tutorial is to provide a basic overview of the Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) module in the MPLAB® Code Configurator (MCC).

Synchronous/asynchronous serial communication is often used to communicate between the microcontroller and other peripheral devices that expand the microcontroller’s capabilities without radically changing the design. A few good examples that use the EUSART are the RN41 wireless module and the CAN bus technology, as well as many others. EUSART is especially useful for the RS-232 protocol as well as RS-422 and RS-485. One example of the RS-232 protocol would be communication with a PC Terminal Program.

EUSART communication style is useful because it only requires two pins, with no clock pin in Asynchronous mode. It is also simpler than other serial protocols to understand. However, its limitations lie in the fact that each set of two pins can only facilitate communication between one pair of microcontrollers, as opposed to other serial protocols that may not require additional data lines (think additional pins on your microcontroller) to add controllers to the communication process.

Locating the EUSART

The EUSART block is located under Device Resources in the MCC.


Double-clicking on the EUSART opens the following window:


Basic Use

Enable EUSART: This box selection enables the EUSART peripheral.

Enable Transmit: EUSART communication has two lines, one for transmitting labeled TX and the other for receiving labeled RX. RX is automatically enabled but this box enables the transmit capabilities.

Baud Rate: The baud rate ensures the data transmission rate of the controller sending out the signal is the same as that of the controller receiving the signal. If these are different, the controllers will not be able to communicate because the pulses of the information bits will be different lengths. 9600 is a fairly common rate. You can, however, set it to other baud rates as well.

Redirect STDIO to USART: Some of the more common functions in programming such as printf(), putchar(), and puts() are included in the STDIO (stdio.h) library. Checking this box allows the use of this functionality. Keep in mind that this will require additional memory to accommodate the stdio.h libraries.

Configuring the Pins in MCC

As previously mentioned, the EUSART uses two pins: TX and RX. These will connect to the opposite pin on the other microcontroller being communicated with (i.e the TX of the Xpress board will be connected to the RX of the other microcontroller and vice versa).

To select these pins, click the chosen locks in the MCC Pin Manager:


The RC0 and RC1 are chosen here because these connections will allow the PIC16F18855 based Xpress board to communicate with the PC for testing and developing applications using a terminal on the computer.

Using Basic Software Functionality in main.c file


MCC will generate library files that contain custom functions for the EUSART. The eusart.h header file contains three functions, all of which are important to the data communication process. Find this file under the Project tab, as seen in the figure above.

Software Function (found in eusart.h) What It Does
void EUSART_Initialize(void); This function sets-up all the preset register values for the EUSART on launch and must be called at the beginning of a code using the EUSART functionality.
uint8_t EUSART_Read(void); This function reads a byte of data from the incoming signal on the RX line.
void EUSART_Write(uint8_t txData); This function writes a byte of data to the TX line to be read by the other microcontroller or computer.

Another important aspect to keep in mind is the functionality of the STDIO library which provides a very efficient way to accomplish the same things as the functions above.

Example Code

One such example is seen in the code below:

#include "mcc_generated_files/mcc.h"
void main(void)
    // initialize the device
    while (1)
        puts("Hello World!");

It displays the entire string “Hello World!” as opposed to updating individual bytes through the EUSART_Write() command.


While this covers just the basics needed to get a project up and running, more information on how to use this peripheral can be found in this example application.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.