MPLAB® Harmony v3 is now configurable through MPLAB Code Configurator (MCC). Although the instructions in this tutorial are for MPLAB Harmony Configurator (MHC), the flow and experience of creating a project, configuring peripherals, and generating code using MCC are similar. Refer to the following links for specific instructions to use MPLAB Harmony v3 with MCC.
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 MHC tool, a set of modular devices and middleware libraries. Additionally, there are 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 MHC to create an application that gets you started in developing applications on SAM E70/S70/V70/V71 MCUs using MPLAB Harmony v3 software framework.
The application reads the current room temperature from the temperature sensor on the I/O1 Xplained Pro Extension Kit. The temperature reading is displayed on a serial console periodically every second. Further, the application writes the temperature readings to EEPROM. When a character is entered on the console, the last five written temperature values are read from the EEPROM and displayed on the console. 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) Driver to read the temperature from a temperature sensor and store/retrieve to/from EEPROM.
- Timer System Service to periodically sample temperature sensor data.
- Universal Synchronous Asynchronous Receiver Transmitter (USART) Driver (in Direct Memory Access (DMA) mode) to print the temperature values on a COM (serial) port terminal application running on a PC.
- PORTS Peripheral Library to toggle an LED.
In the process, the lab will also demonstrate the use of callback functions.
Two Ways to Use This Tutorial
- Create the project from scratch:
- Use the provided source files and step-by-step instructions below.
- 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.
- Create an MPLAB X IDE Harmony v3 project for a SAM E70 microcontroller from scratch.
- Use MHC to configure and generate Harmony Driver code for I²C and USART peripherals.
- Along with the configuration of drivers for I²C and USART peripherals, use MHC to configure and generate Harmony v3 peripheral libraries for the I²C, USART, DMA, and PORTS peripherals.
- Use MHC to configure and generate the Harmony System Service code for the Timer peripheral.
- Along with the configuration of Timer System Service, use MHC to configure and generate Harmony v3 peripheral libraries for the TC peripheral.
- Use the Harmony v3 Driver, System Service, and Peripheral Library Application Programming Interfaces (APIs) to implement the application.
|Tool|| About|| Purchase|
SAM E70 Xplained Ultra
I/O1 Xplained Pro
The Xplained Pro series evaluation kits include an on-board 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 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.
The application has the temperature sensor and EEPROM connected to the SAM E70 over I²C interface and the console (serial terminal) on a PC connected over USART interface (through USB to USART converter).
IO1 Xplained Pro features Microchip’s AT30TSE758 temperature sensor chip with an 8 kbit serial EEPROM. The temperature sensor has two TWI addresses: one for the temperature sensor and one for the EEPROM. The A2 address line of TWI must be soldered to 0. This is done to modify the address of the EEPROM on the I/O1 Xplained Pro Extension Kit so that it does not conflict with the address of EEPROM on SAM E70 Xplained Evaluation Kit. The modification changes the address of temperature sensor to 0x4B and EEPROM to 0x50. These modified addresses are used in this tutorial.
The hardware modification on the IO1 Xplained Pro is shown in the following figure.
This project has been verified to work with the following versions of software tools:
MPLAB X IDE v5.20, MPLAB XC32 Compiler v2.20, MPLAB Harmony CSP v3.5.0, DEV_PACKS v3.5.0, MHC v3.3.2, CORE v3.5.0
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.
| Windows|| Linux|| Mac OSX|
Integrated Development Environment
For this lab, download the following repositories from GitHub:
- CSP: The following table shows the summary of contents.
|apps||Example applications for CSP library components|
|arch||Initialization and starter code templates and data|
|docs||CSP library help documentation|
|peripheral||PLIB templates and configuration data|
- DEV_PACKS: The following table shows the summary of contents.
|Microchip||Peripheral register specific definitions|
|arm||Core Specific Register Definitions (CMSIS)|
- MHC: The following table shows the summary of contents.
|doc||Help documentation and licenses for libraries used|
|np_templates||New Project templates for supported toolchains|
|*.jar||Java implementations of MHC modules|
|mhc.jar||Main Java executable (run: java -jar mhc.jar -h)|
|runmhc.bat||Windows cmd batch file to run standalone MHC Graphical User Interface (GUI)|
- CORE: The following table shows the summary of contents.
|apps||Example applications for core library components|
|config||Core module configuration scripts|
|docs||Core module library help documentation|
|driver||Core module peripheral device drivers|
|osal||MPLAB Harmony Operating System Abstraction Layer|
|system||MPLAB Harmony system services|
|templates||Application and system file templates|
- Use the MPLAB Harmony 3 Framework Downloader to download the repositories.
This lab shows you how to create an MPLAB Harmony v3 project from scratch, to configure and generate:
- Harmony v3 Peripheral Libraries code for the TC, I²C, USART, DMA, and PORTS peripherals
- Harmony v3 Driver code for the I²C and USART peripherals
- Harmony v3 System Service code for the timer peripheral
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. It further writes the temperature readings to EEPROM. When a character is entered on the console, the last five written temperature values are read from the EEPROM and displayed on the console. Also, an LED is toggled every time the temperature is displayed on the serial console.
The application is divided into two tasks: the Sensor task and the EEPROM task. Each runs its state machines. The Sensor and the EEPROM tasks are called from SYS_Tasks routine which is run in a while (1) loop.
After the initialization of the I²C sensor client and USART driver, the sensor task waits for the one-second periodic timer event. On every one-second periodic timer event, the sensor task submits a temperature sensor read request through the I²C interface. When a temperature sensor read is completed, the application submits a USART write request to transfer the read temperature values to a serial terminal on a PC, at the same time, the sensor task notifies the EEPROM task to store the read temperature value in the EEPROM.
After the initialization of the I²C EEPROM client, the EEPROM task submits a USART read request to receive any user input. Parallelly, for every notification from the sensor task to store the values in the EEPROM, the EEPROM task writes the value to the EEPROM. When user input is received (as a character from the serial terminal on the PC), the EEPROM task submits an I²C request to read the stored (last five) temperature values. When the EEPROM read is completed, the EEPROM task prints the read temperature values on the serial terminal.
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 folder below:
<Any directory of your choice>/training/
(example Directory = C:/microchip/harmony/v3_5_0)
- The project location of a Harmony v3 project is independent of the location of the Harmony Framework path (i.e., you do not need to 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.
- The point above is true because when created, a Harmony v3 project generates all the referred source/header files and libraries (if any) under the project folder.
- Both points above contrast with Harmony v2 project location. In Harmony v2, the project was supposed to be created in a location under the Harmony framework.
- getting_started_drv 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 below).
- firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.
All steps must be completed before you will be ready to build, download, and run the application.
- Step 1.1 - Install the MPLAB Harmony Configurator (MHC) 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.1 - Configure Timer System Service
- Step 2.2 - Configure I²C Driver and I²C Pins
- Step 2.3 - Configure USART Driver and USART Pins
- Step 3.1 - Configure LED Pin
- Step 3.2 - Rename the Default Main File
- Step 3.3 - Configure Application Tasks