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.

Matlab is not detecting serial port, the data is coming serially from AVR

Status
Not open for further replies.

ultraviolet_ray

Newbie level 6
Joined
Jul 8, 2011
Messages
11
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,375
I am trying to send an infinite sequence of charachters from AVR to PC, by using COM 1 and 2400 baudrate.
The hyperterminal sucessively shows the received charachters , but if I try to plot or visualise the result using MATLAb using COM1, an error appears saying:

??? Error using ==> serial.fopen
Port: COM1 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device.

I am using the following code:
Code:
%run('clean');
clear all;
close all;
 
s = serial('COM1'); %assigns the object s to serial port
 
set(s, 'InputBufferSize', 256); %number of bytes in inout buffer
set(s, 'FlowControl', 'hardware');
set(s, 'BaudRate', 2400);
set(s, 'Parity', 'none');
set(s, 'DataBits', 8);
set(s, 'StopBit', 1);
set(s, 'Timeout',10);
%clc;
 
disp(get(s,'Name'));
prop(1)=(get(s,'BaudRate'));
prop(2)=(get(s,'DataBits'));
prop(3)=(get(s, 'StopBit'));
prop(4)=(get(s, 'InputBufferSize'));
 
disp(['Port Setup Done!!',num2str(prop)]);
 
fopen(s);           %opens the serial port
int t =1;
disp('Running');
x=0;
for t = 1:200
 
   a =fread(s); %reads the data from the serial port and stores it to the matrix a
   a=max(a);  % in this particular example, I'm plotting the maximum value of the 256B input buffer
 
   x =[x a];  % Merging the value to an array, this is not very computationaly effective, as the array size is dynamic.
                 %Consider pre allocation the size of the array to avoid this. But beware, You might loose some important
                  %data at the end!
 
   plot(x);
   axis auto;
   grid on;
 
   disp([num2str(t),'th iteration max= ',num2str(a)]);
   hold on;
   t=t+1;
   a=0;  %Clear the buffer
   drawnow;
end
 
fclose(s); %close the serial port

I even closed the hyperterminal(incase the error is being generated because of the connection at hyperterminal), but I still get the same error.
 
Last edited:

You may try different com port, let say com3 if your pc have (check the device manager if it is windows)

Also you may run this command

Code:
delete(instrfind);
s = serial('COM3');
instrfind
fopen(s)
instrfind

then post the results as below

Code:
 Serial Port Object : Serial-COM3

   Communication Settings 
      Port:               COM3
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             closed
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0
 

   Serial Port Object : Serial-COM3

   Communication Settings 
      Port:               COM3
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             open
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0
 

You may try different com port, let say com3 if your pc have (check the device manager if it is windows)

Also you may run this command

Code:
delete(instrfind);
s = serial('COM3');
instrfind
fopen(s)
instrfind

then post the results as below

Code:
 Serial Port Object : Serial-COM3

   Communication Settings 
      Port:               COM3
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             closed
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0
 

   Serial Port Object : Serial-COM3

   Communication Settings 
      Port:               COM3
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             open
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0

unfortunately,my PC has only one working port, COM1.Instead of COM3, i tried it with COM1 :
Code:
delete(instrfind);
s = serial('COM1');
instrfind
fopen(s)
instrfind
and got the following results.(hyperterminal was closed during this operation)
Code:
Serial Port Object : Serial-COM1

   Communication Settings 
      Port:               COM1
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             closed
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0
 

   Serial Port Object : Serial-COM1

   Communication Settings 
      Port:               COM1
      BaudRate:           9600
      Terminator:         'LF'

   Communication State 
      Status:             open
      RecordStatus:       off

   Read/Write State  
      TransferStatus:     idle
      BytesAvailable:     0
      ValuesReceived:     0
      ValuesSent:         0

I tried to access hyper terminal and it says :
Another program is using selected telephony device.Try again after the other program completes
so , Matlab has access to the cOM1, but it still is not showing me any data , and the same error that COM1 is NOT AVAILABLE
 

Make sure that the antivirus/firewall software not blocked the matlab operations if you install such antivirus/firewall software.

Run only matlab program and check without opening or running other terminal program
 

hii friend, iam doing the same project as yours.trying to get the accelerometer data in matlab.can u please share some info ,pls send to my email id:lenin419@yahoo.com

---------- Post added at 14:22 ---------- Previous post was at 14:20 ----------

hii friend, iam doing the same project as yours.trying to get the accelerometer data in matlab.can u please share some info ,pls send to my email id:lenin419@yahoo.com.i am getting error that the com port to which accelerometer is mapped is not available.pls need ur help

---------- Post added at 14:24 ---------- Previous post was at 14:22 ----------

hey i am using an accelerometer eval board which is connected to pc throuch usb and data is transferred serially through virtual comport.but i am unable to access the comport in matlab,i am getting the same error which u got above .please i need ur help.
 

hii friend, iam doing the same project as yours.trying to get the accelerometer data in matlab.can u please share some info ,pls send to my email id:lenin419@yahoo.com

---------- Post added at 14:22 ---------- Previous post was at 14:20 ----------

hii friend, iam doing the same project as yours.trying to get the accelerometer data in matlab.can u please share some info ,pls send to my email id:lenin419@yahoo.com.i am getting error that the com port to which accelerometer is mapped is not available.pls need ur help

---------- Post added at 14:24 ---------- Previous post was at 14:22 ----------

hey i am using an accelerometer eval board which is connected to pc throuch usb and data is transferred serially through virtual comport.but i am unable to access the comport in matlab,i am getting the same error which u got above .please i need ur help.

Hey Tlenin, I tried to send the data to matlab serially , but wasnt lucky. I would have pondered more on the problem, but did not get enough time. But yes , i received data serially from the AVR controller and used hyperterminal to extract the incoming sequence to be used in our next process. You can try the same way if you like,but that might not help in case of realtime data input.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top