Title: Setting a Custom Baud Rate in Linux (2.6.x Kernel)
Keywords: Baud Rate, baudrate, custom baudrate, stty, setserial
Date: October 9, 2007
KDB: KDB-309
Revision: 0.00
Author: GRV
Distribution: External
When using a serial port with the Linux serial module 8250, you are usually limited to the predefined baud rates in the driver. If you are using a serial card with a non-standard clock, most applications will not be able to use the non-standard baud rates without some modifications. Here are some steps to use for a quick and easy way to get around this.
Determine what clock speed your serial card is using. Divide this speed by 16 (UART samples 16 clock pulses), this will be your “base baud” as it is the highest baud rate achievable.
Here is an example on how to set a baud rate of 500,000 bps using our XP014 serial card (Xtreme/104-Plus 8 port RS-232/422/485). This card has a 48 MHz clock installed.
# setserial /dev/ttyS# Baud_base 3000000 // 48,000,000 divided by 16
# setserial /dev/ttyS# spd_cust // turns the spd_cust flag ON
# setserial /dev/ttyS# divisor 6 // spd_cust will use a divisor of 6
3,000,000 divided by 6 equals 500,000
spd_cust is a special flag used by setserial. It uses the baud rate defined by “Baud_base” divided by “divisor” whenever a baud rate of 38400 bps is called in the application.
In this example, whenever you set the baud rate to 38400, the actual baud rate will be 500,000 bps.
End of KDB-309