MPLAB® Harmony v3 Peripheral Libraries on PIC32MX 470: Step 2

Last modified by Microchip on 2023/11/09 09:09

Configure TMR2 Peripheral Library

Click on the Resource Management [MCC] tab. In the Device Resources, expand Peripherals > TMR.
Double-click or drag and drop TMR2 and TMR3 to add the Timer2 and Timer3 Peripheral Libraries (PLIBs) to the project.

Timer2 adding

In PIC32MX470, by default, TMR2 is configured as a 16-bit timer and is sourced by a 48 MHz Peripheral Bus Clock (PBCLK). Using the default TMR2 configuration, the generation of 500 milliseconds, 1 second, 2 seconds, and 4 seconds period is not possible. To generate these time periods, TMR2 needs to be configured as a 32-bit timer.

In the Project Graph window, configure the TMR2 PLIB as a 32-bit timer and set timer period as 500 milliseconds. Once TMR2 PLIB is configured as 32-bit timer, TMR2 and TMR3 work together as a single 32-bit timer.

Project Graph window

In the Project Graph window, verify the TMR3 PLIB is set to generate a compare interrupt on every 500 milliseconds.

Project Graph window

Verify that the PBCLK is set to 48 MHz.

Verify that the PBCLK is set to 48 MHz

Back to Top


Configure CORE TIMER Peripheral Library

 

Click on the Resource Management [MCC] tab. In the Device Resources, expand Peripherals > CORE TIMER.
Double-click on CORE TIMER to add the CORE TIMER PLIB to the project.

Available Components tab

Core timer is configured to use CORE TIMER PLIB. The CORE TIMER PLIB provides blocking timer delay APIs. The blocking timer delay APIs are needed for initializing temperature sensor.

In the Project Graph window, use the default CORE TIMER PLIB configuration as shown.

Project Graph window

Back to Top


Configure I²C PLIB and I²C Pins

Click on the Resource Management [MCC] tab. In the Device Resources, expand Peripherals > I²C.

Double-click on I²C1 to add the I²C instance 1 to the project.

Available Components tab

Select the I²C1 Peripheral Library and use the default configuration as shown.

I²C1 Peripheral Library

Retain I²C1 speed as default 50 kHz because the temperature sensor chip on MikroElectronika Weather Click board™ can operate at 50 kHz.

Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.

Tools > Pin Configuration

Now, select the MCC Pin Table tab and then scroll down to the I²C1 module as shown below.

  • Enable I²C Clock (SDA1) on RD9 (Pin #43)
  • Enable I²C Data (SCL1) on RD10 (Pin #44)

Pin Table tab

Pin Table tab

  1. This completes the configuration of the I²C PLIB. The application code will use the I²C PLIB Application Programming Interfaces (APIs) to read temperature from the temperature sensor.
  2. In the Pin Table, you can isolate any peripheral or any pin from other peripherals or other pins by right-clicking and choosing that specific peripheral or that specific pin.

Pin Table

Back to Top


Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART Pins

Click on the Resource Management [MCC] tab. In the Device Resources, expand Peripherals > UART.

Double-click on UART2 to add UART instance 2 to the project.

Available Components tab

Select the UART2 Peripheral Library and configure it as shown below.

UART2 Peripheral Library

Verify the default baud rate is set to 115200 Hz.

UART interrupt is disabled because Direct Memory Access (DMA) will be used (configured in future steps) to transfer application buffer to the UART TX register.

Select the Pin Table tab and then scroll down to the UART2 module as shown below.

Enable UART_TX (U2TX) on Pin #1.

Pin Table tab

Pin Table tab

The application will use the UART PLIB for printing messages on the serial terminal. Hence, in the UART2 configuration, only the transmit pin is configured and the receive pin is not configured.

Back to Top


Configure DMA PLIB

Open the DMA Configurator tab by clicking Project Graph > Plugins> DMA Configuration.

DMA Configurator tab

In the DMA Settings window, enable and configure Direct Memory Access (DMA) Channel 0 to transfer application buffer to the UART TX register as shown below. The DMA transfers one byte from the user buffer to UART transmit buffer on each trigger.

  • The Priority drop-down option for a channel helps give priority to a DMA channel over the other when more than one DMA channel is configured by the application. Since in this application only one DMA channel is configured, the default priority (zero or CHPRI0) is not changed.

DMA Settings window

UART transmit buffer empty event triggers for the DMA to transfer one byte of data from source (user buffer) to destination (UART Tx register). When all the requested bytes are transmitted, the DMA PLIB notifies the application by calling the registered DMA callback event handler.

Back to Top