Send CAN messages from MATLAB to ECU with PEAK device

14 views (last 30 days)
Hi!
I am trying to send CAN messages from MATLAB to my connected ECU. I have a PCAN-USB FD (https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1), so I start the channel (the third library is installed). Then, I open the database that contain the two message variables. Then, I transmit periodically the messages to this channel. (The code that I am running is below)
The problem is that when the data is transmited, the PEAK device is receiving these messages, but it does not transmit the messages to the CAN bus, for the ECU to receive them.
I don't know if I am doing something wrong, or if there is other way to communicate with my ECU using MATLAB and a PCAN-USB FD.
If someone know something about, it could be so helpful for me.
Thanks in advance.
Óscar.
%CAN TRANSMITED DATA TO THE USB
txCh = canChannel('PEAK-System', 'PCAN_USBBUS1'); % Construct CAN channel connected to specified device
start(txCh);
%%
db = canDatabase('file.dbc'); % Open the database and attach it to the CAN channels
txCh.Database=db;
msg1 = canMessage(db,'ECU_1'); % Definir el mensaje a extraer de .dbc
msg2 = canMessage(db,'ECU_2');
transmitPeriodic(txCh,msg1,'On',0.05); % Transmitir el mensaje a determinada frecuencia
transmitPeriodic(txCh,msg2,'On',0.05);
%%
msg1.Data= data_calculation(50);
msg2.Data = msg1.Data;

Answers (1)

Alexey Molchanov
Alexey Molchanov on 9 Feb 2022
You need to set up correct speed for CAN interface before use it.
  1 Comment
Timothy
Timothy on 3 Jun 2024
I have the same issue as the orignial post. What do you mean by set up correct speed for CAN interface? The default bit rate should be fine for what Im trying to transmit, yet PCAN is receiving the meassages not transmitting them.

Sign in to comment.

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!