Serial communication error between mbed and MATLAB
4 次查看(过去 30 天)
显示 更早的评论
I have a code to send data serially from mbed(LPC1768) to MATLAB(2018a). mbed reads the connected GPS values and being sent to MATLAB continuously.
Iam using the following line,
printf("%lf,%lf,%lf,%lf\n", easting, northing, speed_main, heading_main); to send data from mbed. (this is inside a continously running while loop).
while data not available from gps I have set the 'easting, northing, speed_main, heading_main' variable values to zero.
At MATLAB end am reading it inside a while loop which is running continuously. Am able to read data correctly from MATLAB end for few iterations but going forward it throws error as follows ."Matching failure in format. The format specified for conversion, '%f, %f, %f, %f', is incorrect". Why it is happening? any solution to read it every iterations without error? is this a timing issue? I tried with different delays 0.1, 0.2 sec etc at both end but not solved? (GPS, mbed to pc baud are also set to same baud rate 9600.)
MATLAB end code
while(true)
mbed = serial('COM7', ...
'BaudRate', 9600, ...
'Parity', 'none', ...
'DataBits', 8, ...
'StopBits', 1);
fopen(mbed);
pause(0.5);
values = fscanf(mbed, '%f, %f, %f, %f');
fclose(mbed);
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!