Serial Communication between Simulink and microcontroller is not working

9 views (last 30 days)
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.

Answers (2)

Nguyen Huy
Nguyen Huy on 10 Oct 2018
Can you send me the simulink file. I can't download it. Thanks

Nguyen Huy
Nguyen Huy on 10 Oct 2018

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!