Introduction
Author: Alexandru Niculae, Microchip Technology Inc. |
The UART-capable peripherals come in different variants on microcontrollers. Sometimes, the peripheral is named UART or USART and sometimes it is called EUSART to emphasize enhanced functionalities. The data sheet of each device shows the type of UART peripheral it has.
The purpose of this document is to describe how to configure the Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) on PIC18 devices to demonstrate its usage for some common use cases.
- For each use case, there are three different implementations, which have the same functionalities: one generated with MPLAB® Code Configurator (MCC), one generated using the Foundation Services MCC Library and one bare metal.
- The MCC generated code offers hardware abstraction layers that ease the use of the code across different devices of the same family. The Foundation Services generated code offers a driver-independent Application Programming Interface (API) and facilitates the portability of code across different platforms. The bare metal code is easier to follow and allows a fast ramp-up on the use case associated code.
While EUSART is a complex peripheral and can work in various modes, this document will use it in Asynchronous mode and describes the following use cases:
- Send ‘Hello
World’:
This example shows how to send a string to the PC and see it in the MPLAB® Data Visualizer Terminal.
- Send
Formatted Messages Using
printf
:This example shows how to enhance the first use case with the ability to use the
printf
function to send messages over EUSART. In this example, messages are Data Stream protocol frames, and the MPLAB Data Visualizer can be used to display them as plots. - Receive
Control Commands:
This example shows how to implement a command line interface. This way, the microcontroller can receive control commands via the EUSART. In this use case, an LED is controlled using commands sent from the MPLAB Data Visualizer.
The examples in this technical brief have been developed using the PIC18F47Q10 Curiosity Nano development board, which is equipped with the QFN40 package.