Harmony v3 Peripheral Libraries on PIC32MX 470: Step 2

Step 2.1: 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.


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.


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



Verify that the PBCLK is set to 48 MHz.


Step 2.2: 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.


Core timer is configured to use CORE TIMER PLIB. The CORE TIMER PLIB provides blocking timer delay Application Programming Interface (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.


Step 2.3: 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.


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


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.



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

  • Enable I²C Clock (SCL1) on Pin #43
  • Enable I²C Data (SDA1) on Pin #44
  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.

Step 2.4: 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.


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


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.


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.

Step 2.5: Configure DMA PLIB


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



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.

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.

Next Step >

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.