Main Content

Calibrate ECU Parameters in CANape Using XCP-Based Serial Interface on Arduino Hardware

This example shows how to monitor signals and tune parameters of a Simulink® model on Arduino® Mega 2560 board using CANape® software. CANape is primarily used in optimizing parameterization (calibration) of electronic control units (ECU). By using CANape, you can calibrate parameter values and acquire measurement signals during system run time.

In this example, you will learn how to tune the parameters and monitor the signals in an algorithm in real time from CANape software.


Complete the Get Started with Arduino Hardware example.

Required Third-party Software

  • CANape 16.0 SP6

Required Hardware

Any Arduino board as listed in the Supported Hardware section of Arduino Support from Simulink.

Simulink Model

Open the arduino_xcponserial_CANape Simulink model.

This example contains three signals that are enabled for logging and two parameters for tuning. The three signals are:

  • Counter — Increments the output by STEP_PARAM at every time step

  • Sine_Wave — A sine wave

  • Pulse — A pulse signal with tunable amplitude

Configuring Simulink Model for Arduino Board

The Simulink model provided in this example is preconfigured for Arduino Mega 2560, but it can be run on any of the Arduino boards. To use a hardware board other than Arduino Mega 2560 and enable calibration of parameters in CANape, follow these steps:

1. Open arduino_xcponserial_CANape model

2. Go to Modeling > Model Settings to open the Configuration Parameters dialog box.

3. Open the Hardware Implementation pane, and select the required Arduino board from the list in Hardware board parameter.

4. Expand Target hardware resources for that board.

5. Go to External mode tab and choose XCP on Serial as the Communication interface.

6. Choose Third party calibration tools as the Host Interface.

7. Click Apply and OK.

Initiate Build and Deploy Action for the Model and Generate A2L File

1. In the Hardware tab of Simulink toolstrip, click Build for Monitoring. This action builds the model and generates the executable along with the A2L file in the current MATLAB folder path. The A2L file contains XCP server information for using in third-party calibration tools. The file name of the A2L file is in this format: modelname.a2l. For more information on A2L file generation, see Export ASAP2 File for Data Measurement and Calibration (Simulink Coder).

2. Click Deploy in the Simulink Toolstrip to deploy the executable onto the target.

3. Import the A2L file into third-party calibration tools, connect to the XCP server, and start monitoring of signals and calibration of parameters using the interface in third-party calibration tool.

Create New Project in CANape and Connect to Arduino board

1. Open Vector CANape 16.0 software. Create a new Project.

2. Drag and drop the A2L file generated from the model into CANape. This opens a new dialog box which creates a new device.

3. Click Next and finally click OK. A new device is created, and the Settings dialog box for the newly created device opens.

4. Expand the Protocol tab in the Settings dialog box. Click Transport Layer.

5. Ensure that you have selected the correct Channel (COM Port to which Arduino is connected) in the COM section. Modify the Baud Rate to 921600.

6. Click Accept all changes in the top-left corner of the Settings dialog box and close it.

7. Click Online to connect to the Arduino board.

Perform Measurement and Calibration from CANape

1. Open the list of signals and parameters by expanding the Devices tab in the Explorer pane.

2. Drag the signals that you want to monitor, to the Display area and select a graphic window.

3. Drag the parameters that you want to tune, to the Display area and select Parameter window.

4. Click Start measurement in the Start tab to start monitoring the selected signals.

5. Use the Parameter window to tune the parameters.

Troubleshoot Calibration in CANape

While you perform calibration of parameters using CANape, you may encounter these errors:

  • CANape fails to connect with the error: No response from the ECU

To resolve this issue, check the COM Port and Baud Rate settings and ensure that they are correct. If the error persists, press Reset button on Arduino board and try to connect again.

  • Data Acquisition does not start when you click Start for the first time.

To resolve the issue, click Start again.

The issue occurred because CANape sends command 0xD7 (GET_DAQ_EVENT_INFO) and 0xDC (GET_DAQ_CLOCK) to the server, even though these are not listed as supported optional commands in the ASAP2 file. By default, CANape has XCP_OPTIONAL_CMD_AUTO_LEARNING feature, which learns that the GET_DAQ_EVENT_INFO and GET_DAQ_CLOCK commands are not supported, and correctly sends DAQ on the second attempt. This information persists in the project database, so the failure does not occur again for the same project.


Signal monitoring or parameter tuning of type double can only be done on Arduino with ARM cores.