
MATLAB/Simulink Model for I2C Peripheral Example: Curiosity Platform Development Board, dsPIC33AK128MC106 Curiosity GP DIM and MPU9250
This document describes the setup requirements for demonstration of I2C communication on the hardware platform EV74H48A "Curiosity Platform Development Board" and EV02G02A "dsPIC33AK128MC106 General Purpose Dual In-Line Module (DIM)" using MPU9250 sensor on the MPU 9DOF Click Board.
MPU-9250 is a multi-chip module (MCM) with 9-axis MotionTracking device that combines a 3-axis gyroscope, 3-axis accelerometer, 3-axis magnetometer and a Digital Motion Processor™ (DMP).
To clone or download this MATLAB model on GitHub,
- MATLAB model can be cloned or downloaded as zip file from the Github repository (link).
- MPLAB® X IDE v6.25
- MPLAB® XC-DSC Compiler v3.21
- MATLAB R2024b
- Required MATLAB add-on packages
- Simulink (v24.2)
- Simulink Coder (v24.2)
- MATLAB Coder (v24.2)
- Embedded Coder (v24.2)
- MPLAB Device blocks for Simulink (v3.59)
- Motor Control Blockset (v24.2)
NOTE: The software tools used for testing the model during release is listed above. It is recommended to use the version listed above or later versions for building the model.
- Curiosity Platform Development Board (EV74H48A)
- dsPIC33AK128MC106 General Purpose Dual In-Line Module (EV02G02A)
- MPU 9DOF CLICK
This section describes the hardware setup required for the demonstration.
Note:
In this document, hereinafter Curiosity Platform Development Board is referred as development board.
-
Insert the dsPIC33AK128MC106 Curiosity GP DIM into the DIM Interface connector J1 on the development board. Make sure the DIM is placed correctly and oriented before going ahead.
-
Insert the MPU 9DOF click into the mikro BUS A interface connector J13 on the development board. Make sure the click board is inserted correctly before going ahead.
-
The development board has an onboard programmer PICkit™ On Board (PKoBv4) , which can be used for programming or debugging the microcontroller or dsPIC DSC on the DIM. To use the onboard programmer, connect a micro-USB cable between the Host PC and connector J24 on the development board.
The development board is also powered by this USB itself.
Follow the below instructions step-by-step, to set up and I2C demo application:
-
Launch MATLAB (refer the section “2.2 Software Tools Used for Testing the MATLAB/Simulink Model").
-
Open the folder downloaded from the repository, in which MATLAB files are saved (refer the section "2.1 MATLAB Model Required for the Demonstration").
-
Double click on the I2C example Simulink model - curiosity_i2c.slx. This opens the Simulink model as shown below.
Note:
This example demonstrates only the code generation to demostrate the I2C communication. The simulation is not possible in this case. -
From this Simulink model an MPLAB X project can be generated, and it can be used to run the I2C Communication using development board.
To generate the code from the Simulink model, go to the "MICROCHIP" tab, and enable the tabs shown in the figure below.
-
This model uses the External Mode debug option for real time data visualization. To configure the external mode click on "Ext Mode Settings" option under the “Microchip” tab.
This will open External Mode Setup window and enable the checkboxes as shown in the figure. Also select the COM port connected to the development board and Baud Rate.
Note:
Two COM ports are available on the development board. Select the second COM port number for the external mode (if COM2 and COM3 are available on the development board, select COM3). -
To generate the code and run the I2C communication on hardware, click on "Monitor & Tune" option under the Hardware tab and ensure that "Stop Time" is set to "inf".
-
After compilation and programming the device. The external mode will be running on the dsPIC.
The General Purpose LED's will be blinking.
-
The RGB LEB will be glowing in different colors. To increase the brightness of the RGB LED, vary the Potentiometer on the development board.
-
To view the I2C communication from "MPU9250" double click on the scope. This opens the scope view. Tilt or turn the development board by hand to view variations in the signal from the accelerometer, gyroscope and magnetometer sensors of MPU9250.
-
Click on the Stop button to stop the I2C communication and external mode.
For more information, refer to the following documents or links.
- Curiosity Platform Development Board User's Guide (DS70005562)
- dsPIC33AK128MC106 General Purpose Dual In-Line Module (DIM) Information Sheet (DS70005556)
- dsPIC33AK128MC106 Family datasheet (DS70005539)
- MPLAB® X IDE User’s Guide (DS50002027) or MPLAB® X IDE help
- MPLAB® X IDE installation
- MPLAB® XC-DSC Compiler installation
- MPLAB Device Blocks for Simulink :dsPIC, PIC32 and SAM mcu
- External Mode Demo