receive date from PIC to matlab via serial port
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Walter Roberson
le 6 Sep 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 commentaire
Eslam gomaa
le 2 Avr 2015
Modifié(e) : Eslam gomaa
le 2 Avr 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??!!
Voir également
Catégories
En savoir plus sur Search Path dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!