Step 2.1: Configure TMR2 Peripheral Library
1
Click on the Resource Management[MCC] tab. In the Device Resources, expand Peripherals > TMR.
Double-click or drag and drop TMR2 and TMR3 to add the Timer2 and Timer3 Peripheral Libraries (PLIBs) to the project.
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.
In the Project Graph window, verify the TMR3 PLIB is set to generate a compare interrupt on every 500 milliseconds.
Step 2.2: Configure CORE TIMER Peripheral Library
1
Click on the Resource Management[MCC] tab. In the Device Resources, expand Peripherals > CORE TIMER.
Double-click on CORE TIMER to add the CORE TIMER PLIB to the project.
Core timer is configured to use CORE TIMER PLIB. The CORE TIMER PLIB provides blocking timer delay Application Programming Interface (APIs). The blocking timer delay APIs are needed for initializing temperature sensor.
Step 2.3: Configure I²C PLIB and I²C Pins
1
Click on the Resource Management[MCC] tab. In the Device Resources, 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.
Retain I²C1 speed as default 50 kHz because the temperature sensor chip on MikroElectronika Weather Click board™ can operate at 50 kHz.
3
Now, select the MCC Pin Table tab and then scroll down to the I²C1 module as shown below.
- Enable I²C Clock (SCL1) on Pin #43
- Enable I²C Data (SDA1) on Pin #44
- 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.
- 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.
Step 2.4: Configure Universal Asynchronous Receiver Transmitter (UART) PLIB and UART Pins
1
Click on the Resource Management[MCC] tab, In the Device Resources, expand Peripherals > UART.
Double-click on UART2 to add UART instance 2 to the project.
Select the UART2 Peripheral Library and configure it as shown below.
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 Pin #1.
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
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 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.