MPLAB® Harmony v3 Peripheral Libraries on PIC32MZ EF: Step 2
Configure I2C, UART, and TMR1 Peripheral Libraries
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.
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.
Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.
Select the 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).
Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART pins
Under the 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.
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).
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.
Configure Cache Maintenance
Under the Project Graph tab, click on System, and enable Use Cache Maintenance.