2

I am trying to increase the baud rate for serial communication to a microcontroller using Matlab and it seems Matlab does not want to cooperate. My very basic setup in Matlab is:

s = serial('/dev/tty.usbserial-A104VT0Q')
set(s,'BaudRate',256000)
fopen(s)

I get this error:

Open failed: BaudRate could not be set to the specified value.

This works fine (no error) if the baud rate is 115200 or a lower standard baud rate, but I get this error for higher standard baud rates of 128000 or 256000 (Matlab lists standard rates here) or for non-standard rates. Why is this happening and how can I set the baud rate higher?

If I set the baud rate from the microcontroller to 250000 and use the Arduino serial monitor at the same rate, it seems to work fine (can get successful serial communication of bytes), so I don't see that there is a hardware issue preventing this rate from being set. So I suspect this is some quirk of Matlab, but my searching online hasn't found a solution.

More about my setup: using an Atmel ATUC3C1512C MCU on a custom board, the USART is going through an FTDI FT232RL (rated for up to 3 Mbaud) to USB, into a Macbook Pro running OS X 10.11.6, running Matlab R2016a.

Again, the whole setup works at a baud rate of 115200, but I would like to increase the rate for the transmission of lots of data after a test is run and I can't figure out what's preventing me from setting it higher. Thanks.

thkemp
  • 121
  • 3
  • 1
    Try using a standard UART rate such as `230400`... – l'L'l Oct 25 '16 at 06:26
  • That seems to work! I actually found [this discussion](https://developer.mbed.org/forum/mbed/topic/893/?page=1#comment-4526) and tried the rates listed there. I can actually get it up to 921600 (8x faster than before). Forgive my ignorance, but what is driving these rates, is it a clock/oscillator in the MCU? Or the FTDI chip? Or something else? – thkemp Oct 25 '16 at 07:40
  • It's a combination of factors - and definitely the chip plays a major part of it. Generally if you stick to the standard rates though and have the proper bits set then you'll likely have fewer issues. :) good nfo here also: http://forum.arduino.cc/index.php?topic=98364.0 – l'L'l Oct 25 '16 at 07:44
  • One more thing you could try is taking it up to 1500000 ... – l'L'l Oct 25 '16 at 07:57
  • I am communicating with a 8-bit 8051 micro through an FTDI 232R at the speed of 3,000,000 and it works great. The settings of the UART on the MCU is indeed the hardest part to get right. I don't remember ever having the same error message than you though... – Hoki Oct 25 '16 at 08:43
  • @l'L'l - 1500000 doesn't work for me, I get the same `BaudRate could not be set to the specified value.` error as before. @Hoki - yes that's what I'd like to do, since my FTDI is rated for 3 Mbaud, but I seem to be limited by this error. Are you using Matlab for your communication? – thkemp Oct 25 '16 at 09:14
  • Well one of the reason could be that MATLAB does support the rate 256000 , but the COM port or USB port you are using does not support that baud-rate – Novice_Developer Oct 25 '16 at 09:22
  • @thkemp: That's what I was getting at — testing the limits of your controller with Matlab; for now `921600` is probably the limit. – l'L'l Oct 25 '16 at 11:23

0 Answers0