Master-Slave-Interface introductory demo project for dual-core dsPIC33CH from Microchip tutorial:
IMPORTANT NOTES:
-
MPLAB X IDE v6.05 is broken - it will hang-up forever once Slave Core project is added to Master Core project (!)
-
MPLAB X IDE v6.10 has another bug: It does not work with PicKit 3 and PKOB (PicKit on-board) programmer - so you will be unable to program dsPIC on Curiosity board.
To fix it you have to install Plugin Updates
-
so latest working MPLAB X IDE is v6.10 WITH UPDATES or v5.50.
Hardware Requirements:
- dsPIC33CH Curiosity Development Board
- Micro USB cable (there is no one included with board!)
- ensure that you downloaded data-sheet from:
- Notice dsPIC type from data-sheet:
Here is brief overview of I/O peripherals - excluding DC/DC converter parts:
Peripheral | dsPIC33CH pin and/or port |
---|---|
S1 push-button | RE7 |
S2 push-button | RE8 |
S3 push-button | RE9 |
S4 push-button | /MCLR (reset) |
R/G/B LED | RB14/RD7/RD5 |
LED1 red | RE0 |
LED2 red | RE1 |
10kOhm pot | RA0 |
Software Requirements:
- MPLAB X IDE
v6.10
- DFP:
dsPIC33CH-MP_DFP
v1.12.352` - MCC Core: v5.5.7 (Updated)
- PLIB: 1.171.2 (Updated)
- XC16
v2.10
Again important notes:
- it is necessary to install Plugin Updates in MPLAB X IDE v6.10, otherwise it will NOT work with PicKit on-board programmer (PKOB). To be able to program dsPIC on Curiosity board you need these updates.
- also if MPLAB X IDE v6.10 does not see your on-board programmer try to:
- exit MPLAB X IDE
- (re) connect Curiosity board
- start MPLAB X IDE again
- now programmer should be visible
We will mostly follow
- https://microchipdeveloper.com/16bit:ch-example Adjusting it for Curiosity board and parts.
To create Master core project do this:
- connect your Curiosity board to PC with USB micro cable
- se we will be able to select Programming tool while creating new project.
- run MPLAB X IDE
Now we will create project for Master Core:
- click on
File
->New Project...
- select
Microchip Embedded
->Standalone Project
, clickNext
- select:
- Family:
16-bit DSCs (dsPIC33)
- Device:
dsPIC33CH512MP508
(MASTER - withoutS1
!) - Tool:
Starter Kits (PKOB)-SN:BURxxx
(you need to have your Curiosity board connected to PC for this)
- Family:
- click
Next
- select XC16 compiler - in my case
v2.00
- click
Next
- NOW important:
- select location for Master project - please note that we will later create 2nd (Slave) project on same level
- do NOT use dash (
-
) or spaces in project name! It is later converted to Symbol name which will crash build!
- I selected:
- project Name:
Master
(again - do NOT use dashes (-)) - project Location:
E:\projects\dsPIC33CH-Curiosity-Demo
- resulting project folder
E:\projects\dsPIC33CH-Curiosity-Demo\Master.X
- keep
Set as main project
checked on.
- project Name:
- click on
Finish
Now we have to run MCC (Microchip Configuratin tool)
- ensure that you have installed MCC in MPLAB X IDE
- go to
Tools
->Plugins
- seect
Installed
tab and look forMPLAB Code Configurator
- if it is not there - select tab
Available Plugins
and select it - in my case I have plugin
MCC v5.0.3
- latest version for MPLAB v5.50
- go to
- now click on
MCC
icon on Toolbar to open MCC Tool - now we will follow guide and so:
MCC Content Manager
window should appear- click on
Select MCC Classic
- click on
Finish
- it will download required libraries and finally run MCC Tool - now select
Resource Management
tab - under window
Device Resources
expandPeripherals
->SLAVE CORE
->Slave Core
- either click on
+
icon or double-clickSlave Core
to add it to Project - fill in to Slave Project Name:
Slave
(we will later createSlave.X
project that must match this name) - for sake of example we have to do this under
Master Slave Interface
->Mailbox Configuration
- enable
Protocol A
andProtocol B
- in case of
Protocol A
change Direction to:M -> S
(wasS -> M
) - the
Protocol B
should be kept toS -> M
- both should have Buffer Size 2 bytes (default)
Now we have to assign these LEDs from above table to proper Master and/or Slave core:
Peripheral | dsPIC33CH pin and/or port |
---|---|
LED1 red | RE0 |
LED2 red | RE1 |
So do this:
- select
Pin Manager: Grid View
(it is in right-bottom Window) - now Single click on this cell:
- Row:
Pin Module
->GPIO output
- Column:
Port E
-0
- Row:
- the right cell should have now green Lock Icon
- now Single click on this cell for Slave LED (
RE1
):- Row:
Slave Core
->Ownership
->output
- Column:
Port E
->1
- Row:
- now select
Pin Module
tab (top middle Window) - and on
RE0
set Custom Name:LED_MASTER
Now we have to save Master settings from Slave core (yes :-)
- select tab
Slave Core
- click on
Save Master Settings
- this should save
.mc3
files underMaster.X
project
Now we can click on Project Resources -> Generate to generate C source files
under Master.X/mcc_generated_files/
- ignore warnings so far
Now rather close MCC tool by clicking on MCC
icon in toolbar
Do NOT build yet - we need to create Slave project for build to succeed.
Back in MPLAB X IDE we have to create Slave project:
- click on
File
->New Project...
- select
Microchip Embedded
->Standalone Project
, clickNext
- select:
- Family:
16-bit DSCs (dsPIC33)
- Device:
dsPIC33CH512MP508S1
(SLAVE - must end withS1
!) - Tool:
No tool
- does not matter unless you want to debug BOTH Cores, in which case you need 2nd Debugger (slave is programmed from Master Core and its Master flash)
- Family:
- click
Next
- select XC16 compiler - in my case
v2.00
- click
Next
- NOW important:
- select location for Slave project - it must be on same level where is
Master.X
project (!)
- select location for Slave project - it must be on same level where is
- I selected:
- project Name:
Slave
- the name must match those configured in MCC Tool (!) - project Location:
E:\projects\dsPIC33CH-Curiosity-Demo
- resulting project folder
E:\projects\dsPIC33CH-Curiosity-Demo\Slave.X
- temporarily keep CHECKED
Set as main project
- project Name:
- click on
Finish
Now we need a bit tricky way run MCC
on Slave.X
project:
- ensure that
Slave
is temporarily Main project (Bold font in Projects tab) - click on
MCC
icon in toolbar to run MCC tool onSlave
project - again select
MCC Classic
andFinish
Loading Master settings to Slave project:
- select tab
Master Core
- select
Easy Setup
sub-tab - click on
Load Slave Settings from Master Configuration
- when asked for
.mc3
file selecte:\projects\dsPIC33CH-Curiosity-Demo\Master.X\master_config.mc3
- don't be scared with RB1 pin conflict.
- click on YES to override
RB1
pin setting
Now we have to properly configure and name RE1
(in Master config we just reserved
id as "Slave output" but detailed configruation must be done for Slave core:
- in Pin Manager:
Grid View
- now SINGLE click on this cell:
- Row:
Pin Module
->GPIO output
- Column:
Port E
-1
- Row:
- there must show green lock icon in this cell.
- now in
Pin Module
set Custom NameLED_SLAVE
forRE1
pin.
Now we can click on Project Resources -> Generate to generate C source files
under Slave.X/mcc_generated_files/
Now we need to understand how Dual Core CPU is programmed and executed:
- Master Core flash contains code for BOTH Master and Slave CPU
- Master Core copy Slave program to Slave Program RAM (PRAM)
- master Core starts Execution of Slave
Therefore there is only Single Program (hex) file that must include both Master and Slave
Core code. So we have to include Slave.X
project into Master.X
project build using:
- select tab
Projects
- right-click on
Master
->Secondaries
(wasSlaves
in older MPLAB X IDE) and - click on
Add Secondary Project...
- select
E:\projects\dsPIC33CH-Curiosity-Demo\Slave.X
- ensure that Store path as: is
Relative
(to make this project portable) - and click on
Add
- AGAIN WARNING! If you have MPLAB X IDE v6.05 it will likely freeze...
- so use rather MPLAB X IDE v5.50 - it works fine.
Now we need to tell MPLAB to build Slave project:
- right-click
Master
->Secondaries
->Properties...
- WARNING do NOT right-click on
Slave
leaf - there is noProperties...
dialog. You have to click on parentSecondaries
- WARNING do NOT right-click on
- select checkbox
Build
and clickOK
to close dialog.
Finally we have to copy and paste example sources
to Master.X/main.c
and Slave.X/main.c
as shown
on https://microchipdeveloper.com/16bit:ch-example
Please see:
- Master.X/main.c
- Slave.X/main.c for full source.
In Tab Projects
right-click on Master
and select Set as Main Project
(it must be that
way before build).
Now you can right-click on Master
and select Clean and Build
- or use Hammer icons on Toolbar.
- Please note that this will ALSO build
Slave
project, because it has to be included in Master Core Program Flash.
If you have already assigned embedded PicKit programmer you can just use
Run Main Project
(big green arrow icon on toolbar)
After a while both LED1 and LED2 should be ON (forever).
- Plase be patient - it may take some time for program to run...