4.1.4.1 UART Hello World

This section describes in detail on how to enable UART functionality on PIC32WM-BW1 Curiosity board using MCC.

Users can choose to just run the precompiled Application Example hex on the PIC32WM-BW1 Curiosity Board and experience the demo or can go through the steps involved in enabling UART from scratch using MCC

Hardware Requirements

Table 4-16. Hardware Requirements
Tool Qty
PIC32WM-BW1 Curiosity Board1
USB Type-C cable1

Software Requirements

  • To install Tera Term tool, refer to the Tera Term web page listed in the Reference Documentation from Related Links.

Programming the precompled hex file or Application Example

Programming the hex file using MPLABX IPE:

  1. Precompiled Hex file is located in “<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\chip_peripherals\uart_hello_world\hex” folder

  2. For detailed steps, refer to Programming a Device in MPLAB® IPE in Reference Documentation from Related Links.
    Note: Ensure to choose the correct Device and Tool information.

Programming the Application using MPLABX IDE:

  1. Perform the following the steps mentioned in Running a Precompiled Example. For more information, refer to Running a Precompiled Application Example from Related Links.
  2. Open and program the application example “uart_hello_world.X” located in “<Harmony Content Path>\wireless_apps_pic32_bw1\apps\ble\chip_peripherals\uart_hello_world\firmware” using MPLABX IDE.

Testing

  1. Connect the PIC32WM-BW1 Curiosity board to PC, program the application example. Open Tera Term and configure it with following settings:
    1. Baud rate/ Speed – 115200
    2. Parity – None
    3. Data bits – 8
    4. Stop bits – 1
    5. Flow Control – None
  2. Reset the board and the demo will print “Hello World” on the terminal.
    Figure 4-106. Tera Term

Project Graph

This section explains how MCC Project graph must look like and component configurations.
  1. Verify if the Project Graph window has all the expected configuration as illustrated in the following figure.
Figure 4-107. Project Graph

Verify UART Configuration

  1. Select SERCOM0 component in project graph. The Transmit pinout configuration is for without hardware flow control.
    Figure 4-108. Sercom0 Configuration
  2. Select System component in project graph
    Figure 4-109. System Configuration

Files and Routines Automatically Generated by the MCC

After generating the program source from MCC interface by clicking Generate Code, the peripheral libraries (PLIBs) configuration can be found in the following project directories
Figure 4-110. Project File Structure
The sercom initialization routine executed during program initialization can be found in the project files. This initialization routine is automatically generated by the MCC according to the user settings
Figure 4-111. 

Header Files

  • Header File associated with the sercom0 peripheral library or any other peripheral library for a different example is included in definitions.h file
    Note: To use all the SERCOM0 functionality include the definitions.h file in application code

Function Calls

MCC generates and adds the code to initialize the UART peripheral in SYS_Initialize() function
  • SERCOM0_USART_Initialize() is the API that will be called inside the SYS_Initialize() function

User Application Development

  1. Include

    • definitions.h in app.c (definitions.h is called to include the peripheral.h files)

    • app_idle_task.h in app.c

  2. Transfer data using USART in app.c
    #include "peripheral/sercom/usart/plib_sercom0_usart.h"
  3. In APP_Tasks(), case APP_STATE_INIT:
    SERCOM0_USART_Write((uint8_t *)"Hello World\r\n",13);