Serial Communication between Simulink and microcontroller is not working
3 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/166442/image.png)
Any type of help, tips and comments are welcome.
回答(2 个)
另请参阅
类别
在 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!