Getting Started with MPLAB® Harmony v3 Peripheral Libraries on PIC32MK GP MCUs: Step 2
Configure TMR2 Peripheral Library
Click on the Device Resources tab in the left pane in the MPLAB® Code Configurator (MCC) window. Expand Harmony > Peripherals > TMR > TMR2.
Double click or drag and drop TMR2 to add the Timer2 Peripheral Library (PLIB) to the project graph.
In the project graph, configure the TMR2 PLIB as a 32-bit timer and set the timer period as 500 milliseconds.
Verify that PBCLK2 is set to 60 MHz.
Configure CORE TIMER Peripheral Library
Under the Device Resources tab, expand Harmony > Peripherals > CORE TIMER
Double click on CORE TIMER to add the CORE TIMER PLIB to the project graph.
In the project graph, use the default CORE TIMER PLIB configuration as shown.
Configure SPI PLIB and SPI Pins
Under the Device Resources tab, expand Harmony > Peripherals > SPI >SPI6
Double click on SPI6 to add the SPI instance 6 to the project.
Select the SPI6 Peripheral Library and disable the Master Mode Slave Select Enable bit, as shown.
Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration
In MPLAB Code Configurator (MCC), select the Pin Settings tab and sort the entries by Ports as shown.
Now, select the MCC Pin Table tab and then scroll down to the SPI6 module as shown.
- Enable SPI Clock (SCK6) on Pin #23 (RA1)
- Enable SPI MISO (SD06) on Pin #24 (RB0)
- Enable SPI MOSI (SDI6) on Pin #14 (RG9)
Click the Pin Settings tab and then scroll down to the GPIO pin RC0 (Pin Number 32) in the Pin ID column and configure RC0 as an output pin for SENSOR_CS functionality as shown.
Step 2.4: Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART Pins
Under the Device Resources tab, expand Harmony > Peripherals > UART > UART6.
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.
Verify the default baud rate is set to 115200 Hz.
Select the Pin Table tab and then scroll down to the UART6 module as shown.
Enable UART_TX (U6TX) on Pin #51 (RA4).
Step 2.5: Configure DMA PLIB
Open the DMA Configurator tab 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. The DMA transfers 1 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 channels are configured by the application. Since in this application only one DMA channel is configured, the default priority (zero or CHPRI0) is not changed.