MPLAB® Harmony v3 Drivers on SAM E70/S70/V70/V71 Using FreeRTOS™: Step 2

Last modified by Microchip on 2023/11/09 09:09

Configure I²C Driver and I²C Pins

Under the Device Resources tab, expand Harmony > Drivers > I²C.​​

  • Select and double-click on I²C to add the I²C driver to the project.

Resource Management tab

Confirm Component Auto-Activation dialog box

Confirm Component Auto-Activation dialog box

Project Graph tab

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.

Configuration Options pane

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

  • Associate I²C driver with I²C instance 0 (TWIHS0) peripheral by right-clicking on the red diamond.

Satisfiers TWIHS0

Project Graph I2C Instance 0 TWIHS0

  • Click on Instance 0 under I²C Driver to view the Configuration Options. Change the Number of Clients to 2.

I2C Number of Clients

  • 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® Code Configurator (MCC) assumes a minimum of one client for each instance of the driver.

I2C driver diagram

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 + sign on the I²C driver block. Every click on the + sign adds a new instance to the driver. Each instance can be configured separately.

  • Click on I²C to verify the driver is configured in Synchronous mode.

Synchronous

  • Select TWIHS0 Peripheral Library and notice the default configuration by expanding Hardware Settings.

TWIHS0 Hardware Settings

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

Open the Pin Configuration tabs by clicking Project Graph > Plugins > Pin Configuration.

Tools > Pin Configuration

Select the Pin Settings tab and sort the entries by Ports.

Now, select the Pin Table tab and then scroll down to the TWIHS0 module.

  • Enable I²C Clock (TWIHS0_TWCK0) on PA04 (Pin #77).
  • Enable I²C Data (TWIHS0_TWD0) on PA03 (Pin #91).

Enable I²C Clock and I²C Data

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 last five temperature values stored in the EEPROM.

Back to Top


Configure Universal Synchronous Asynchronous Receiver Transmitter (USART) Driver and USART Pins

Under the Device Resources tab, expand Harmony > Drivers > SQI Flash > USART.​​​​​

Double click on USART to add the Universal Synchronous Asynchronous Receiver Transmitter (USART) driver to the project.

Double click on USART to add the Universal Synchronous Asynchronous Receiver Transmitter (USART) driver to the project

INstance 0 DRV_USART

Project Graph tab

  • Associate USART Driver with USART instance 1 (USART1) peripheral by right-clicking on the red diamond.

Satisfiers USART1

USART1 Periphrtsl Library UART connecyed to INstance 0

  • Verify USART driver is configured to run in Synchronous mode by clicking on the USART block.

Driver Mode

  • Click on Instance 0 under USART Driver to view the Configuration Options. Change the number of clients to the USART driver Instance 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.

Number of Clients

  • Select the USART1 Peripheral Library in the Project Graph and configure it for USART protocol, including setting the baud rate to 115200 Hz.

Instance 0 USART1 Peripheral Library UART

Select the Pin Table tab and then scroll down to the USART1 module.

  • Enable USART_TX (USART1_TXD1) on PB04 (Pin #105).
  • Enable USART_RX (USART1_RXD1) on PA21 (Pin #32).

Pin Table tab

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.

Back to Top