3.5.2.1 SHD Based Click Board (CAN-mcp25625) Example on PIC32CM JH VL Curiosity Nano Evaluation Kit + Nano Explorer
Description
This application demonstrates the use of the MCP25625 CAN Click board for transmitting and receiving CAN data with the PIC32CM JH-Value Line Curiosity Nano + Touch evaluation kit. The mikroBUS interface on the Curiosity Nano Explorer provides a seamless connection to the MCP25625 Click board, ensuring reliable communication between the microcontroller and the CAN transceiver.
The application is built using the SHD feature, which automatically configures and enables the necessary peripheral access for the Curiosity Nano Explorer. This includes the SPI interface and GPIO connections required for communication with the MCP25625 Click board, as well as the UART interface used for data display.
To demonstrate CAN communication, the setup consists of two hardware configurations:
-
Transmitter Setup: PIC32CM JH-Value Line Curiosity Nano + Touch evaluation kit and MCP25625 CAN Click board mounted on the Curiosity Nano Explorer board, configured to send CAN messages
-
Receiver Setup: PIC32CM JH-Value Line Curiosity Nano + Touch evaluation kit and MCP25625 CAN Click board mounted on the Curiosity Nano Explorer board, configured to receive CAN messages
Both setups are connected through the CAN bus using the CAN_H and CAN_L lines, and both setups are capable of transmitting and receiving CAN messages.
The transmitted and received CAN messages are displayed on a serial terminal through UART, allowing users to easily monitor the flow of CAN data. This demo highlights the integration of SHD with MPLAB Harmony, simplifying peripheral setup and reducing manual configuration effort while showcasing end-to-end CAN communication using MCP25625 Click boards.
Modules/Technology Used
- Peripherals
- PORT
- SYSTICK
- SERCOM0 - SPI
- SERCOM1 - UART
- Core
- SHD
- PIC32CMJH-CURIOSITY-NANO-EXPLORER
The following figure provides the MCC Harmony project graph with all the components.
Hardware Used
- PIC32CM JH-Value Line Curiosity Nano + Touch Evaluation Kit - 2 Units
- Curiosity Nano Explorer - 2 Units
- MCP25625 Click - 2 Units
- Connecting wires - 3 Units
Software/Tools Used
This project has been verified to work with the following versions of software tools:
Refer to the Project Manifest present in
harmony-manifest-success.yml under the project folder
firmware/src/config/pic32cm_jh_vl_cnano.
- Refer to the Release Notes to know the MPLAB X IDE and MCC Plug-in version
- Any Serial Terminal application, such as Tera Term/PuTTY terminal application
Due to Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project does not seem to work and version incompatibility is suspected, it is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to the document How to Use the MPLAB Harmony v3 Project Manifest Feature (DS90003305).
Hardware Setup
- Place the PIC32CM JH VL Curiosity Nano + Touch evaluation kit on the Curiosity Nano Explorer Board
- Mount the MCP25625 on mikroBUS Socket 1 of the Curiosity Nano Explorer board
- Ensure the jumper
connections are properly made for the SPI lines and the MikroBUS between
the PIC32CM JH VL Curiosity Nano + Touch evaluation kit and the
Curiosity Nano Explorer Board, as follows:
- PA04 - SPI MOSI
- PA06 - SPI MISO
- PA05 - SPI SCK
- PB04 - MBUS CS
- PB06 - MBUS RST
- PA03 - MBUS AN
- Connect the jumper pins
between the two MCP25625 MikroBUS setups for the following signals:
- CANH
- CANL
- GND
- Connect the PIC32CM JH VL Curiosity Nano + Touch evaluation kit to the
host PC using a Type-A male to Type-C USB cable. Plug the cable into the
Type-C USB (Debug USB) port on the evaluation kit
Programming Hex File
The pre-built hex file can be programmed by following the below steps.
- Open MPLAB X IDE
- Close all existing projects in IDE, if any project is opened
- Go to
File>Import>Hex/ELF File - In the Import Image File
window,
- Create Prebuilt
Project,
- Click the Browse button to select the prebuilt hex file
- Select Device as PIC32CM6408JH00064
- Ensure the proper tool is selected under Hardware Tool and click the Next button
- Select Project
Name and Folder,
- Select appropriate project name and folder
- Click the Finish button
- Create Prebuilt
Project,
- In MPLAB X IDE, click the Make and Program Device button to program the device
- Follow the steps in Running the Demo section
- Operating at 3.3V, configure the internal oscillator VDD range to 2.7V - 3.6V in the clock configuration
- Operating at 5V, configure
the internal oscillator VDD range to 3.6V - 5.5V in the clock
configuration
Programming/Debugging Application Project
- Open the project
(
pic32cm_jh_vl_cnano/pic32cm_jh_vl_cnano_mikroe_click/pic32cm_jh_mcp25625/firmware/pic32cm_jh_vl_cnano.X) in MPLAB X IDE - Then, right click on the project (mcp25625_click_pic32cm_jh_vl_cnano) and click the Set as Main Project button
- Ensure
PIC32CM JH-VL CNANOis selected as hardware tool to program/debug the application - Build the code and program the device by clicking on the Make and Program button in MPLAB X IDE tool bar
- Follow the steps in Running the Demo section
Running the Demo
-
Open the Tera Term/PuTTY terminal application on the PC (from the Windows® Start menu by pressing the Start button)
-
Set the baud rate to 115200
-
Repeat the above two steps for the second hardware setup (Setup-2)
- Enter a character
aon one Tera terminal application to initiate the CAN Message Transmit - Enter a character
bon another Tera terminal application to wait for the CAN Message Receive -
In both the Tera terminal windows, the user will see the CAN message transmission and reception continuously
Instructions to Add MCP25625 Functionality to the Application
The user could use this demonstration as an example to add MCP25625 functionality to the MPLAB Harmony v3-based application. Follow the below steps:
-
If the user has not downloaded the pic32cm_jh_mcp25625 demo yet click here to download, otherwise go to the next step.
-
Unzip the downloaded .zip file.
-
From the unzipped folder
pic32cm_jh_mcp25625/firmware/src, copy the folder click_routines to the folder firmware/src under the MPLAB Harmony v3 application project. -
Open MPLAB X IDE.
-
Open the application project.
-
In the project explorer, right click on Header Files folder and add a sub folder, click_routines, by selecting Add Existing Items from Folders...
- Click the Add
Folder... button.
- Select the click_routines
folder and select Files of Types as Header Files
- Click the Add button
to add the selected folder.
- The MCP25625 click example
header files gets added to the project.
- In the project explorer,
right click on Source Files folder and add a sub folder, click_routines, by
selecting Add Existing Items from Folders...
- Click the Add
Folder... button.
- Select the click_routines
folder and select Files of Types as Source Files.
- Click the Add button
to add the selected folder.
- The MCP25625 click example
source files gets added to the project.
- The MCP25625 Click example
requires specific peripheral and pin configurations. The exact configuration
depends on the PIC32CM JH VL Curiosity Nano board used in conjunction with
the Curiosity Nano Explorer board, which provides connectivity to the
MCP25625 Click board.
-
Configure the SHD:
-
Add the SHD Component of PIC32CMJH-Curiosity-Nano-Explorer block to the MCC project graph.
- Select
PIC32CMJH-Curiosity-Nano-Explorer block in the project
graph. In the Configuration Options window, go to
External Connectors>Curiosity Nano Explorer mikroBUSand select MCP25625 Click. - MCC
automatically adds the peripheral configuration to the
Project Graph after MCP25625 selection.
-
For Curiosity Nano Explorer mikroBus - MCP25625 configuration, only the AN, SPI, RST configurations are required.
Disable additional, unused configurations (PWM, INT, UART and I2C) in the Curiosity Nano Base mikroBUS 1 Configuration Options window. - Enable the
Virtual COM Port interface in the On-Board Nano Debugger
interface.
- Users can
view the pin configuration for RST, AN, UART, and SPI lines
in the pin settings window, which are used for CAN
communication.
- Map Generic
Macros:
- After generating the project, following the above configuration, map the generic macros used in the click routines to the Harmony PLIB APIs of the 32-bit MCU the project is running on.
- The
generic macros should be mapped in the
click_interface.h header file.
As an example, the MCP25625 click routines for the example on PIC32CM JH VL Curiosity Nano evaluation kit uses the following Harmony PLIB APIs.
- The click_routines folder contain an example C source file mcp25625_example.c. The user could use mcp25625_example.c as a reference to add MCP25625 functionality to the application.
-
-
Comments
- Reference Training Module: Getting Started With MPLAB® Harmony v3 Peripheral Libraries on PIC32CM JH (Arm® Cortex®-M0+) MCUs
- Reference Application: MCP25625 Click Example on SAM E51 Curiosity Nano Evaluation Kit
- This application demo
builds and works out of box by following the instructions in Running the
Demo section. If the user needs to enhance/customize this application
demo, should use the MPLAB Harmony v3 Software framework. Refer to the
following links to setup and build the applications using MPLAB
Harmony.
- How to Setup MPLAB Harmony v3 Software Development Framework (DS90003232)
- How to Build an Application by Adding a New PLIB, Driver, or Middleware to an Existing MPLAB Harmony v3 Project (DS90003253)
- Video - How to Set up the Tools Required to Get Started with MPLAB® Harmony v3 and MCC
- Create a new MPLAB Harmony v3 project using MCC
- Update and Configure an Existing MHC-based MPLAB Harmony v3 Project to MCC-based Project
