Harmony v3 Peripheral Libraries on PIC32MZ EF: Step 2

Step 2.1: Configure TMR1 Peripheral Library


Under the Device Resources tab, expand Harmony > Peripherals > TMR1.
Double click or drag and drop TMR1 to add the Timer1 Peripheral Library (PLIB) to the project graph.



Set TMR1 to run at 32,768 Hz low-speed clock.

  • When a module is added to the project graph, the MPLAB® Code Configurator (MCC) automatically enables the clock to the module. The default TMR1 clock source is the internal peripheral 100 MHz clock (PBCLK3), shown in the accompanying image in green highlight.
  • On the PIC32MZEF device, TMR1 can be clocked through several clock sources with frequencies ranging from 32,768 Hz to 200 MHz. TMR1 can be sourced through a low-speed clock using the secondary oscillator. Configure the secondary oscillator as shown in the accompanying image in red highlight.
  • Go back to the project graph and select timer clock source as 32,768 Hz low-speed clock source through External clock from T1CKI pin.


Configure the TMR1 PLIB to generate a compare interrupt every 500 milliseconds.

  • The 32,768 Hz low-speed Timer1 Clock Frequency is sufficient to generate periods of 500 milliseconds and 1 second, but it is not sufficient to generate periods of 2 seconds and 4 seconds.
  • To generate periods of 2 seconds and 4 seconds, it needs further low-speed Timer1 Clock Frequency. This can be achieved using the TMR1 Prescaler. Configure TMR1 > Select Prescaler to 1:8 prescale value. This will generate periods of 2 seconds and 4 seconds at run time. Also, configure the Timer Period (Milli Sec) to 500.

Note: Ensure that the Enable Interrupts? option is checked.

Step 2.2: Configure I²C Peripheral Library and I²C pins


Under the Device Resources tab, expand Harmony > 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 in the accompanying image.


Note: Retain I²C1 speed as default 50,000 Hz because the temperature sensor chip on the I/O1 Xplained Pro Extension Kit can operate at 50,000 Hz.


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



Select the Plugins > Pin Table tab and then scroll down to the I²C1 module as shown in the accompanying image.

  • Enable I²C Clock (SCL1) on RA14 (Pin #95).
  • Enable I²C Data (SDA1) on RA15 (Pin #96).

Note: This completes the configuration of the I²C PLIB. The application code will use the I²C PLIB Application Peripheral Interfaces (APIs) to read temperature from the temperature sensor.

Step 2.3: Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART pins


Under the tab Device Resources tab, expand Harmony > Peripheral > UART.

Double click on UART6 to add the UART instance 6 to the project.


Select the UART6 Peripheral Library in the Project Graph and configure it as shown in the accompanying image.


Verify that the default baud rate is set to 115,200 Hz.

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


Select the Pin Table tab and then scroll down to the UART6 module as shown in the accompanying image.

Enable UART_TX (U6TX) on RF2 (Pin #79).


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

Step 2.4: Configure DMA Peripheral Library


Launch DMA Configurator by going to the Project Graph tab in MPLAB X IDE and then selecting Plugins > DMA Configuration.



Click on the DMA Settings tab. Enable and configure DMA Channel 0 to transfer the application buffer to the UART TX register as shown in the accompanying image. The DMA transfers one byte from the user buffer to the 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.

Note: UART transmit buffer empty event triggers the DMA to transfer one byte of data from the source (user buffer) to the 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.

Step 2.5: Configure Cache Maintenance

Under the Project Graph tab, click on System, and enable Use Cache Maintenance.


Note: The above configuration is enabled to generate the cache maintenance API. The cache maintenance APIs are used in this application to address the cache coherency issues observed in transferring the temperature values to the serial terminal using DMA.

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.