Serial communication with microcontroller: receiving garbage values
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi everyone,
I am trying to establish a communication between MATLAB and a microcontroller using the serial port. Every 1 second I send a string encoded with a variable name and the microcontroller should respond by giving the value stored in it.
I tested the C code of the microntroller using putty software and it sends the correct data. But when I use MATLAB I dont get any values. If I change the C microcontroller code to respond to just one character input from the string in MATLAB then I receive the value once in every 3 attempts. But for more than one character string input I dont get anything.
I tested the C code to check the received buffer with itself and transmit the received string. In this case only the first character is what I had sent and the remaining are garbage values.
Any suggestions what I might be doing wrong? My MATLAB code is as follows:
clc
clear all
s = serial('COM8','baudrate',115200);
set(s, 'InputBufferSize', 13);
fopen(s);
while(1)
pause(1);
disp('tx and rx');
//commented// fprintf(s,'ckpp');
fwrite(s,'ckpp');
b=fread(s);
//commented// b=fscanf(s);
end
fclose(s);
Thanks!
댓글 수: 2
Walter Roberson
2016년 7월 28일
MATLAB does not permit the use of // commenting, so you must be using some language other than MATLAB.
Walter Roberson
2016년 7월 28일
For any data rate over 9600, you should be setting hardware flow control, unless perhaps you are using a serial to USB convertor. Serial to USB convertors have their own challenges, however.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Inputs에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!