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

 Objective

This tutorial shows you how to develop an application prototype from a concept without designing a 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 CLICK, Fan Click, EINK 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 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 for 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

Tool About Purchase
board-50px.png
PIC32CM MC00 CURIOSITY NANO
EVALUATION KIT
board-50px.png
CURIOSITY NANO BASE FOR CLICK BOARDS
Base board
board-50px.png
BM71-XPRO Bluetooth Low Energy
Daughter board
board-50px.png
Weather click
Click board
board-50px.png
Fan Click
Click board
board-50px.png
EINK CLICK BUNDLE
Click board and display
board-50px.png
5V DC Fan
.
board-50px.png
3.7V 5000mAH Lipo Rechargeable Battery
.

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:
MPLAB X IDE v5.50
MPLAB XC32 Compiler v3.00
MPLAB Harmony CSP v3.9.1
Core v3.9.1
DEV_PACKS v3.9.0
MHC v3.7.2
bt v3.4.1
Microchip Bluetooth Data Android App

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.

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC32
C/C++ Compiler

For this lab, download the following repositories from GitHub:

  • CSP: The following table shows the summary of contents.
Folder Description
apps Example applications for CSP library components
arch Initialization and starter code templates and data
docs CSP library help documentation
peripheral Peripheral library templates and configuration data
  • DEV_PACKS: The following table shows the summary of contents.
Folder Description
Microchip Peripheral register specific definitions
arm Core Specific Register Definitions (CMSIS)
  • MHC: The following table shows the summary of contents.
File/Folder Description
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)
  • bt: The following table shows the summary of contents.
Folder Description
apps Example applications for Bluetooth library components
docs Bluetooth module library help documentation
driver Bluetooth module peripheral device drivers
templates Application 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.

flowchart.png
Figure 2. 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

block1.png

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.


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
ble_setup.jpg

Programming private characteristics

  • Download the manual configuration tool from BM70/71 Firmware & Software Tools v1.11
  • Extract and locate configuration tool from 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
ble_config_loading_mainscreen.png
ble_config_loading_step1.png
  • 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
ble_config_loading_step2.png
  • Click on the EDIT option
ble_config_loading_step3.png
  • Select 0x01: BM71 in BLEDK and click OK
ble_config_loading_step4.png
  • Update the Operation Mode Setting from Auto Pattern to Manual Pattern
ble_config_loading_step5_1.png
  • Confirm OK to disable the "Flow Control and LE Connection Parameter Update Request"
ble_config_loading_step5_2.png
  • Click on Finish
ble_config_loading_step5.png
  • Click on Write
ble_config_loading_step6.png
  • Select respective COM Port and set Baudrate to 115200 then click on Write
ble_config_loading_step7.png
  • Click on Yes to successfully update the private characteristics on to BM71 module
ble_config_loading_step8.png
  • After successful update, click OK and remove the power from BM71-XPRO and change jumper J2 to select EXT
ble_config_loading_step9.png
  • 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 Curiosity Nano Baseboard
  • Mount the eINK Click bundle (eINK Click + eINK display) on the mikroBUS 1 connector of 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_setup.jpg
Figure 1: Hardware Setup

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



First Step >

© 2021 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.