3 Send Formatted Messages Using
printf
It is a common use case for an application to send a message with variable fields over EUSART, such as when the application reports a sensor reading. Using formatted messages is a very flexible approach and reduces the number of code lines. This can be accomplished by redirecting Standard Input/Output (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 MPLAB X Data Visualizer has a built-in Data Stream Protocol decoder and can display charts of the values in the message in real time.
This use case follows the steps:
- Configure the system clock
- Configure EUSART2
- Configure the pins