Harmony v3 Drivers and Middleware on PIC32MZ EF MCUs Using FreeRTOS: Step 2

Step 2.1: Configure I²C Driver and I²C pins

1

Under the Available Components tab, expand Harmony > Drivers.

  • Select and double click on I2C to add the I²C driver to the project.
i2c_driver_select.png
core_activation.png
freertos_activation.png
i2c_core_freertos.png

Select FreeRTOS and view the Configuration Options on the right. Depending on the requirements of the application, the FreeRTOS default configuration can be changed using the GUI. For this tutorial, you will use the default configuration.

freertos_default.png

Adding FreeRTOS maps all the Operating System Abstraction Layer (OSAL) Application Programming Interface (API) calls used by the Harmony drivers and system services to FreeRTOS APIs.

  • Associate the I²C driver with I²C instance 1 (I²C1) peripheral by right clicking on the red diamond highlighted below.
i2c_driver_instance.png
i2c_driver_project_graph_plib_linked.png
  • Click on Instance 0 under I²C Driver to view the Configuration Options. Change the Number of clients to 2.
i2c_driver_client_changes.png
  • The above configuration allows the same instance of driver to be used by two different clients. The first application client interfaces with the Temperature Sensor thread and the second application client interfaces with the EEPROM thread.
  • The number of clients for each driver instance is automatically set to one. MPLAB® Harmony Configurator (MHC) assumes a minimum of one client for each instance of the driver.
i2c_driver_multiclient.png

If the application had two or more devices that were interfaced through different I²C peripherals, then the driver had to be configured to enable multiple instance support. Multiple instance support is enabled by clicking on the + (plus) sign on the I²C driver block. Every click on the + (plus) sign adds a new instance to the driver. Each instance can be configured separately.

  • Click on I2C to verify the driver is configured in Synchronous mode.
i2c_sync.png
  • Select I2C1 Peripheral Library and notice the default configuration by expanding Hardware Settings.
i2c_plib_conf.png

The I²C retains the default 50 kHz speed because the temperature sensor chip and EEPROM on I/O1 Xplained Pro Extension Kit can operate at 50 kHz I²C speed.

2

In MHC, open the pin configuration tabs by clicking Tools > Pin Configuration.

open_pin_configuration.png

3

Select the MHC Pin Settings tab and sort the entries by Ports as shown below.

i2c_pins_setup_1.png

Now, select the MHC Pin Table tab and then scroll down to the I2C 1 module as shown below.

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

This completes the configuration of the I²C driver. The application code will use the I²C driver APIs to read the temperature from the temperature sensor and store it in EEPROM. The application also retrieves the last five temperature values stored in the EEPROM.

Step 2.2: Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Driver and USART pins

1

Under the Available Components tab, expand Harmony > Drivers.

  • Double click on USART to add the USART Driver to the project.
usart_driver_select.png
usart_driver_project_graph.png
  • Associate the USART Driver with UART instance 6 (UART6) peripheral by right clicking on the red diamond highlighted below.
usart_driver_instance.png
usart_driver_project_graph_plib_linked.png
  • Verify that the USART Driver is configured to run in Synchronous mode by clicking on the USART block as shown below.
usart_sync.png
  • Click on Instance 0 under USART Driver to view the Configuration Options. Change the Number of Clients of the USART Driver Instance from 0 to 3. The User Input thread will use the USART Driver to read the character input on the serial terminal. The Sensor and EEPROM threads will use the USART Driver to print temperature values on the serial terminal.
i2c_driver_instance_changes.png
  • Select the UART6 Peripheral Library in the Project Graph and configure it for UART protocol, including setting the Baud Rate to 115,200 Hz.
usart_plib_conf.png

2

Select the Pin Table tab and then scroll down to the UART6 module as shown below.

Enable USART_TX (U6TX) on RF2 (Pin #79).
Enable USART_RX (U6RX) on RF13 (Pin #57).

usart_pins_setup_1.png
usart_pins_setup_2.png

The application will use the USART Driver for printing messages on the serial terminal and receiving input from the user to retrieve the last five stored values from the EEPROM.


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.