It is a common use case for an application to send a message with variable fields over EUSART, when the application reports a sensor reading, for instance. Using formatted messages is a very flexible approach and reduces the number of code lines. This can be accomplished by redirecting STDIO to EUSART.
In this example, a counter value and twice its value are sent in a binary format, using the Data Stream Protocol, over EUSART. The MPLABX Data Visualizer has a built-in Data Stream Protocol decoder and can display charts of the values in the message in real time.
- TB3282 - Getting Started with UART using EUSART on PIC18
- PIC18F-Q10 Family Product Page
- PIC18F47Q10 Data Sheet
- PIC18F47Q10 Code Examples on GitHub
- MPLAB® X IDE 5.30 or newer (microchip.com/mplab/mplab-x-ide)
- MPLAB® XC8 2.10 or a newer compiler (microchip.com/mplab/compilers)
- MPLAB® Code Configurator (MCC) 3.95.0 or newer (microchip.com/mplab/mplab-code-configurator)
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs (microchip.com/mplab/mplab-code-configurator)
- Microchip PIC18F-Q Series Device Support (1.4.109) or newer (packs.download.microchip.com/)
- PIC18F47Q10 Curiosity Nano (DM182029)
The PIC18F47Q10 Curiosity Nano Development Board (DM182029) is used as the test platform. It has an onboard debugger that acts as an USART to USB convertor so no further hardware is needed.
The following configurations must be made for this project:
Pin | Configuration |
---|---|
RD0 | Digital Output |
Run the code and configure the Data Visualizer as described in the Technical Brief document.
This example shows how to enhance the "Hello World" use case with the ability to use printf function to send messages over EUSART. In this example, messages are Data Stream protocol frames, MPLAB Data Visualizer can be used to display them as plots.