Difference between revisions of "RS-232"

From Noah.org
Jump to navigationJump to search
m
Line 259: Line 259:
 
| <br>
 
| <br>
 
|}
 
|}
 +
 +
== Common speeds ==
 +
 +
<pre>
 +
  110
 +
  150
 +
  300
 +
  600
 +
  1200
 +
  2400  3000 feet
 +
  4800  1000 feet
 +
  9600  500 feet  "This is the most commonly used speed."
 +
19200    50 feet
 +
38400
 +
56000
 +
57600
 +
115200
 +
</pre>
  
 
== using screen as a serial terminal ==
 
== using screen as a serial terminal ==

Revision as of 16:43, 23 November 2010

RS-232

RS-232 is the serial communications protocol that won't die. It's been around since the 60's.

RS-232 is also known as RS232, RS-232-C, RS-232-D, EIA-232, TIA-232E, TIA-232-F -- and even V.28/V.24. These standards are not identical, but RS-232 will get you close to what you want. In theory, the RS-232C standard only specifies the signaling, not how you actually wire it up. The pinouts given in this article are common.

The RS-232C standard requires the transmitter to use +12V (0, logic low) and -12V (1, logic high). The receiver needs only see over +3V and under -3V. Most transmitting ports use only +5V and -5V. Those levels are compatible with most devices and host computers. Maxim is one of the more popular suppliers of RS-232 level shifters or level converters.

DE-9 pinout (AKA: D-sub9, TIA-574, DE-9, DB-9, and DB9)

diagram of a DE-9 connector

Technically this connector is called a D-sub 9 or a DE-9, but it is often incorrectly referred to as a DB-9. The D refers to the shape of the connector. The E specifies the size of the connector shell. I'm not sure why you couldn't just get that from the number of pins, but whatever...

DE-9 (DB-9) connector
facing you
 1 2 3 4 5
  6 7 8 9

DB-25 pinout

diagram of a DB-25 connector

The D specifies the shape of the connector. The B specifies the size of the connector shell. Note that DB-25 may carry two RS-232 lines, but this is rare.

DB-25 connector facing you
 1   2   3   4   5   6   7  8   9  10  11  12  13

  14  15  16  17  18  19  20  21  22  23  24  25

5-wire RS-232

This is the most common RS-232 connection wiring. It consists of data and hardware flow control lines: TxD, RxD, SGND, RTS, and CTS.

pins 3,2,5,7,8 on DE-9
pins 2,3,7,4,5 on DB-25

line DE-9 pins DB-25 pins
TxD 3 2
RxD 2 3
SGND 5 7
RTS 7 4
CTS 8 5

3-wire RS-232

A minimal 3-wire RS-232 connection wiring. It consists only of TxD, RxD, and SGND. You see this a lot in embedded systems.

pins 3,2,5 on DE-9
pins 2,3,7 on DB-25

line DE-9 pins DB-25 pins
TxD 3 2
RxD 2 3
SGND 5 7

RS-232 DB-25 to DE-9 pinout table

DB-25
DE-9
line
description
direction
DTE is the computer
DCE is the device
1

shield
ground shield

2
3
TxD
Transmit Data
OUT: DTE -> DCE
3
2
RxD
Receive Data
  IN: DTE <- DCE
4
7
RTS
Request To Send
OUT: DTE -> DCE
5
8
CTS
Clear To Send
 IN: DTE <- DCE
6
6
DSR
Data Set Ready
 IN: DTE <- DCE
7
5
SGND
signal ground
< - >
8
1
DCD
Data Carrier Detect
 IN: DTE <- DCE
9




10




11




12




13




14




15




16




17




18




19




20
4
DTR
Data Terminal Ready
OUT: DTE -> DCE
21




22
9
RI
Rind Indicator
 IN: DTE <- DCE
23




24




25




Common speeds

   110
   150
   300
   600
  1200
  2400  3000 feet
  4800  1000 feet
  9600   500 feet  "This is the most commonly used speed."
 19200    50 feet
 38400
 56000
 57600
115200 

using screen as a serial terminal

Screen makes a very good RS-232serial terminal. You can connect a screen window to any serial device in /dev. Most serial devices in linux are named like /dev/ttyS0 and /dev/ttyS1 for a built-in RS-232 port; or for USB-to-RS-232 adapters the names are usually like /dev/ttyUSB0 and /dev/ttyUSB1.

The communication settings are a comma separated list of control modes as would be passed to `stty`. See the man page for `stty` for more info. The most common settings are 8N1 (8-bits per character, no parity, and 1 stop bit). The most common speeds are 9600, 19200, 115200 baud. The serial console on a lot of network equipment uses 9600 baud. A lot of people like to run serial consoles at 115200 because it makes the terminal feel more responsive and zippy. The downside of using this speed is that 115200 can be noisy. I usually settle on 19200. It's good enough and gives a more more reliable and consistent connection. 9600 baud is the most common default speed used in a lot of networking and server equipment. This speed is just barely tolerable for editing with vi or watching displays being updated periodically from tools like `top` or `kismet`.

Old, slow-speed serial devices usually like 9600 8N1 (9600 baud, 8-bits per character, no parity, and 1 stop bit):

The Coyote Point E450si load balancer manual calls for the following settings:

screen /dev/ttyS0 9600,cs8,-parenb,-cstopb,-hupcl

*9600 baud
*8 data bits
*no parity
*one stop bit
*VT100 terminal emulation
*ignore hang-ups (if supported); this allows a single terminal session to continue running even if Equalizer restarts.

These settings are for the serial console of an embedded computer board (115200 8N1):

screen /dev/ttyS0 115200,cs8,-parenb,-cstopb,-hupcl

Linux serial TTY communications -- stty

This section shows various ways to watch the serial ports to see what is going on with the signals.

/proc/tty/driver/serial

watch -n 1 cat /proc/tty/driver/serial

Every 1.0s: cat /proc/tty/driver/serial                 Tue Nov 17 11:39:23 2009

serinfo:1.0 driver revision:
0: uart:16550A port:000003F8 irq:4 tx:334 rx:214898 fe:2636 brk:254 RTS|DTR
1: uart:16550A port:000002F8 irq:3 tx:181 rx:12 RTS|CTS|DTR
2: uart:unknown port:000003E8 irq:4
3: uart:unknown port:000002E8 irq:3

`setserial`

watch -n 1 setserial -avg /dev/ttyS*

Every 1.0s: setserial -avg /dev/ttyS0 /dev/ttyS1 /d...  Tue Nov 17 11:40:02 2009

/dev/ttyS0, Line 0, UART: 16550A, Port: 0x03f8, IRQ: 4
        Baud_base: 115200, close_delay: 50, divisor: 0
        closing_wait: 3000
        Flags: spd_normal skip_test

/dev/ttyS1, Line 1, UART: 16550A, Port: 0x02f8, IRQ: 3
        Baud_base: 115200, close_delay: 50, divisor: 0
        closing_wait: 3000
        Flags: spd_normal skip_test

/dev/ttyS2, Line 2, UART: unknown, Port: 0x03e8, IRQ: 4
        Baud_base: 115200, close_delay: 50, divisor: 0
        closing_wait: 3000
        Flags: spd_normal skip_test

/dev/ttyS3, Line 3, UART: unknown, Port: 0x02e8, IRQ: 3
        Baud_base: 115200, close_delay: 50, divisor: 0
        closing_wait: 3000
        Flags: spd_normal

`statserial`

statserial /dev/ttyS0

Device: /dev/ttyS0

Signal  Pin  Pin  Direction  Status  Full
Name    (25) (9)  (computer)         Name
-----   ---  ---  ---------  ------  -----
FG       1    -      -           -   Frame Ground
TxD      2    3      out         -   Transmit Data
RxD      3    2      in          -   Receive  Data
RTS      4    7      out         1   Request To Send
CTS      5    8      in          0   Clear To Send
DSR      6    6      in          0   Data Set Ready
GND      7    5      -           -   Signal Ground
DCD      8    1      in          0   Data Carrier Detect
DTR     20    4      out         1   Data Terminal Ready
RI      22    9      in          0   Ring Indicator