Using Serial Adapters with Baudrates >230400 on OSX

The Problem

For the project I am currently working I have a development board with a FTDI 2232 serial to USB adapter to connect to it. The Baudrate is set to Baudrate of 460800. This is not a problem on Linux and Windows. But if you are using OSX and open the serial device with a baudrate over 230400, it falls back to 9600 baud. (Up to 230400 all baudrates work fine)

I investigated already a bit into this, and the problem occurs independently of the program that you use to open the terminal. I tried GNU screen, and a couple of others.

I even tried to use other drivers, in my case the drivers provided by FTDI (stock OSX provides its own drivers for most serial converters). But this still didn’t help.

All combinations of serial terminal clients and drivers „pretend“ to open the device at 460800 baud, but if you look at the signals with an oscilloscope or logic analyzer you see that in reality it is only 9600.

The solution I found involves the commandline program stty, which can be used to set (among other options) the Baudrate of TTYs on Unix systems. stty opens the serial port device, and sets the new baudrate. However there is one tricky part left: OSX resets the baudrate after stty exits!! But I found a solution here

TL;DR: The Solution

stty -f /dev/cu.usbserial-141A 460800 & screen /dev/cu.usbserial-141A 460800

Explanation: The first part (before the &) sets the baudrate for the terminal. The & sends the stty process to the background. The second part opens the serial terminal, while stty is still in the background. There is a small time frame after stty exits where OSX did not reset the baudrate yet, and this is used to connect to it with the correct baudrate.

Advertisements
Dieser Beitrag wurde unter Allgemein veröffentlicht. Setze ein Lesezeichen auf den Permalink.

Kommentar verfassen

Trage deine Daten unten ein oder klicke ein Icon um dich einzuloggen:

WordPress.com-Logo

Du kommentierst mit Deinem WordPress.com-Konto. Abmelden / Ändern )

Twitter-Bild

Du kommentierst mit Deinem Twitter-Konto. Abmelden / Ändern )

Facebook-Foto

Du kommentierst mit Deinem Facebook-Konto. Abmelden / Ändern )

Google+ Foto

Du kommentierst mit Deinem Google+-Konto. Abmelden / Ändern )

Verbinde mit %s