Configure Model for XCP on CAN External Mode
R2026bUse XCP on CAN external mode to monitor signals and tune parameters in a Simulink® model deployed on Arduino® using a CAN bus connection. With Simulink as the host interface, you can use the Monitor & Tune workflow to interact with the running model directly from Simulink. Use this workflow to prepare signals and parameters, deploy the model to Arduino hardware, and monitor and tune parameters in real time over CAN.
Prerequisites
Before you begin, make sure:
CAN hardware is installed and verified on the host computer. For more information, see Step 1: Set Up CAN Hardware on Host Computer for XCP on CAN Communication.
CAN interface is enabled on Arduino hardware.
Vehicle Network Toolbox™ is installed.
Example Model
In this example, you create a simple model that generates a sine wave, applies a tunable gain, and outputs the results to a PWM pin on Arduino. You can monitor the sine wave signal and tune the gain parameter in real time over XCP on CAN.

Open Simulink and create a blank model.
Add and connect these blocks:
Configure the Sine Wave block.
Set amplitude to
1.Set frequency to
2*pi.Set sample time to
0.01seconds.
Configure the Gain block.
Set gain to
1.
Configure the PWM block.
Set pin number to
5or any other available GPIO pin.
In the Configuration Parameters dialog box, configure these parameters in the model solver:
Set Type to
Fixed-step.Set Solver to
auto (Automatic solver selection).Set Fixed-step size to
0.01.
Enable Signal Logging
Enable logging for the signals you want to monitor during external mode simulation.
In the Simulink model, select the signal line you want to monitor, for example, the output of the Sine Wave block.
On the Simulink Toolstrip, on the Simulation tab, click Log Signals. A logging badge appears on the signal line, indicating the signal will be captured during external mode execution.
Repeat for any additional signals you want to monitor.
Select Hardware
In the Configuration Parameters dialog box, select Hardware Implementation.
Set Hardware board to any one of these supported Arduino boards:
Arduino DueArduino Uno R4 Wi-Fi®Arduino Uno R4 MinimaArduino Nano R4Teensy 4.0 (Arduino compatible)Teensy 4.1 (Arduino compatible)
Configure CAN Baud Rate on Target
In the Configuration Parameters dialog box, navigate to Hardware board settings>Target hardware resources>On-board CAN properties.
Set the CAN Bus Speed (kBits/s) to match the baud rate configured in the third-party calibration tool. A baud rate mismatch prevents communication.
Configure External Mode Communication
In the Configuration Parameters dialog box, navigate to Hardware board settings>Target hardware resources>External mode.
Set Communication interface to
XCP on CAN.Set Host interface to
Simulink.Navigate to Hardware board settings>Target hardware resources>Host-board connection>External mode over CAN and configure the host-side CAN hardware parameters.
CAN Vendor — Select the vendor of the CAN hardware connected to the host computer (Vector, PEAK-System, or Kvaser). This list is populated from the CAN hardware detected by the
canChannelList(Vehicle Network Toolbox) function.CAN Device — Select the CAN device from the list of detected devices for the selected vendor.
CAN Channel — Select the CAN channel on the selected device.
Configure the target-side CAN module.
CAN module — Select the On-board CAN controller module for XCP on CAN.
Configure CAN identifier parameters.
Extended CAN ID — Select if your CAN network uses extended 29-bit identifiers instead of standard 11-bit identifiers.
CAN ID command — CAN identifier for command messages from host to target.
CAN ID response — CAN identifier for response messages from target to host.
Configure polling time.
Set XCP target polling time — If you need to override the automatic polling time, set to
Manually.Polling time (in seconds) — Specify a custom polling time.
Click Apply.
Deploy Model and Monitor Signals
On the Hardware tab of the model, click Monitor & Tune. Simulink builds the model, deploys it to Arduino, and establishes the XCP on CAN connection.
Once the connection is established, open Simulation Data Inspector to view logged signals in real time. Modify tunable parameters directly in the block dialog or MATLAB® Command Window to observe the effect on the deployed model.
To stop the external mode session, on the Hardware tab, click Stop.
Troubleshooting
Connection timeout in external mode
To verify the CAN hardware is detected, run
canChannelList(Vehicle Network Toolbox) in the MATLAB Command Window.If the hardware is not listed, see the Troubleshooting steps.
Close and reopen the Configuration Parameters dialog box after connecting new hardware.
Insufficient logging buffer memory
If you encounter a logging buffer memory overflow error:
Reduce the number of signals marked for logging.
Increase the Logging buffer size (in bytes) value or select Set logging buffer size automatically to allow Simulink to calculate the required buffer size.
See Also
canChannelList (Vehicle Network Toolbox) | External mode | Host-board connection | On-board CAN properties | On-board CAN
Receive | On-board CAN
Transmit