Getting Started with MPLAB® Harmony v3 Peripheral Libraries on SAM E70/S70/V70/V71 MCUs

Last modified by Microchip on 2024/06/24 06:31

Objective

MPLAB® Harmony v3 is a flexible, fully integrated embedded software development framework for 32-bit microcontrollers (MCUs) and microprocessors (MPUs).

MPLAB Harmony v3 includes the MPLAB Code Configurator (MCC) tool, a set of modular, device, and middleware libraries, and numerous example applications, all of which are designed to help you quickly and easily develop powerful and efficient embedded software for Microchip’s 32-bit PIC® and SAM devices.

This tutorial shows you how to use MCC to create an application that gets you started in developing applications on SAM E70/S70/V70/V71 MCUs using the MPLAB Harmony v3 software framework.

The application makes use of SAM E70 Xplained Ultra Evaluation Kit and I/O1 Xplained Pro Extension Kit (sold separately).

The application reads the current room temperature from the temperature sensor on the I/O1 Xplained Pro Extension. The temperature read is displayed on a serial console periodically every 500 milliseconds. The periodicity of the temperature values displayed on the serial console is changed to one second, two seconds, four seconds, and back to 500 milliseconds every time you press the switch SW0 on the SAM E70 Xplained Ultra Evaluation Kit. Also, an LED, LED3, is toggled every time the temperature is displayed on the serial console.

The application you create will utilize:

  • Two-Wire Interfaces (TWIHS) (I²C) Peripheral Library to read the temperature from a temperature sensor
  • Timer Counter (TC) Peripheral Library to periodically sample temperature sensor data
  • Universal Synchronous Asynchronous Receiver Transmitter (USART) and Direct Memory Access (DMA) Peripheral Libraries to print the temperature values on a COM (serial) port terminal application running on a PC
  • PORTS Peripheral Library to change the periodicity of temperature sensor data read using SWITCH event and toggle the LED

In the process, the lab will also demonstrate the use of callback functions.

There are two ways to use this tutorial:

  1. Create the project from scratch:
    • Use the provided source files and step-by-step instructions below.
  2. Use the solution project as an example:
    • Build the solution project and download it to the SAM E70 Xplained Ultra Evaluation Kit Board to observe the expected behavior.

Back to top

Lab Objectives

  1. Create an MPLAB® Harmony v3 project for a SAM E70 microcontroller from scratch.
  2. Use MCC to configure and generate MPLAB® Harmony v3 Peripheral Libraries code for TC, I²C, USART, DMA, and PORTS peripherals.
  3. Use the MPLAB® Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement the application.

Back to top

Resources

The Xplained Pro series evaluation kits include an onboard Embedded Debugger (EDBG). No external tools are necessary to program or debug the ATSAME70Q21B. For programming/debugging, the EDBG connects to the host PC through the USB Micro-B connector on the SAM E70 Xplained Ultra Evaluation Kit.

Hardware setup

Back to top

Hardware Connection Setup

Apart from the hardware tools listed above, the following items are required:

  • USB Type-A male to Micro-B male cable for programming/debugging.

Back to top

Software Tools

This project has been verified to work with the following versions of software tools:

  • MPLAB X IDE v6.10,
  • MPLAB XC32 Compiler v4.30, and
  • MPLAB Code Configurator v5.3.7

Because we regularly update our tools, occasionally you may discover an issue while using the newer versions. If you suspect that to be the case, we recommend that you double-check and use the same versions that the project was tested with.

Back to top

Software Tools

For this lab, download the following repositories from GitHub:

Back to top

Overview

This lab shows you how to create an MPLAB Harmony v3 project from scratch, to configure and generate MPLAB Harmony v3 Peripheral Libraries code for TC, I²C, USART, DMA, and PORTS peripherals. It demonstrates the reading of temperature sensor values from the temperature sensor available on the I/O1 Xplained Pro Extension kit periodically and displays it on a serial console. The periodicity of temperature sampling is changed for every switch press event. Every time the temperature is displayed on the serial console, an LED is toggled.

The application initializes the clock, PORTs, and other peripherals (configured through MCC) by calling the function SYS_Initialize.
The application registers callback event handlers for TWIHS (I²C), DMA, TC, and Parallel Input/Output (PIO) Peripheral Libraries. The callback event handlers are called back by the peripheral libraries when the transaction completion events occur.

Application Flow Sequence

A callback event handler for USART is not registered as the actual USART data transfer, this is accomplished by the DMA. The DMA calls back the callback event handler when the DMA transfer request is completed.

The application checks whether the configured TC timer period has expired. On every timer period expiry, the application calls the function TWIHS0_WriteRead to submit a temperature sensor read request to the I²C peripheral library. The I²C peripheral library calls back the registered callback event handler when the latest temperature value is read from the sensor. The application sets a flag in the TC callback event handler.

The application checks the temperature read complete flag to submit a write request to DMA to print the latest temperature value (in a formatted message) onto the serial console over the USART interface.

The application also monitors the pressing of the switch SW0; if a switch press is detected, the application changes the temperature sampling rate from the default 500 milliseconds to one second. On subsequent switch press, the application changes the temperature sampling rate to two seconds, four seconds, and back to 500 milliseconds. The application cycles the temperature sampling rate on every switch press, as shown in Figure 1.2.

Temperature Sampling Rate

The application also toggles user LED LED3 every time the latest temperature value is displayed on the serial console.

Back to top

Lab Source Files and Solutions

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the lab as per the following step-by-step instructions (see the "Procedure" section on this page).

The contents of this ZIP file need to be placed in the following folder:

<Any directory of your choice>/training/
(example Directory = C:/microchip/harmony/v5.3.7)

Note:

  1. The project location of an MPLAB Harmony v3 project is independent of the location of the Harmony Framework path (i.e., you need not create or place a Harmony v3 project in a relative path under the Harmony v3 framework folder). The project can be created or placed in any directory of your choice.
  2. The point above is true because when created, an MPLAB Harmony v3 project generates all the referred source/header files and libraries (if any) under the project folder.
  3. Both points above contrast with the MPLAB Harmony v2 project location. In MPLAB Harmony v2, the project was supposed to be created in a location under the Harmony framework.

Back to top

Zip Files

Extracting the ZIP file creates the following folders:

  • same70_getting_started contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
    • dev_files contains subfolder sam_e70_xult containing application source files and other support files (if any) required to perform the lab (see "Procedure" section).
    • firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.

Back to top

Procedure

All steps must be completed before you will be ready to build, download, and run the application.

Lab Index

Step 1: Create project and configure the SAM E70

  • Step 1.1 - Install the MPLAB Code Configurator (MCC) Plug-in in MPLAB X IDE
  • Step 1.2 - Create MPLAB Harmony v3 Project using MPLAB X IDE
  • Step 1.3 - Verify Clock Settings

Step 2: Configure I²C, USART, and TC Peripheral Libraries

  • Step 2.1 - Configure TC Peripheral Library
  • Step 2.2 - Configure I²C Peripheral Library and I²C pins
  • Step 2.3 - Configure USART Peripheral Library and USART pins
  • Step 2.4 - Configure DMA Peripheral Library

Step 3: Configure Pins for Switch and LED

  • Step 3.1 - Configure switch button pin with PIO to generate an interrupt
  • Step 3.2 - Configure LED Pin
  • Step 3.3 - Rename the default main file

Step 4: Generate Code
Step 5: Add application code to the project
Step 6: Build, program, and observe the outputs

Back to top