Trying to get serial data from AWR6843AOPEVM

1 Ansicht (letzte 30 Tage)
Vinoth Kumar Chandrasekaran
Vinoth Kumar Chandrasekaran am 30 Apr. 2024
Beantwortet: Gojo am 12 Mai 2024
Hi,
I'm using TI radar AWR6843AOPEVM, trying to get the serial data in matlab using below code.
s= serialport("COM5", 921600, 'DataBits',8);
fid=fopen("seriallog.txt",'a');
while(true)
data=readlines(s,200,'string')
fprintf(fid,data);
end
But When i connect this board with arduino IDE it directly display the data in serial monitor.

Antworten (1)

Gojo
Gojo am 12 Mai 2024
Hi Vinoth,
I have a few suggestions.
The "readlines" function is probably used for reading from a file. You can check the documentation for "readlines" function here: https://www.mathworks.com/help/matlab/ref/readlines.html
For reading data from a serial port, try using "read" or "readline" functions as illustrated in the following documentation: https://www.mathworks.com/help/matlab/import_export/write-and-read-serial-port-data.html
You can try exeption handling to verify if everything is working as desired.
Also, since the "readline" function returns data as a string, you need to adjust the format specifier in "fprintf".
s = serialport("COM5", 921600, 'DataBits', 8);
fid = fopen("seriallog.txt", 'a');
% Check if the file was opened successfully
if fid == -1
error('Failed to open file for writing.');
end
try
while true
data = readline(s);
disp(data);
fprintf(fid, '%s\n', data);
end
catch ME
disp(ME.message);
end
% Close the serial port and the file
delete(s);
fclose(fid);
I would also suggest to use available callback functions as shown in the following documentation: https://www.mathworks.com/help/matlab/import_export/use-events-and-callbacks-for-serial-port-communication.html
You may also find the following MATLAB Answers relevant:
I hope this helps!

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by