Filter löschen
Filter löschen

Serial Communication between Simulink and microcontroller is not working

3 Ansichten (letzte 30 Tage)
Will Roy
Will Roy am 31 Jul. 2017
Kommentiert: windsnow am 28 Apr. 2023
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.

Antworten (2)

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

Nguyen Huy
Nguyen Huy am 10 Okt. 2018

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by