Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Maximum Serial Port Baud rate in Matlab 7.0.0.19920(R14)

178 views
Skip to first unread message

abu

unread,
Oct 28, 2010, 1:27:03 AM10/28/10
to
Dear All,

I am using usb to serial port devices for serial port access. These devices support data rates at 230400, 460800 and 921600 etc. Serial port works OK up to 460800 in matlab. however I get strange charters at 921600. There is no problem if I open serial port in windows HYPER TERMINAL. Does it mean Matlab doesn't support the speed in my version [Matlab 7.0.0.19920(R14)].

I am using serial port in matlab command prompt.
Regards,

Abu Bakar

Trent Jarvi

unread,
Oct 28, 2010, 12:15:20 PM10/28/10
to

"abu " <mab...@gmail.com> wrote in message
news:iab1j7$84d$1...@fred.mathworks.com...


Hi Abu,

Hyperterminal reads and displays the data instantly. MATLAB will buffer 512
bytes by default and then the serial port will be overrun if the data is not
read by you in time.

You may try using hardware flow control which will throttle the data when
its not read in time. Another possible solution is increasing the input
buffer size to prevent overruns. Small byte by byte reads would be a bad
idea at those baudrates. If you are doing binary transfers, use FREAD with
the terminator set to ''. This will prevent scanning of the data which can
slow you down.


abu

unread,
Oct 28, 2010, 7:19:04 PM10/28/10
to
Dear Trent Jarvi

Thanks for your valuable suggestions. Actually I am facing this problem while transmitting data from Matlab to HT. I have just found that there is no problem in Matlab-Matlab transmission too, at 921600 baud. I am using fread and fwrite like this:

fwrite(tx,data,'uchar');
rxData=fread(rx,dataLen,'uchar');

tx and rx => serial port objects
data, dataLen > transmission data and its length

Actually what I am intending to do is that there is a large binary 8-bit data. I want to transmit and receive it over optical link. Then compare original data with received stream. Compare the two and calculate errors/mismatches. I can do it with writing and reading one byte at a time but it would take a long time as you have observed. *Also I can not implement hardware flow control as there is just one channel.

I am getting strange results while transmitting more than 50 bytes using fwrite. Sometimes an error message would pop up, at others the received stream is circular shifted so that starting and ending in middle. It is problematic for byte versus byte comparisons. I am not defining a terminating character, just telling fread to wait for certain number of bytes.

Regards,

Abu Bakar

Trent Jarvi

unread,
Oct 29, 2010, 6:20:03 PM10/29/10
to

"abu " <mab...@gmail.com> wrote in message
news:iad0d8$s00$1...@fred.mathworks.com...

Hi Abu,

Just on clarification. When you say that you are not defining the
terminating character, that actually means one is set for you (new line).

For performance while using FREAD, you want to set the termintor to ''.

s=serial('com1')
s.Terminator=''
...

This gives a hint to the serial object that you are not interested in using
terminators which avoids some - performance wise - expensive byte by byte
comparisons.


0 new messages