Step 2.1: Configure TMR1 Peripheral Library
2
Set TMR1 to run at 32,768 Hz low-speed clock.
- When a module is added to the project graph, the MPLAB® Harmony Configurator (MHC) automatically enables the clock to the module. The default TMR1 clock source is the internal peripheral 100 MHz clock (PBCLK3), shown below 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 below 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.
3
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
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.
Select the I²C1 Peripheral Library and use the default configuration as shown below.
Note: Retain I²C1 speed as default 50,000 Hz because the temperature sensor chip on I/O1 Xplained Pro Extension Kit can operate at 50,000 Hz.
3
Select the MHC Pin Table tab and then scroll down to the I²C1 module as shown below.
- 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
1
Under the tab Available Components tab, expand 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 below.
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 application buffer to the UART TX register.
2
Select the Pin Table tab and then scroll down to the UART6 module as shown below.
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
2
Click on the DMA Settings tab. Enable and configure DMA Channel 0 to transfer the application buffer to the UART TX register as shown below. 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.