Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

programming code for matlab_serial(RS-232) communication

Status
Not open for further replies.

jyothi1

Junior Member level 1
Joined
Sep 24, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Anantpur, A.P
Activity points
1,614
HI sir,
right now I doing speech recognition robot project.For that I am learning Matlab I am very new to this subject.I want to write program for serial communication in matlab.Actually I have written program. but I am getting an error as (??? Error using ==> serial.serial at 62
The PORT must be specified.).
In my program I used comport. Even though that error is coming.My program is as below.


s = serial('COM2');
fopen(s)
printf(s,'RS232?');
data1 = fscanf(s);
data = 9600;0;0;NONE;LF
C = textscan(a, '%d%d%d%s%s','delimiter',';');

[br, sfc, hfc, par, tm] = deal(C{:});

fclose(s)

I tried, but I did n't get where I did mistake.Can anybody please help me.

Thanks,
Jyothi.
 
Last edited:

you may try this example code (assumed baud rate=9600)

Code:
s = serial('COM2'); 
set(s,'BaudRate',9600);
fopen(s);
tx='RS232?';  
fprintf(s,'%s',tx);
data1 = fscanf(s)
...
...
fclose(s)
 
HI sir,
thank you very much for responding my question.I tried sir, I got output.
Once again thank you sir.:smile:

Actually I am working on speech recognition Pick and place robot.If I will stuck I will ask you the questions.Hope you will clarify it.:smile:

Thanks and regards,
Jyothi.P.
 

Yes you can post your questions in relevant forum here and you'll have possible answers for them
 
Hello sir Gud nun,
Actually In my speech recognition pick and place robot project,
If any person can speek any word like move farward/backward/left/right.
It need to move.First of all In matlab we need to convert some words in to digital one and It should compare with predefined words.If it will match then we need to send that command to microcontroller(8051) through serially.
According to that command motors in pick and place robot should move.
Actually I have completed controller work.I need to send commands serially to microcontroller through matlab software.
Here my doubt is I am comparing some x values with 1,2,3,4,5then according to that I am displaying some messages.
I applied now serial com port(matlab).Please check whether it is correct are not.
Can you please help in How to send commands through serially in matlab.Ans please mention In matlab what is send command and receive command as same as in controller. My code(matlab) is as below
clc;
s=serial('COM2');
fopen(s);
r = fscanf(s);
while(1)
r=input('enter 1-farward;2-backward;3-left;4-right;5-stop');
% switch(r)
% case 1
% disp('motors are in backward');
% case 2
% disp('motors are in farward');
% otherwise
% disp('motors stop');or by using ifelse
if r==1
disp('motors in farward');
elseif r == 2
disp('motors are in farward');
elseif r==3
disp('motors are in left');
elseif r==4
disp('motors are in right');
elseif r==5
disp('motors are in stop condition');
end
end
fclose(s);
 

Hi sir,
Thank you for sending me this code sir.but I stopped that project there only. because my manager told to work on another project, right now I am working on CAN controller interfacing with lpc2366 and controlling of dc motors.I am trying to write protocol sir.If I will get any doubt I will ask you sir.:)

Thanks and regards,
Jyothi.P
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top