필터 지우기
필터 지우기

receive date from PIC to matlab via serial port

조회 수: 1 (최근 30일)
esra
esra 2013년 9월 6일
편집: Eslam gomaa 2015년 4월 2일
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
esra
esra 2013년 9월 6일
thanks i search in help of matlab about this function but the output was
Use the Help browser Search tab to search the documentation,
or type "help help" for help command options, such as help for methods.
Muthu Annamalai
Muthu Annamalai 2013년 9월 6일
Sorry, fflush is not available on MATLAB, right now.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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
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??!!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Search Path에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by