help with Matlab and serial communication
erick_2987
Posts: 11
hi all,
i am trying to establish a serial communication with my bs2p and matlab. Here is my bs code:
*************************************************
' Variables
test VAR Word
'**********************
' Main Program
test = 6
Main:
SEROUT 16,2400,[DEC test, CR]
PAUSE 250
GOTO Main
END
***********************************************************
and my matlab code:
***************************************************************************************************
s = serial('COM3','BaudRate',2400,'DataBits',8,'Parity', 'none', 'FlowControl', 'none');
s.terminator = 'CR';
s.ReadAsyncMode = 'manual';
fopen(s)
s_scan = fscanf(s,'%d\n');
s_get = fgetl(s);
s_read = fread(s);
fclose(s);
********************************************************************************************************
when i execute the program, the output from the matlab is:
Warning: A timeout occurred before the read operation completed.
Warning: A timeout occurred before the read operation completed.
Warning: The specified amount of data was not returned within the Timeout period.
meanwhile the debug window in bs2 gives me:
i am trying to establish a serial communication with my bs2p and matlab. Here is my bs code:
*************************************************
' Variables
test VAR Word
'**********************
' Main Program
test = 6
Main:
SEROUT 16,2400,[DEC test, CR]
PAUSE 250
GOTO Main
END
***********************************************************
and my matlab code:
***************************************************************************************************
s = serial('COM3','BaudRate',2400,'DataBits',8,'Parity', 'none', 'FlowControl', 'none');
s.terminator = 'CR';
s.ReadAsyncMode = 'manual';
fopen(s)
s_scan = fscanf(s,'%d\n');
s_get = fgetl(s);
s_read = fread(s);
fclose(s);
********************************************************************************************************
when i execute the program, the output from the matlab is:
Warning: A timeout occurred before the read operation completed.
Warning: A timeout occurred before the read operation completed.
Warning: The specified amount of data was not returned within the Timeout period.
meanwhile the debug window in bs2 gives me:
Comments
MAtLab
Command Window
The result is 54 or 0x36 which is ASCII for 6.
Not following you.
Did you try the code and it didn't work? Make sure you update the COMxx port in MatLab.
What is 240? 2400 baud?
1021 equals 2400 baud in the BS2p SEROUT command. See basic stamp help.
Open mode