Controlling serial ports in Linux

From RidgeRun Developer Connection

Revision as of 14:38, 11 June 2012 by Tfischer (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to:navigation, search

Introduction

Built-in serial ports in embedded Linux devices typically show up as

/dev/ttyS0
/dev/ttyS1

You can configure the serial port using the Busybox stty command.

Configuring baudrate

Here is the stty command I use to set the baud rate:

serial_port=/dev/ttyS0
baud=9600

stty -F $serial_port $baud intr ^C quit ^D erase ^H kill ^U eof ^Z eol ^J start ^Q stop ^S -echo echoe echok -echonl echoke -echoctl -istrip -icrnl -ocrnl -igncr -inlcr onlcr -opost -isig -icanon cs8 -cstopb clocal -crtscts -ixoff -ixon -parenb -parodd -inpck

To test the changed baudrate, on a host PC I use picocom.

picocom -b 9600 -r -l /dev/ttyUSB3

where /dev/ttyUSB3 is my host's serial port (via a USB RS-232 dongle).

Navigation
Toolbox