Skip to content

This example shows how to use the printf function to send messages over EUSART and display charts in MPLAX Data Visualizer using Data Stream Protocol.

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic18f47q10-cnano-eusart-printf-mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCHP

Sending Formatted Messages Using printf – Use case for Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) Using the PIC18F47Q10 Microcontroller With MCC Melody

In many applications, it is a standard practice to transmit messages containing variable fields through the EUSART. This is the case when an application needs to communicate sensor readings, for instance. Using formatted messages offers considerable flexibility and has the added benefit of minimizing the amount of code required. Such functionality can be achieved by redirecting the Standard Input/Output (STDIO) to interface with the EUSART.

In this example, a numerical counter value along with twice its value are transmitted in binary form via the Data Stream Protocol through the EUSART. The MPLAB® X Data Visualizer has a built-in Data Stream Protocol decoder, which enables it to display real-time graphical representations of the values contained within the message.

Related Documentation

Software Used

Hardware Used


Operation

To program the Curiosity Nano board with this MPLAB X project, follow the steps provided in the How to Program the Curiosity Nano Board chapter.

Setup

The following peripheral and clock configurations are set up using the MPLAB Code Configurator (MCC) Melody for the PIC18F47Q10:

  1. Clock Control:
  • Clock Source: HFINTOSC
  • HF Internal Clock: 4 MHz
  • Clock Divider: 4


  1. UART2:
  • UART PLIB Selector: EUSART2
  • Requested Baud Rate: 9600
  • Data Size: 8
  • Redirect Printf to Uart: Enabled


  1. EUSART2 Peripheral:
  • Receive Enable: Disabled
  • Clock/Transmit Polarity: Non-Inverted
  • Serial Port Enable: Enabled
  • Transmit Enable: Enabled
  • Baud Rate Generator: 16-bit generator
  • Baud Rate Generator Speed Select: High speed


The following configurations must be made for this project:

Pin Configuration
RD0 (EUSART2 - TX) Digital output

Demo

The board has an on-board debugger that acts as an USART-to-USB convertor so no further hardware is needed. Run the code and configure the Data Visualizer as described in the How to Use MPLAB® Data Visualizer chapter.


Summary

This example shows how to enhance the "Hello World" use case with the ability to use the printf function to send messages over EUSART. In this example, messages are Data Stream protocol frames, which can be displayed as plots using MPLAB Data Visualizer.

How to Program the Curiosity Nano Board

This chapter demonstrates how to use the MPLAB X IDE to program an PIC® device with an Example_Project.X. This is applicable to other projects.

  1. Connect the board to the PC.

  2. Open the Example_Project.X project in MPLAB X IDE.

  3. Set the Example_Project.X project as main project.
    Right click the project in the Projects tab and click Set as Main Project.

  4. Clean and build the Example_Project.X project.
    Right click the Example_Project.X project and select Clean and Build.

  5. Select AVRxxxxx Curiosity Nano in the Connected Hardware Tool section of the project settings:
    Right click the project and click Properties.
    Click the arrow under the Connected Hardware Tool.
    Select AVRxxxxx Curiosity Nano (click the SN), click Apply and then click OK:

  6. Program the project to the board.
    Right click the project and click Make and Program Device.


How to use MPLAB® Data Visualizer

This section illustrates how to use the MPLAB X Data Visualizer to send commands and receive information, prior to programming the PIC18F56Q71 Curiosity Nano Board. This can be applied to any other project. The Data Visualizer configuration for this project is saved as a .dvws file that can be imported. To import the Data Visualizer configuration skip to step 8.

  1. Open the software terminal in MPLAB X IDE. Left click the Data Visualizer button.


  1. Prepare settings in Data Visualizer.
  • Left click the specific serial port communication COMx
  • Set the correct Baud Rate
  • Select the right Input Source


  1. Go to the Variable Streamers tab and click New to add a new variable.


  1. In the New Variable Streamer tab make the following settings:
  • Set a Variable Streamer Name
  • Select Ones' Complement for Framing Mode
  • Set Start of Frame 0x03
  • Add two new Variables by clicking the '+' symbol and name them accordingly


After setting everything mentioned above click Save.

  1. In the Variable Streamers tab, set the source to the coresponding COM and click Add Plot to plot the two variables on the graph.


  1. Click the Start button and see the expected result in Data Visualizer.


  1. To import the Data Visualizer configuration follow the next steps:
  • Right click the Important Files in the project and click Add Existing Item. Select the DV_SETTINGS.dvws file.


  • Right click DV_SETTINGS.dvws imported file and click Open with Data Visualizer.


  • Click the Start button and see the expected result in Data Visualizer as presented in the picture at step 7

Menu

About

This example shows how to use the printf function to send messages over EUSART and display charts in MPLAX Data Visualizer using Data Stream Protocol.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •