receive date from PIC to matlab via serial port
이전 댓글 표시
hi
i have some problem i connect matlab code with PIC16F874A micro_control , i need to sent 2 hex number from PIC to matlab (becouse PIc only work with hex number),
this number will active the matlab code in matlab code I open connect between PIC and computer via serial port
_______________________
if true
%%open connect
ess=serial('COM3');
set(ess,'BaudRate',9600);
fopen(ess);
fread(ess)%to read data came from PIc
x=hex2dec(fread(ess))
________________________________
above code (fread)to read data from PIC
but when run the matlab code output ====>
Warning: The specified amount of data was not returned within the Timeout period.
ans =
Empty matrix: 1-by-0
Warning: The specified amount of data was not returned within the Timeout period.
x =
[]
please i need help
sorry for bad English
댓글 수: 3
Muthu Annamalai
2013년 9월 6일
did you try,
fflush(ess)
to flush out the buffers?
esra
2013년 9월 6일
Muthu Annamalai
2013년 9월 6일
Sorry, fflush is not available on MATLAB, right now.
답변 (1개)
Walter Roberson
2013년 9월 6일
Set the terminator mode to byte. Unless, that is, the PIC is sending a CR or LF after the two bytes, in which case leave the fcn mode as terminator and set the serial port Terminator property as appropriate.
Do not just fread() against the port: that is going to try to keep reading until end of file or the buffer is full or terminator is encountered. You didn't set a buffer size and you didn't mention there being any terminator so you would be reading until the port closed or until the buffer of default size was reached.
[h, count] = fread(ess, 2, 'uint8=>char');
if count < 2
%uh oh, end of file or timeout
else
x = hex2dec(h);
end
댓글 수: 1
Eslam gomaa
2015년 4월 2일
편집: Eslam gomaa
2015년 4월 2일
hi
I try to recieve data from pic to matlab but I send character in pic code I know i will Set the terminator mode to byte.but which fn to get that data, is fread or fscan or else?? it showed me there is a problem in timeout what about time out??!!
카테고리
도움말 센터 및 File Exchange에서 Variables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!