0

Hi everybody !
I have to sent a big amount of data on the serial port (from Matlab to Arduino) as fast as possible ( for on live application). In order to do that, I have changed my baudrate. On the oscilloscope, no problem ( even if I send at 1Mbps) : one bit 'lasts' during 1/1000000 second. Nevertheless, the gap between two bytes sent with matlab is still the same ( around 1 ms).

Do you know how to decrease this time ?

This is an example of the code I use to test :

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


  for i=1:508
      fwrite(s,aEnvoyer(i,1));  
  end
fclose(s);

I have already tried to modify BytesAvailableFcnMode or InputBufferSize, without any success.

Thanks !

MathG38
  • 1
  • 1
  • 1
    How do you send? Please provide the code. – Daniel Jul 03 '15 at 12:22
  • Yes, I have added an instance of code in the main message. To be more accurate. I want to send 508 'uint8' , 24 times per second. The time between two 'fwrite' is around 1.2 ms, this means I have to wait more than 500 ms to send one time my 508 uint8. – MathG38 Jul 03 '15 at 12:33
  • In fact, after several research, I realize It could be possible to send a bigger data pack. Instead of sending 1 uint8 per 1uint8, I can send a vector of 64 uint8 ( size oh the Arduino buffer). But what if the microcontroller has a little buffer ? – MathG38 Jul 03 '15 at 12:41
  • 508x`uint8`=4064 bits ... x24 = 97,536 bits per seconds ... you'll never pack that many bits with a serial port speed of `9600bps`. Start by increasing that. As you found out yourself, you can send _packets_ instead of doing it a single byte at a time, but you'll have to know the size of the buffer on the other end. The code on the Arduino will also have to know in which way you are sending your packets in order to decode them properly. – Hoki Jul 03 '15 at 14:45
  • I knew this baudrate was not enough, the problem was I didn't know why I couldn't go faster even if I increased my baudrate. Indeed, each call to _fwrite_ need a delay before the next one. And this happens whatever the baudrate. But I have just succeeded to send the datas as I wanted to. I send 64 bytes per _fwrite_, and receive them on my Arduino. I still have some issues with the way Arduino '' understands'' my command ( Leds light on even I told them to light off), but I may have done some mistakes in my code. Thanks for your help ! – MathG38 Jul 06 '15 at 08:34

0 Answers0