Rapid prototyping with 32-bit MCU-based Curiosity Nano Evaluation Kit using MPLAB® Harmony v3 Software Framework

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

Warning: This tutorial uses the old Harmony configuration tool (MPLAB® Harmony Configurator (MHC)). New Harmony projects should use the MPLAB Code Configurator (MCC) instead.

 

Objective

This tutorial shows you how to develop an application prototype from a concept without designing a Printed Circuit Board (PCB) using 32-bit MCU-based Curiosity Nano Evaluation Kits and Nano baseboard.

The problem statement you would address is implementing a smart appliance control application on the PIC32CM MC00 Curiosity Nano Evaluation Kit using MPLAB® Harmony v3 software framework.

The application makes use of the PIC32CM MC00 Curiosity Nano Evaluation Kit, the BM71-XPRO Bluetooth® Low energy board, and the following MikroElektronika Click boards™: Weather CLICKFan ClickeINK Click Bundle.

The application is developed on the MPLAB Harmony v3 software framework. MPLAB Harmony v3 is a modular framework that provides interoperable firmware libraries for application development on 32-bit MCUs and MPUs. It includes an easy-to-use Graphical User Interface (GUI) (MPLAB Harmony Configurator (MHC)) for selecting, configuring, and generating starter codes, peripheral libraries, and middleware (USB, TCP/IP, Graphics, and so on).

This application demonstrates smart control of an appliance (fan) through an Android-based smartphone over a Bluetooth Low Energy (BLE) connection.

The application enables BLE transfers by connecting the BM71 XPRO to the Microchip Bluetooth Data (MBD) Android smartphone application. The BM71 XPRO uses a transparent service for data exchange with the Android MBD mobile application. The BM71 XPRO interfaces to the MCU over SERCOM - USART interface.

The fan connected to Fan Click via the Inter-Integrated Circuit (I²C) interface is controlled based on the mobile application's commands. The application supports two types of commands received over BLE.

  1. Environment temperature-based Fan Control mode command
    • When the application receives a command TEMP_CTRL from the Android smartphone, the fan is run based on the environmental temperature. The application reads the temperature values from a weather sensor and displays them on the eINK display and controls a DC fan as mentioned below.
      • The fan rotates at LOW speed at a temperature between 18 (64°F) to 25 (77°F) degrees Celsius
      • The fan rotates at MEDIUM speed at a temperature between 26 (78°F) to 30 (86°F) degrees Celsius
      • Temperature is greater than 30 degrees Celsius (86°F), the fan rotates at HIGH speed
      • Temperature is less than 18 (64°F), the fan is switched OFF
  2. Fan operation control based on the commands received from the Android smartphone.
    • You can control the fan by sending specific commands to the MBD app running on the connected smartphone
      • BLE_CTRL: FAN_ON - Turns the fan "On" and runs at LOW speed
      • BLE_CTRL: FAN_OFF - Turns "Off" the fan
      • BLE_CTRL: FAN_LOW - Runs the fan at LOW speed
      • BLE_CTRL: FAN_MID - Runs the fan at MEDIUM speed
      • BLE_CTRL: FAN_HIGH - Runs the fan at HIGH speed

The application you create will utilize the following peripherals:

  • SERCOM0 (as I²C) peripheral library to read the temperature from the Weather Click sensor and control the speed of the 5 V DC fan using the Fan Click
  • SERCOM1 (as SPI) peripheral library to display the temperature and fan speed status on the eINK display
  • SERCOM3 (as Universal Synchronous Asynchronous Receiver Transmitter (USART)) peripheral library to communicate with the BM71-XPRO using the BM71 Driver
  • SysTick and Timer (TC0) peripheral libraries are used for MikroElektronika board and BM71 driver timing requirements

There are Two Approaches to 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 PIC32CM MC00 Curiosity Nano Evaluation Kit to observe the expected behavior

Lab Objectives

  1. Create an MPLAB X IDE Harmony v3 project for a PIC32CM MC00 MCU from scratch.

  2. Use MHC to configure and generate Harmony v3 Peripheral Library code for SysTick, I²C, USART, SPI, TC0, and PORT peripherals.
  3. Use MHC to configure and generate Harmony v3 BM71 driver, and Timer System Service libraries.
  4. Use MikroElektronika Click routines to add MikroElektronika Click board functionality to the application.
  5. Use the Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement and demonstrate a low-power application.

Materials

Hardware Tools

The PIC32CM MC00 Curiosity Nano Evaluation Kit contains an on-board debugger for programming and debugging. No external tools are necessary to program or debug the PIC32CM MC00. For programming or debugging, the EDBG connects to the host PC through the USB micro-B connector on the PIC32CM MC00 Curiosity Nano Evaluation Kit.

Software Tools

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

Note: 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.

For this lab, download the following repositories from GitHub:

  • CSP: The following table shows the summary of contents
FolderDescription
appsExample applications for CSP library components
archInitialization and starter code templates and data
docsCSP library help documentation
peripheralPeripheral library templates and configuration data
  • DEV_PACKS: The following table shows the summary of contents
FolderDescription
MicrochipPeripheral register specific definitions
armCore Specific Register Definitions (CMSIS)
  • MHC: The following table shows the summary of contents
File/FolderDescription
docHelp documentation and licenses for libraries used
np_templatesNew Project templates for supported toolchains
*.jarJava implementations of MHC modules
mhc.jarMain Java executable (run: java -jar mhc.jar -h)
runmhc.batWindows cmd batch file to run standalone MHC Graphical User Interface (GUI)
  • bt: The following table shows the summary of contents
FolderDescription
appsExample applications for Bluetooth library components
docsBluetooth module library help documentation
driverBluetooth module peripheral device drivers
templatesApplication and system file templates

Overview

This lab shows you how to create an MPLAB Harmony v3 project from scratch. You will configure and generate Harmony v3 peripheral library code for the SysTick, I²C, USART, SPI, BM71 driver, Timer System Services, TC0, and PORT peripherals.

Application flow sequence

The application flow is as follows:

  1. The application initializes the Fan Click board routines, eINK Click board routines, and sets the default state of the fan to OFF.
  2. The application initializes the BLE and runs the BLE Tasks.
  3. The application checks whether the fan control command from the BLE-based Android smartphone app is:
    • Temperature-based control or
    • BLE-based control
  4. If the command is temperature-based control, the application flow is as below:
    • Through the I²C interface, reads the room temperature from the PTH sensor on the Weather Click
    • Checks the room temperature reading against the requirement and, through the I²C interface, controls the state and speed of the fan connected to the Fan Click board and displays the temperature and fan speed on the eINK display
  5. If the command is BLE-based control, the application sets the fan operation (SPEED, ON/OFF) based on the command received and displays the fan speed on eINK display.
  6. The process is repeated to monitor the room temperature and control the fan operation continuously.

Connection diagram for lab

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 by following the step-by-step instructions (see the "Procedure" section on this page).

The contents of this ZIP file need to be placed in a folder of your choice.

Note:

  • The project location of a 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. This is true because when created, a Harmony v3 project generates all the referred source and header files and libraries (if any) under the project folder
  • The point above contrasts with the Harmony v2 project location. In Harmony v2, the project was supposed to be created in a location under the Harmony framework

ZIP

Extracting the ZIP file creates the following folders:

  • pic32cmmc_smart_appliance_control contains the lab solution (in the firmware folder) and source files (in the dev_files folder)
    • dev_files contains subfolder pic32cm_mc00_cnano which contains 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

Hardware Configuration and Connections

The BM71 XPRO needs to be upgraded with firmware having private characteristics and configured to run in Manual mode. The steps to do the same are mentioned below.

Adding private characteristics to BM71:

Hardware Setup

  • In BM71-XPRO, change jumper J2 to select USB

  • In BM71-XPRO, configure DIP switch SW2 with the below configurations
    • All DIP switch ON
  • Power the BM71-XPRO from a Host PC through a Type-A male to Micro-B USB cable connected to Micro-B port (J1)
  • Perform reset by pressing switch SW1 on the BM71-XPRO and check blue LD1 is ON

Hardware setup for lab

Programming private characteristics

  • Download the manual configuration tool from BM70/71 Firmware & Software Tools v1.11
  • Extract and locate configuration tool from the below location
    • Your_downloaded_folder \Firmware & Software Tools v1.11\ConfigurationTool\IS187x_102_BLEDK3v1.11_UI1.00
  • Double click on IS187x_102_BLEDK3v1.11_UI1.00.exe
  • Click on Load button and select Load Text File

Loading version and device

Load text file

  • Select IS1871SF_102_BLEDK3v1.11_UI v1.00(BM71)_default.txt from your_downloaded_folder\Firmware & Software Tools v1.11\ConfigurationTool\IS187x_102_BLEDK3v1.11_UI1.00

Select text file

  • Click on the EDIT option

Edit features

  • Select 0x01: BM71 in BLEDK and click OK

Select BM71

  • Update the Operation Mode Setting from Auto Pattern to Manual Pattern

Change Operation Mode Setting to Manual Pattern

  • Confirm OK to disable the "Flow Control and LE Connection Parameter Update Request"

Disable Flow Control and LE Connection Parameter Update Request

  • Click on Finish

Click Finish

  • Click on Write

Click on write

  • Select the respective COM Port and set Baudrate to 115200 then click on Write

Set the COM Port and change Baud rate to 115200

  • Click on Yes to successfully update the private characteristics on to BM71 module

Click yes to update characteristics

  • After successful update, click OK and remove the power from BM71-XPRO and change jumper J2 to select EXT

Remove power from BM71-XPRO and change Jumper J2 to select EXT

  • Turn OFF DIP 1 switch

Hardware Connection Setup

  • Mount the PIC32CM MC00 Curiosity Nano Evaluation Kit on the CNANO56_HOST_CONN(U3) connector of the Curiosity Nano Baseboard
  • Connect the BM71-XPRO onto the EXT 1 connector of the Curiosity Nano Baseboard
  • Mount the eINK Click bundle (eINK Click + eINK display) on the mikroBUS 1 connector of the Curiosity Nano Baseboard
  • Mount Fan Click board on the mikroBUS click 2 connector of the Curiosity Nano Base and connect 4 fan wires to the fan Click
  • Mount the Weather Click board on the mikroBUS click 3 connector of Curiosity Nano Base
  • Connect Li-ion or Lipo Battery on J1 connector and make sure SW1 slider switch is moved to the battery on the position in Curiosity Nano Baseboard
  • Connect the PIC32CM MC00 Curiosity Nano Evaluation Kit to the Host PC as a USB Device through a Type-A male to micro-B USB cable connected to Micro-B USB (Debug USB) port

Hardware set up example

Procedure

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

Lab Index

Step 1: Create Project and Configure the PIC32CM MC00

  • Step 1.1 - Verify Whether MHC Plug-in is Installed in MPLAB X IDE
  • Step 1.2 - Set Up MHC Plugin Window to Open in Standalone Mode
  • Step 1.3 - Create MPLAB Harmony v3 Project Using MPLAB X IDE
  • Step 1.4 - Configure Clock Settings

Step 2: Configure I²C Peripheral Library

  • Step 2.1 - Configure I²C Peripheral Library and I²C Pins

Step 3: Configure SPI and SysTick Peripheral Library

  • Step 3.1 - Configure SPI Peripheral Library and SPI Pins
  • Step 3.2 - Configure SysTick Peripheral Library

Step 4: Configure UART Peripheral Library and Asscoiate BM71 driver

  • Step 4.1 - Configure UART Peripheral Library and UART pins
  • Step 4.2 - Associate BM71 Driver
  • Step 4.3 - Configure Timer and Harmony Core Services

Step 5: Generate Code

Step 6: Add MikroElektronika routine Code to the Project

  • Step 6.1 - Add Weather click board routine
  • Step 6.2 - Add Fan click board routine
  • Step 6.3 - Add EINK click board routine
  • Step 6.4 - Add BLE source files
  • Step 6.5 - Map generic Macros of click routines

Step 7: Add Application Code to the Project

Step 8: Build, Program, and Observe the Outputs