MPLAB® Harmony v3 Drivers on SAM C21 Using FreeRTOS: Step 2

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

Configure I²C Driver and I²C Pins

Under the Available Components tab, expand Harmony > Drivers.

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

Expand harmony and then drivers

Activate core (harmonycore)

Activate freeRTOS

The project graph is displayed

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.

View the Configuration Options

Information

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 I²C driver with I²C instance 0 (SERCOM2) peripheral by right clicking on the red diamond.

Associate I²C driver with I²C instance 0 (SERCOM2) peripheral

SERCOM2 and I2C are associated

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

View the Configuration Options

Information
  • 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.

Multiclient diagram

Information

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.

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

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

Select SERCOM2 Peripheral Library and notice the default configuration by expanding Hardware Settings

Information
  • The SERCOM2 (as I²C) retains the default 100 kHz speed because the temperature sensor chip on the I/O1 Xplained Pro Extension Kit can operate at 100 kHz I²C speed.
  • The SERCOM2 (as I²C) retains the default 50-100 nanoseconds hold time for Serial Data (SDA) Hold Time because it aligns with the minimum (50 nanoseconds) start hold time stated in the specification of the temperature sensor chip (AT30TSE758).
  • The SERCOM2 (as I²C) retains the default 100 nanoseconds for I²C Trise time because it aligns with the maximum (300 nanoseconds) input rise time stated in the specification of the temperature sensor chip (AT30TSE758).

Open the Pin Configuration tabs by clicking Standalone Window > Tools > Pin Configuration.

Open the Pin Configuration

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

Sort the entries by Ports

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

  • Enable I²C Data (SDA)(SERCOM2_PAD0) on PA12 (Pin #29)
  • Enable I²C Clock (SCL)(SERCOM2_PAD1) on PA13 (Pin #30)

Configure pins 29 and 30

Information

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.

Back to Top


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

Under the Available Components tab, expand Harmony > Drivers.

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

Expand Harmony and then Drivers

The USART driver project graph is displayed

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

Associate USART Driver with USART instance (SERCOM4) peripheral by right clicking on the red diamond

USART Driver and  USART instance (SERCOM4) peripheral are associated

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

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

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

Click on Instance 0 under USART Driver to view the Configuration Options

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

Select the SERCOM4 Peripheral Library in the Project Graph and configure it

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

  • Enable USART_TX on PB10 (Pin #23)
  • Enable USART_RX on PB11 (pin #24)

Configure pins 23 and 24

Information

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