sending serial data from Arduino to simulink

1 次查看(过去 30 天)
Hi Every one
I am trying to send data from arduino to simulink through a serial receive block in simulink. I have written a simple code in arduin and created a simple simulink code for receiving serial data. I am using two arduino boards. First, I deployed the arduino code on the first one and then run the simulink code in external mode on the second one. The baud rate of port 1 which is used as transmitter in board 1 and as receiver in board 2, is 115200 and the time step is fixed to 0.01 in simulink code.
This is my arduino code:
void setup() {
Serial1.begin(115200);
}
void loop() {
Serial1 .write('2');
Serial.print('\n');
delay(10);
}
and bellow is a photo of the simulink code and the configuratin windws.
d1.png
what I gt after running this coded is that no data is shoen in dispaly windows. Both displat data nd status are zero.
I also tried it by changing the baud rate and sample time but the same result.
I would really appreciate if any one could help me to understand what I have done wrong!

回答(1 个)

Arun Kumar
Arun Kumar 2019-10-22
编辑:Arun Kumar 2019-10-22
Hi,
Can you try putting the display block in enabled subsytem triggered by Status output of Serial Receive block. I think the data is being received but you are not able to see because the Serial Receive block outputs 0 when no data is available to read. Since your data is coming every 100mS, most of the time, Serial receive block will output 0.
  2 个评论
elham modaresi
elham modaresi 2019-10-22
Dear Arun
Thanks for trying to help me. I put an enabled block like the below photo. but again nothing changed.
The step time is 0.1. I changed the baud rate to 9600. I also checked the baud rate of the corresponding com in my device manager to be 9600. It seems every thing is correct. I am really wondering what the problem is.
One thing more is that I used a usb2ttl cable to check if the board which is deployed by the arduino code is sending the data or not. I did received the data in HTerminal. So the first board is sending the data correctly. but the second one which is deployed by the simulink code seems not to receive it .
d1.png

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Modeling 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by