How to create a simulink block to receive/transmite a CAN message with the Arduino due (native CAN 0 and CAN1)?
조회 수: 2 (최근 30일)
이전 댓글 표시
I have been trying to create a simulink block with s-function to receive/transmite a CAN message from the Arduino due with its 2 CAN, but with no sucess. I also would like to use the CAN pack/unpack block to send the message via CAN, and sometimes I have tried to create the s-function and run the code I get an error related to the data type.
댓글 수: 1
답변 (1개)
Anshuman
2023년 5월 18일
Hi Alan,
Here are some general steps that you can follow to create an S-function block for sending and receiving CAN messages from an Arduino Due:
- Prepare the Arduino Due: You will need to have an Arduino Due board that is equipped with two CAN interfaces. You should also have a CAN transceiver that is compatible with the Due, and any necessary cables and connectors.
- Define the inputs and outputs: In your S-Function block, you will need to define the inputs and outputs that correspond to the messages you want to send and receive. For example, you might have an input for the message data, an input for the message ID, and an output for the received message data.
- Initialize the CAN interfaces: In your S-Function block's initialization function, you will need to initialize the two CAN interfaces on the Arduino Due. This may involve configuring the CAN bit rate, setting the message filters and masks, and enabling the interfaces.
- Implement the send function: In your S-Function block's send function, you will need to pack the message data into a CAN message and send it via the appropriate CAN interface on the Due. You can use the CAN pack block to help you with this step.
- Implement the receive function: In your S-Function block's receive function, you will need to wait for incoming messages on the appropriate CAN interface and unpack the received data into the output signals of your S-Function block. You can use the CAN unpack block to help you with this step.
- Test the S-Function block: Once you have created your S-Function block, you can test it by running a Simulink model that uses the block to send and receive CAN messages to/from the Arduino Due. You may need to adjust the bit rate and other settings to ensure that the CAN communication is reliable.
In terms of the errors you are encountering related to data types, you will need to ensure that you are using the correct data types and sizes for the inputs and outputs of your S-Function block. You can use the Data Type Assistant in Simulink to help you with this step, or manually specify the data types using the S-Function Builder tool. You should also ensure that you have the necessary include files and libraries in your S-Function block's source code to work with the CAN interfaces on the Arduino Due.
Hope it helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!