Serial communication error between mbed and MATLAB
3 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Instrument Control Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!