Harmony v3 Peripheral Libraries on PIC32MX 470: Step 2

Step 2.1: Configure TMR2 Peripheral Library

1

Click on the Available Components tab in the left pane of the MPLAB® Harmony Configurator (MHC) window. Expand Peripherals > TMR.
Double click or drag and drop TMR2 and TMR3 to add the Timer2 and Timer3 Peripheral Libraries (PLIBs) to the project.

tmr2_adding.png

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.

2

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.

tmr2_configuration_setup.png

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

tmr3_configuration_setup.png

3

Verify that the PBCLK is set to 48 MHz.

tmr2_clock_setup.png

Step 2.2: Configure CORE TIMER Peripheral Library

1

Under the Available Components tab, expand Peripherals > CORE TIMER.
Double click on CORE TIMER to add the CORE TIMER PLIB to the project.

coretimer_adding.png

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.

2

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

coretimer_configuration_setup.png

Step 2.3: Configure I²C PLIB and I²C Pins

1

Under the Available Components tab, expand Peripherals > I²C.

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

i2c_selection.png

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

i2c_setup.png

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

2

Open the Pin Configuration tabs by clicking Tools > Pin Configuration.

open_pin_configuration.png

3

Now, select the MHC 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)
i2c_pins_setup_3.png
i2c_pins_setup_2.png
  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.
isolation_step.png

Step 2.4: Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART Pins

1

Under the tab Available Components tab, expand Peripherals > UART.

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

uart_selection.png

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

uart_setup.png

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.

2

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

Enable UART_TX (U2TX) on RE5 (Pin #1).

uart_pins_setup_1.png
uart_pins_setup.png

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

1

Open the DMA Configurator tab by clicking Tools > DMA Configuration.

open_dma_configuration.png

2

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_dma_setup.png

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 >

© 2020 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.