Serial Communication between Simulink and microcontroller is not working

7 ビュー (過去 30 日間)
Will Roy
Will Roy 2017 年 7 月 31 日
コメント済み: windsnow 2023 年 4 月 28 日
I try to make a functioning Serial communication between Simulink and my MCU.
I want to make a Simulink Simulation in which I will send data to my Arduino Mega and receive from it calculated data back.
For now I just made a Simulink Model to test the Serial communication.
---
I do not need help in the Arduino-side of this, I need help in the Simulink side where I am a beginner. My Arduino program is working correct, tested with 2 serial monitors.
My Arduino program reads any incoming data from Serial0 and sends it to Serial1 and reads any incoming data from Serial1 and sends it to Serial0.
Serial0(Arduino-USB, COM24) is connected to the computer and is used inside Simulink. Serial1 is connected to a Serial-to-USB adapter(COM3) and is watched at with a serial monitor.
My Arduino code:
void setup() {
Serial.begin(9600);
Serial.setTimeout(500);
Serial1.begin(9600);
Serial1.setTimeout(500);
}
void loop() {
if (Serial.available()) {
Serial1.write(Serial.read());
}
if (Serial1.available()) {
Serial.write(Serial1.read());
}
}
The Problem
When I open both Serials in 2 serial monitors everything works perfect and I can send and receive from both ports. But with Simulink nothing works. I can not send data from COM3 to Simulink and not from Simulink to COM3.
In Simulink I have a model to test the serial communication with the Arduino. I am new to Matlab and Simulink. I try to send and receive chars/bytes. Because it is too difficult to post here all the block configurations I did upload my simulink model, you can download it from here.
Any type of help, tips and comments are welcome.
  1 件のコメント
windsnow
windsnow 2023 年 4 月 28 日
Have you solved the problem? I had the same problem.

サインインしてコメントする。

回答 (2 件)

Nguyen Huy
Nguyen Huy 2018 年 10 月 10 日
Can you send me the simulink file. I can't download it. Thanks

Nguyen Huy
Nguyen Huy 2018 年 10 月 10 日

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by