Anda di halaman 1dari 5

MATLAB Answers

Vote
0

Is it possible to use serial communication with Arduino


thanks to a baudrate upper than 9600 ?
Asked by mathieu giraud on 30 Jun 2015
Latest activity Commented on by mathieu giraud on 6 Jul 2015
45 views (last 30 days)

Good afternoon everyone, I have to send an important amount of data thanks to the serial
communication, from Matlab to an Arduino mega. ( For your information : I have to send 500 bytes of
data to refresh a 3D Cube. And this must be done at least 24 times per seconds for visual perception.
This is the simple version. In fact, I would like to refresh the 3 colours of each Leds in my cube,
namely I have to send 500*3*24 bytes per second.).

Thus, I need to send 500*24 = 12000 bytes per second ( if a data frame has 1 start bit and one stop
bit, it means I need a baudrate = 500*(8+1+1)*24 =120000 bps.

So the issue is that i made some test with 'tic' and 'toc'. Before 9600 bps, everything is ok, the more
the baudrate is, faster is my communication. But if I try an other usual bit transmit rate ( 14400 for
instance), nothing changes : it cannot go faster than with 9600. And this is the case for each transmit
rate upper than 9600.

I changed the transmit rate on The Arduino too.

Do you know why and how can I modify this "limit" ? Or do you know how can I send data as fast as I
want to ?

2 Comments


Walter Roberson on 30 Jun 2015

Is it a real serial port, or is it serial over USB ?


mathieu giraud on 1 Jul 2015
MATLAB Answers
No, I'm

using the serial over USB on the Mega ( pin RX0 ). As an example, this is my
matlab code :

s=serial('com4','baudrate',9600);
fopen(s);

tic
for a=1:50
fwrite(s,'a','char');
end
toc
fclose(s);
delete(s);
instrreset;

In both case ( BAUD = 9600 or 115200), I got the same result for tictoc : Elapsed time is
0.052218 seconds ( with some variations ).

Log in to comment.

Tags
arduino serial baudrate 9600 transmit speed

Products
MATLAB and Simulink Student Suite

Related Content

1 Answer
MATLAB Answers

Vote
0
Link
Answer by Walter Roberson on 2 Jul 2015
Edited by Walter Roberson on 2 Jul 2015

Serial over USB does not pay attention to baud rate for the USB portion of the transmission. The USB
portion carries the data as fast as USB can. If the data is never converted to a real serial port, then the
baud rate is more or less decoration. The USB driver on the receiving end would need to buffer the
data for a physical serial port at the destination.

However, serial over USB is defined by the standards to require buffering of data until either the USB
packet is full (taking into account the couple of overhead bytes used to communicate the virtual pin
status such as DTR), or until a timeout has occurred. As long as data is still being received, the
timeout will keep getting postponed; if you come one byte of filling up the USB packet it will wait for the
timeout before sending the packet. I have posted different figures for the timeout period in the past,
and I seem to be having difficulty now in finding an official source. I believe you are seeing the effect of
the timeout.

The USB protocol does define a "Push" request to trigger the driver to send the packet in the next
available slot instead of waiting for the packet to fill. Unfortunately MATLAB does not provide any
mechanism for requesting a push.

I know I read about all this before but right now I am having difficulty finding the reference information :
(

If you are being affected by the wait for the buffer to fill, then there should be a magic value
somewhere near 1000 bytes where the time required suddenly decreases, due to exactly filling the
packet.

5 Comments

Show 2 older comments



mathieu giraud on 2 Jul 2015
MATLAB Answers
In any case, I have to tranmit at least 120kbps, so it seems to be the only solution. I have

looked for other way to transmit
data such Ethernet for instance, but it uses the MOSI pin,
and I already need this one.


Walter Roberson on 2 Jul 2015

It is not a magic transmit rate, it is a magic data size being sent. Where you have

tic
for a=1:50
fwrite(s,'a','char');
end
toc

there should be a magic size such as 510 or 512 or 998 or 1022 where suddenly the
latency drops due to the packet being full and flushed immediately.


mathieu giraud on 6 Jul 2015

Finally, I've just succeeded to send my data fast enough. You can use Arduino at
512000bauds. The issue is that Matlab (or USB protocol as you said) waits around 1 ms
before sending a fwrite . Insted of sending one uint8, wait 1 ms, sending an other; I send
64 bytes, wait a little, send 64 bytes ... etc.

So my communication is 64 times faster, which is enough. Thank you for your help !

Log in to comment.

Log in to answer this question.


MATLAB Answers
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB can do for your career.


Opportunities for recent engineering grads.

Apply Today

MATLAB Academy
New to MATLAB?

Learn MATLAB today!

1994-2017 The MathWorks, Inc.

Anda mungkin juga menyukai