You are on page 1of 12

Hardware Firmware Tools Download Commu nity

Search | Legals | Deutsch

Ethernut RS-232 Primer


This practical guide should help to connect your PC to the RS232 interface of your embedded system. Unfortunately, in many modern PCs the RS-232 ports had been omitted. In this case a USB to RS-232 bridge can be used. General information about the RS-232 interface is available at Wikipedia.

Hardware
The RS-232 standard specifies 20 different singal lines. However, many of them are rarely implemented and only two signal wires plus a common ground wire are required as a minimum. While many different connectors had been in use during the last decades, the DB-9 connector had become the commonly used standard in recent years. Due to the asymmetrical specification of the interface, there are two different connector layouts, DTE (data terminal equipment, originally used by teletype writers) and DCE (data communication equipment, originally used by modems). Usually a male connector is available on the DTE device, while a female connector is provided at the DCE.

RS-232 DB-9 male connector at the data terminal equipment (DTE). Red lines are used for outputs, green lines denote inputs.

RS-232 DB-9 female connector at the data communication equipment (DCE).

The signal names refer to the DTE device.


Pin Signal 1 2 3 4 5 6 7 8 9 DCD RxD TxD DTR GND DSR RTS CTS RI Direction Description DTE <- DCE Data Carrier Detect (when connected). DTE <- DCE Received Data (sent from DCE). DTE -> DCE Transmitted Data (sent from DTE). DTE -> DCE Data Terminal Ready (for connection). Common ground. DTE <- DCE Data Set Ready (to connect). DTE -> DCE Request To Send (or DTE ready to receive). DTE <- DCE Clear To Send (or DCE ready to receive). DTE <- DCE Ring Indicator (with incoming call).

We will now look to the wiring options and present a number of often used cables. All wiring schematics are viewed from the solder side of the plugs. Note the asymmetry between connectors at the devices and the related cable plug: The blue plugs are female types, to be plugged into the male connector of DTE devices. For the male plugs on the DCE side the grey color is used.

Straight Cables
Straight cables are used to connect a DTE with a DCE device, like attaching Ethernut 1 or 2 to a PC. They have one male plug to connect the DCE and a female plug for the DTE side. The most simple cable requires 3 wires only.
3-wire straight cable

RxD A2 -> B2 RxD TxD A3 <- B3 TxD GND A5 -- B5 GND

The simple 3-wire cable may not work if one end doesn't provide hardware handshake, while hardware handshake can't be disabled on the other side. In such cases a cable with shortened handshake signals will help.
3-wire straight cable with handshake shorts

RxD A2 -> B2 RxD TxD A3 <- B3 TxD DCD A1 ->| DTR A4 <-| |-> B1 DCD |<- B4 DTR |-> B6 DSR RTS A7 <-| CTS A8 ->| |<- B7 RTS |-> B8 CTS GND A5 -- B5 GND

If you are experiencing character loss, some flow control is required. For basic RTS/CTS flow control we need a 5-wire cable. Often the software will not allow to enable individual handshake signals. So we must locally provide the remaining handshakes.
5-wire straight cable with flow control

RxD A2 -> B2 RxD TxD A3 <- B3 TxD RTS A7 <- B7 RTS CTS A8 -> B8 CTS DTR A4 <-| DSR A6 ->| |-> B1 DCD |<- B4 DTR |-> B6 DSR GND A5 -- B5 GND

For full modem handshake we need a 9-wire cable. This standard straight cable may be used, for example, to attach a modem to Ethernut 3.
9-wire straight cable with full modem handshake

RxD A2 -> B2 RxD TxD A3 <- B3 TxD RTS A7 <- B7 RTS CTS A8 -> B8 CTS DCD DTR DSR RI A1 A4 A6 A9 -> <-> -> B1 B4 B6 B9 DCD DTR DSR RI

GND A5 -- B5 GND

This layout is also usefull as a general extension cable.

Cross Cables
Cross cables are used to connected two DTE devices. In exceptional cases such cables can be used to connect two DCE devices, provided that the female plugs are replaced by male types. Like with straight cables, the most simple one requires 3 wires only.
3-wire cross cable

RxD A2 <- B3 TxD TxD A3 -> B2 RxD GND A5 -- B5 GND

If one end doesn't provide hardware handshake, while hardware handshake can't be disabled on the other side, then we need a cable with shortened handshake signals.
3-wire cross cable with handshake shorts

RxD A2 <- B3 TxD TxD A3 -> B2 RxD RTS A7 ->| CTS A8 <-| |<- B7 RTS |-> B8 CTS DCD A1 <-| DTR A4 ->| DSR A6 <-| |-> B1 DCD |<- B4 DTR |-> B6 DSR GND A5 -- B5 GND

A 5-wire cable is required for basic RTS/CTS flow control. Again, it is a good idea to locally add wires to the unused handshake signals.
5-wire cross cable with flow control

RxD A2 <- B3 TxD TxD A3 -> B2 RxD RTS A7 -> B8 CTS CTS A8 <- B7 RTS DCD A1 <-| DTR A4 ->| DSR A6 <-| |-> B1 DCD |<- B4 DTR |-> B6 DSR GND A5 -- B5 GND

The so called Null Modem Cable uses 7 wires and can be generally used for connecting two DTE devices.
7-wire cross cable with full handshake

RxD A2 <- B3 TxD TxD A3 -> B2 RxD RTS A7 -> B8 CTS CTS A8 <- B7 RTS DTR A4 ->|B1 DCD ->|B6 DSR DCD A1|<|<- B4 DTR DSR A6|<GND A5 -- B5 GND

Splitter Cables
Sometimes the RTS/CTS lines are not needed and can be alternatively routed to a second serial port. This option is available on Ethernut 1, if R32 and R33 (both 0) are mounted

and also on Ethernut 2 when setting the right jumpers on JP1.

Here is the wiring of a cable, which allows to connect two DTE devices to the DCE connector of Ethernut 1 or Ethernut 2.
RxD A2 -> B2 RxD TxD A3 <- B3 TxD RTS A7 <- C3 TxD CTS A8 -> C2 RxD GND A5 -- B5 GND GND A5 -- C5 GND

The same is available for Ethernut 3, where the serial port routing is done in the CPLD. This even allows to have RTS/CTS flow control available on one of the plugs. The cable shown below additionally provides local handshake shortcuts for the attached DCE devices.

RxD A2 <- B2 TxD TxD A3 -> B3 RxD RTS A7 -> B7 CTS CTS A8 <- B8 RTS DTR A4 -> C3 RxD DSR A6 <- C2 TxD GND A5 -- B5 GND GND A5 -- C5 GND

Sniffer Cables
A group of special cables are so called sniffer or monitoring cables. They are used to monitor the communication between two nodes by a third device. For full duplex operation, the monitoring device must provide two serial ports. Here is an example of a cable, which allows to monitor the traffic between a DTE and a DCE device.
DCD RxD TxD DTR GND DSR RTS CTS RI A1 A2 A3 A4 A5 A6 A7 A8 A9 -> -> <<--> <-> -> B1 B2 B3 B4 B5 B6 B7 B8 B9 DCD RxD TxD DTR GND DSR RTS CTS RI

RxD A2 -> C2 RxD GND A5 -- C5 GND TxD B3 -> D2 RxD GND B5 -- D5 GND

As explained in the last chapter about splitter cables, Ethernut 1 and 2 boards allow to reconfigure RTS/CTS lines as

secondary RxD/TxD lines. The following sniffer cable makes use of this feature.
DCD RxD TxD DTR GND DSR RTS CTS RI A1 A2 A3 A4 A5 A6 A7 A8 A9 -> -> <<--> <-> -> B1 B2 B3 B4 B5 B6 B7 B8 B9 DCD RxD TxD DTR GND DSR RTS CTS RI

RxD A2 -> C3 TxD TxD A3 -> C7 RTS GND A5 -- C5 GND

A sniffer cable for Ethernut 3 will have the following layout.


DCD RxD TxD DTR GND DSR RTS CTS RI A1 A2 A3 A4 A5 A6 A7 A8 A9 -> -> <<--> <-> -> B1 B2 B3 B4 B5 B6 B7 B8 B9 DCD RxD TxD DTR GND DSR RTS CTS RI

RxD A2 -> C2 RxD TxD A3 -> C6 DSR GND A5 -- C5 GND

Software
Typically, RS-232 ports can be used like normal files. They can be open or closed and you can read data from and write data to previously opened ports under program control. A basic software is the so called terminal emulator. It will send characters you type on the keyboard to the RS-232 port and display characters on the screen, which are received from the RS-232 port. Furthermore, as its name suggests, it emulates one or more computer terminals. This means, that it interprets special control characters and performs the related actions, like clearing the screen, scrolling in a specific direction, changing the character font etc. The VT52 control codes are quite popular with tiny embedded systems, because they are simple to implement and consume less memory than other more advanced emulations. Last not least a terminal emulator provides menus or command line options to configure the RS-232 interface parameters, like:
o
Baudrate A maximum of 115,200 Baud is supported by most desktop PCs, while embedded systems often allow much higher rates. For debug output, most Nut/OS applications use 115,200 Baud by default. Number of data and stop bits While there is always 1 start bit only, there may be 1 or 2 stop bits. Even 1.5 stop bits are possibly. Either 5, 6, 7 or 8 bits may be used for the data. In order to support the full 8-bit character set at minimum overhead, most applications use 8 data bits and 1 stop bit. Parity This bit adds safety at the cost of additional overhead. Typically no parity bit is transmitted. Handshake Todays embedded systems and PCs are fast enough to transfer data at 115,200 Baud or higher rates without losing characters. Thus, hardware and software handshake can be switched off in most cases.

o o

While some terminal emulators are running in the GUI (graphical user interface) others are simple command line applications, which need to be started in a so called DOS-Box or command line shell, whatever it is called with your operating system. The OS X command line window is called Terminal, which is a bit confusing in this context.

Windows
RS-232 ports are named com1, com2, com3 and so on. Available terminal emulators are, among many others:
o
HyperTerminal Included in earlier Windows releases, but no longer available in Windows Vista. Pros:

o o o
Cons:

Easy to access if installed with your Windows release. Supports all COM ports. Good terminal emulation, including VT52.

o o o

At least those versions we used are most unreliable and buggy. If anything doesn't work, blame this program first before wasting time looking somewhere else. Doesn't support raw transfer without terminal emulation.

TeraTerm Pros:

o o o
Cons:

Easy configuration. Reliable connections. Free software with source code.

o o o o

Window contents is cleared when resized. Supports COM1 to COM4 only. Doesn't support VT52. Doesn't support raw transfer without terminal emulation.

Linux
On Linux the serial port devices are named /dev/ttyS0, /dev/ttyS1 and so on. When using a USB to RS-232 bridge, it may be /dev/usb/ttyUSB0 resp. /dev/usb/ttyUSB1 instead. A simple terminal emulator is:

Minicom

Others are available as well.

Unix
Serial port devices may be named /dev/ttyC0, /dev/ttyC1 etc. Check your /dev directory. The tip utility runs on the command line and is available on many UNIX systems. The following command starts tip for the first serial port at 115,200 Baud.

$ tip -115200 /dev/ttyC0

Mac OS X
Except some old machines, Macs do not have serial ports. Thus, a USB to RS-232 bridge is always required. Fortunately they are cheap, but before buying one, make sure that OS X drivers are available. In most cases the first devices is named /dev/tty.usbserial0, the second is /dev/tty.usbserial1 and so on. The screen utility is included in OS X and you can run it by entering the following command in a Terminal window:

$ screen /dev/tty.usbserial0 115200


Other terminal emulator are:
o o
ZTerm Shareware, which costs US$ 20. Some users are quite satisfied, others hate it or claim, that it is badly supported. minicom This is the same as under Linux. If you don't have Fink or MacPorts installed for other reasons already, this requirement may discourage you from using it.

You might also like