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.

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

5 Antworten zu Using Serial Adapters with Baudrates >230400 on OSX

  1. Onayv schreibt:

    thank you so much! I have been trying to set up communication for (UART 460800) board i need to test and my mac kept failing with SCREEN, thank for posting this! You saved me 30$ from buying a stupid fucking app that i KNEW i did not need! #SceincePrevials

    Gefällt 2 Personen

  2. direcs schreibt:

    Perfect! Thanks for this solution/post!!

    Gefällt 1 Person

  3. Daniele Testa schreibt:

    This does NOT work! The screen command returns „resource busy“ because the stty command is locking the port.


    • stefand986 schreibt:

      Well, it worked „back then“. I didn’t try it in a while, so maybe behavior changed in later versions of OSX.

      You could try whether they fixed the root cause (that OSX resets the terminal settings automatically): try whether the selected baudrate is correctly set if you execute stty and screen sequentially (‚&&‘ instead of ‚&‘).

      BTW it could also be that the device is busy because of the system service that resets the settings (the root cause of the issue)


Kommentar verfassen

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

Du kommentierst mit Deinem Abmelden /  Ändern )

Google Foto

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


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


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

Verbinde mit %s