The dsPIC33C CAN-TP Demo shows an example configuration of the CAN-TP module (Which follows the ISO 15765-2). The purpose of his demo is to also show how CAN-TP handles messages by having two boards transmitting and receiveing messages over a CAN Bus.
The MPLAB® X demo projects included are set up to utilize specific boards defined in the required hardware section below. The dsPIC33C CAN-TP Demo utilizes resources that are available on most boards(LEDs, Buttons, and mikroBUS slot) allowing the project to be portable to other hardware.
- MPLAB® X IDE 6.20 or newer (https://www.microchip.com/MPLABXIDE)
- MPLAB® XC-DSC Compiler 3.10 or a newer compiler (https://www.microchip.com/xcdsc)
- MPLAB® Code Configurator (MCC) 5.7.1 or newer (https://www.microchip.com/mcc)
- MPLAB® Code Configurator (MCC) Melody 2.7.1 or newer (https://www.microchip.com/melody)
- PCAN-View for recording on the CAN bus (https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1)
- Debugging tool: MPLAB® PICkit™ 5 In-Circuit Debugger (https://www.microchip.com/PICkit5)
- MCP2542 Click x2 (https://www.mikroe.com/mcp2542-click)
- CAN BUS - 1 to 1 CAN cable.
- dsPIC33CK Curiosity Development Board (https://www.microchip.com/dsPIC33CKCuriosity)
- Explorer 16/32 Development Board (https://www.microchip.com/Explorer1632)
- dsPIC33CK256MP508 General Purpose Plug-in Module (https://www.microchip.com/MA330042)
- CAN BUS - n to n Multi Device CAN BUS for reading off the line with an analyzer.
- CAN Terminator (https://www.gridconnect.com/collections/can-cables-connectors-terminators/products/can-terminator) (Used for CAN-FD and for the Analyzer)
- PCAN-USB FD (https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1) (Any CAN analyzer will work)
The dsPIC33C CAN-TP Demo uses the dsPIC33CK256MP508 PIM with Explorer 16/32 Development Board and the dsPIC33CK Curiosity Board. To port to other boards or devices that support CAN/CAN-FD communication in Melody, refer to the Porting the CAN-TP demo to use a different Board/Device section below.
-
The Explorer 16/32 board requires the following:
- MCP2542 Click - inserted into the mikroBUS A slot
- dsPIC33CK256MP508 PIM inserted into the designated slot
- USB cable connected from the PC to the PICkit™ 5
-
The Curiosity board requires the following:
- MCP2542 Click - inserted into the mikroBUS A slot
- USB cable connected from the PC to the PICkit™ 5
-
Connect the devices together using an CAN cable:
- Insert the ends into each MCP2542 click board
- Optional: Connect a CAN analyzer to the bus to view the frames being sent over the bus
- Note: An 120 ohm CAN Bus Terminator may be required for different CAN Bus setups.
Figure 1 - Setup of the dsPIC33C CAN-TP Demo
- Open the dspic33ck-explorer1632-can-tp.X project in the MPLAB® X IDE.
- Right click the project in "Projects" tab of MPLAB® X IDE and select "Set as Main Project".
- Plug in the PICKit™ 5 from the board to the PC.
- Program the device by selecting the "Make and Program Device (Project dspic33ck-exp1632-can-tp)" button on the menu bar.
- The project should build and program successfully.
- Open the dspic33ck-curiosity-can-tp.X project in the MPLAB® X IDE.
- Right click the project in "Projects" tab of MPLAB® X IDE and select "Set as Main Project".
- Plug in the PICKit™ 5 from the board to the PC.
- Program the device by selecting the "Make and Program Device (Project dspic33ck-curiosity-can-tp)" button on the menu bar.
- The project should build and program successfully.
After programming both boards, ensure both are powered on. Pressing the button S3 on Explorer 16/32 board will start the transmission and reception of the messages between the two devices.
As one board transmits a message the board recieving that message utilizes the first byte of the message to update its state. The current state will be shown by toggling the LED at different speeds. All other data in the message is strictly added to show the frame types handled by CAN-TP (Refer to Figure 2 below regarding the frame types).
The transmission and reception of the messages will continue until one board is manually powered off.
Figure 2 - Recording over the CAN bus
CAN-TP v1.1.0 now Supports CAN(Classic/2.0 Mode), if this mode is preferred follow the bolded Note sections below for differences in configuration. Otherwise the steps will cover updating up the CAN-TP projects with a CAN-FD peripheral.
- Any dsPIC device that supports CAN-TP and CAN/CAN-FD in MCC Melody.
- LED (one for each board to show the different states)
- Button (Used for one board ONLY to trigger the start of the loop)
- mikroBUS slot (one for each board to utilize the MCP2542 click board)
The setup below describes the setup for the two boards as well as the CAN/CAN-FD configurations to use. Refer to the Commonly Used PIMS/Board Pin Selections section below for more information.
The project for board 1 kicks off the message passing. It requires a button and an LED. This will utilize the dspic33ck-exp1632-can-tp.X project to receive, process and respond to devices with an ID of 0xA2.
-
Open the dspic33ck-exp1632-can-tp.X project in the MPLAB® X IDE.
-
Right click the project in "Projects" tab of MPLAB® X IDE and select Properties. Change the device to the one you are using and select an XC compiler. Apply these settings and continue with the next steps.
-
Right click the project in "Projects" tab of MPLAB® X IDE and select "Set as Main Project".
-
Open Melody by selecting the MCC button.
-
Ensure CAN-TP is added to the project and configure the following:
- TMR1 for the timer dependency for CAN-TP
- MessageID is set to 0xA1
-
Within the Pin Grid View for your board select pins for the following: (Refer to the board/devices schematics and Pin mapping to choose the correct selections for each option below)
- Select an LED as output
- Select an Button for input
- Select the CAN1TX for your board
- Select the CAN1RX for your board
-
Within Pins resource under the Project Resources tab:
- For the button input selected make the following configurations
- Enable Weak pullup
- Select interrupt on negative change
- Change the custom name to be BUTTON
- For the LED selected make the folowing configurations
- Change the custom name to be LED
- For the button input selected make the following configurations
-
Select CAN_FD1 and do the following:
- Enable Data Bit Rate and Set Bit Rate to 2Mbps
- In filter0's Message ID Set it to 0xA2
-
Select the Generate Button under project resources.
- DO NOT overwrite the contents of the main.c.
-
Build and Program the board.
The project for board 2 waits until it receives a message before responding. It requires an LED. This will utilize the dspic33ck-curiosity-can-tp to receive, process and respond to devices with an ID of 0xA1.
-
Open the dspic33ck-curiosity-can-tp.X project in the MPLAB® X IDE.
-
Right click the project in "Projects" tab of MPLAB® X IDE and select Properties. Change the device to the one you are using and select an XC compiler. Apply these settings and continue with the next steps.
-
Right click the project in "Projects" tab of MPLAB® X IDE and select "Set as Main Project".
-
Open Melody by selecting the MCC button.
-
Ensure CAN-TP is added to the project and configure the following:
- TMR1 for the timer dependency for CAN-TP
- MessageID is set to 0xA2
-
Within the Pin Grid View for your board select pins for the following: (Refer to the board/devices schematics and Pin mapping to choose the correct selections for each option below)
- Select an LED as output
- Select the CAN1TX for your board
- Select the CAN1RX for your board
-
Within Pins resource under the Project Resources tab:
- For the LED selected make the folowing configurations
- Change the custom name to be LED
- For the LED selected make the folowing configurations
-
Select CAN_FD1 and do the following:
- Enable Data Bit Rate and Set Bit Rate to 2Mbps
- In filter0's Message ID Set it to 0xA1
-
Select the Generate Button under project resources.
- DO NOT overwrite the contents of the main.c.
-
Build and Program the board.
The CAN-TP project uses the following:
- MCC Melody CAN-TP Library
- MCC Melody CAN-FD Driver
- 1ms Timer
- LED (For both boards)
- Button (For one of the two boards)
This project can be opened in MPLAB® X IDE and programmed to any board capable of using CAN.
| Function | Description |
|---|---|
| Set_Ticks(int) | This updates the state that will determine the LED toggle time. |
| BUTTON_Pressed() | Called by the button interrupt to start the sending loop. |
| Update_Message() | Updates the state in the Tx message to send to the other board. |
| LED_Tick() | Decrement counter that will update the current blink duration. |
| Custom_Ticks() | Calls the CAN_TP_TICK and LED_TICK function. This also checks the tick count to toggle the LED. |
- The following is assuming the MCP2542 click board is in mikroBUS A on both Boards
| Board | PIM/On Board | CAN_RX | CAN_TX | LED(output) | BUTTON(input) |
|---|---|---|---|---|---|
| Explorer 16/32 | (PIM)dsPIC33CK256MP508 | PORTD0 | PORTD1 | PORTE0 | PORTB14 |
| Explorer 16/32 | (PIM)dsPIC33CK512MP608 | PORTD0 | PORTD1 | PORTE0 | PORTB14 |
| dsPIC33CK Curiosity | (On Board)dsPIC33CK256MP508 | PORTD15 | PORTD14 | PORTE14 | PORTE7 |
- For any other boards/devices check the Schematics and Pin mapping of each to configure the Click board, LED and button correctly.


