receive date from PIC to matlab via serial port
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Walter Roberson
el 6 de Sept. de 2013
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 comentario
Eslam gomaa
el 2 de Abr. de 2015
Editada: Eslam gomaa
el 2 de Abr. de 2015
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??!!
Ver también
Categorías
Más información sobre Search Path en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!