RS232 focusses on the connection of DTE, data terminal equipment (computers, printers, etc.) with DCE, data communication equipment (modems).RS232 cables can use DB25 or DB9 connectors. DB25 connectors have provision for two RS232 connections, but the single connection DB9 is most commonly used.
RS323 DB9 pinout
| 1 | DCD | Data carrier detect |
| 2 | RD | Receive data |
| 3 | TD | Transmit data |
| 4 | DTR | Data terminal ready |
| 5 | SG | Signal ground |
| 6 | DSR | Data set ready |
| 7 | RTS | Request to send |
| 8 | CTS | Clear to send |
| 9 | RI | Ring indicator |
DTE to DTE connections through a null modem cable (PC to PC)
The purpose of a null-modem cable is to permit two RS-232 DTE devices to communicate with each other without modems or other communication devices (i.e., DCEs ) between them.
A null modem cable is an RS232 serial cable where the transmit and receive lines are crosslinked. In some cables there are also handshake lines crosslinked. In many situations a straight through serial cable is used, together with a null modem adapter. The adapter contains the necessary crosslinks between the signals.
Null modem without handshaking
| Connector 1 | Connector 2> | Function |
| 2 | 3 | Rx -> Tx> |
| 3 | 2 | >Tx> -> Rx |
| 5 | 5 | Signal ground |
Null modem with loop back handshaking
| Connector 1 | Connector 2 | Function |
| 2 | 3 | Rx -> Tx |
| 3 | 2 | Tx -> Rx |
| 5 | 5 | Signal ground |
| 1 + 4 + 6 | - | DTR -> >CD + DSR |
| - | 1 + 4 + 6 | DTR -> CD + DSR |
| 7 + 8 | - | RTS -> CTS |
| - | 7 + 8 | >RTS -> CTS |
Null modem with partial handshaking
| Connector 1 | Connector 2 | Function |
| 1 | 7 + 8 | RTS2 -> CTS2 + CD1 |
| 2 | 3 | Rx -> Tx |
| 3 | 2 | Tx -> Rx |
| 4 | 6 | DTR -> DSR |
| 5 | 5 | Signal ground |
| 6 | 4 | >DSR -> DTR |
| 7 + 8 | 1 | RTS1 -> CTS1 + CD2 |
Null modem with full handshaking
| Connector 1 | Connector 2 | Function |
| 2 | 3 | Rx -> Tx |
| 3 | 2 | Tx -> Rx |
| 4 | 6 | DTR -> DSR |
| 5 | 5 | Signal ground |
| 6 | 4 | DSR -> DTR |
| 7 | 8 | RTS -> CTS |
| 8 | 7 | CTS -> RTS |
Software flow control (XOFF/XON)
When one end of a data link is unable to accept any more data (or approaching that point), it sends XOFF to the other end. The other end receives the XOFF code, and suspends transmission.
Once the first end is ready to accept data again, it sends XON, and the other end resumes transmission.
Requires less wiring and is slower, as sending XOFF requires at least one character time to transmit, it may be queued, has to be done in software and has the overhead of escaping the control codes so that they are not confused with data.
XOFF/XON representations in ASCII
| Code | Meaning | ASCII | Dec | Hex | Keyboard |
| XOFF | Pause transmission | DC3 | 19 | 0×13 | CTRL+S |
| XON | Resume transmission | DC1 | 17 | 0×11 | CTRL+Q |
Hardware flow control
In common RS232 there are pairs of control lines:
- RTS flow control, RTS/CTS
- DTR flow control, DTR/DSR
Hardware flow control is typically handled by the DTE or “master end”, as it is first raising or asserting its line to command the other side.
In case of RTS control flow, DTE sets its RTS, which signals the opposite end (the slave end such as a DCE) to begin monitoring its data input line. When ready for data, the slave end will raise its complementary line,
CTS in this example, which signals the master to start sending data, and for the master to begin monitoring the slave’s data output line. If either end needs to stop the data, it lowers its respective “data readyness” line.
For PC-to-modem and similar links, the case of DTR flow control, DTR/DSR are raised for the entire modem session (say a dialup internet call), and RTS/CTS are raised for each block of data.
Testing serial ports with stty
Print configuration
stty -F /dev/ttyS0 -a
Set to 38400, no flow control, one stop bit, odd parity, 8 bit, disable special characters
On target,
stty -F /dev/ttyS1 speed 38400 raw -echo -echoe -echok -echoctl -echoke -cstopb -parenb -parodd cs8 -crtscts icanon
cat /dev/ttyS1
On host,
stty -F /dev/ttyS1 speed 38400 raw -echo -echoe -echok -echoctl -echoke -cstopb -parenb -parodd cs8 -crtscts icanon
for x in 1 2 3 4 5; do date > /dev/ttyS1;sleep 1;done
To turn on the hardware flow control, do:
stty -F /dev/ttyS1 crtscts
stty -F /dev/ttyS1 crtscts
Post a Comment