rs232 standards

Upload: van-quang-dung

Post on 03-Apr-2018

245 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 RS232 Standards

    1/12

    HardwareFirmware Tools Download Commu

    nitySearch| Legals|Deutsch

    Ethernut RS-232 PrimerThis practical guide should help to connect your PC to the RS-232 interface of your embedded system.

    Unfortunately, in many modern PCs the RS-232 ports had beenomitted. In this case a USB to RS-232 bridge can be used.

    General information about the RS-232 interface is availableatWikipedia.

    Hardware

    The RS-232 standard specifies 20 different singal lines.

    However, many of them are rarely implemented and only twosignal wires plus a common ground wire are required as aminimum. While many different connectors had been in useduring the last decades, the DB-9 connector had become thecommonly used standard in recent years.

    Due to the asymmetrical specification of the interface, thereare two different connector layouts, DTE (data terminalequipment, originally used by teletype writers) and DCE (data

    communication equipment, originally used by modems).Usually a male connector is available on the DTE device, whilea female connector is provided at the DCE.

    http://www.ethernut.de/en/hardware/index.htmlhttp://www.ethernut.de/en/hardware/index.htmlhttp://www.ethernut.de/en/firmware/index.htmlhttp://www.ethernut.de/en/tools/index.htmlhttp://www.ethernut.de/en/download/index.htmlhttp://www.ethernut.de/en/community/index.htmlhttp://www.ethernut.de/en/community/index.htmlhttp://www.ethernut.de/en/search.htmlhttp://www.ethernut.de/en/search.htmlhttp://www.ethernut.de/en/imprint.htmlhttp://www.ethernut.de/en/imprint.htmlhttp://www.ethernut.de/en/imprint.htmlhttp://www.ethernut.de/de/index.htmlhttp://www.ethernut.de/de/index.htmlhttp://www.ethernut.de/de/index.htmlhttp://www.ethernut.de/de/index.htmlhttp://en.wikipedia.org/wiki/Rs232http://en.wikipedia.org/wiki/Rs232http://en.wikipedia.org/wiki/Rs232http://www.ethernut.de/index.htmlhttp://en.wikipedia.org/wiki/Rs232http://www.ethernut.de/de/index.htmlhttp://www.ethernut.de/en/imprint.htmlhttp://www.ethernut.de/en/search.htmlhttp://www.ethernut.de/en/community/index.htmlhttp://www.ethernut.de/en/community/index.htmlhttp://www.ethernut.de/en/download/index.htmlhttp://www.ethernut.de/en/tools/index.htmlhttp://www.ethernut.de/en/firmware/index.htmlhttp://www.ethernut.de/en/hardware/index.html
  • 7/28/2019 RS232 Standards

    2/12

    RS-232 DB-9 male connector at the

    data terminal equipment (DTE).

    RS-232 DB-9 female connector at the

    data communication equipment (DCE).

    Red lines are used foroutputs, green lines denote inputs.

    The signal names refer to the DTE device.

    Pin Signal Direction Description

    1 DCD DTE DCE Data Terminal Ready (for connection).

    5 GND Common ground.

    6 DSR DTE DCE Request To Send (or DTE ready to receive).

    8 CTS DTE

  • 7/28/2019 RS232 Standards

    3/12

    RxD A2 -> B2 RxD

    TxD A3 B2 RxD

    TxD A3 |

    DTR A4 B1 DCD

    | B6 DSR

    RTS A7 |

    | B8 CTS

    GND A5 -- B5 GND

    If you are experiencing character loss, some flow control isrequired. For basic RTS/CTS flow control we need a 5-wirecable. Often the software will not allow to enable individualhandshake signals. So we must locally provide the remaininghandshakes.

    5-wire straight cable with flow control

    http://www.ethernut.de/img/rs232s3-3.pnghttp://www.ethernut.de/img/rs232s3hs-3.pnghttp://www.ethernut.de/img/rs232s3-3.pnghttp://www.ethernut.de/img/rs232s3hs-3.pnghttp://www.ethernut.de/img/rs232s3-3.png
  • 7/28/2019 RS232 Standards

    4/12

    RxD A2 -> B2 RxD

    TxD A3 B1 DCD

    | B6 DSR

    GND A5 -- B5 GND

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

    9-wire straight cable with full modem handshake

    RxD A2 -> B2 RxD

    TxD A3 B1 DCD

    DTR A4 B6 DSR

    RI A9 -> B9 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. Inexceptional cases such cables can be used to connect two DCEdevices, provided that the female plugs are replaced by male

    types.Like with straight cables, the most simple one requires 3 wiresonly.

    3-wire cross cable

    http://www.ethernut.de/img/rs232s-3.pnghttp://www.ethernut.de/img/rs232s5hs-3.pnghttp://www.ethernut.de/img/rs232s-3.pnghttp://www.ethernut.de/img/rs232s5hs-3.png
  • 7/28/2019 RS232 Standards

    5/12

    RxD A2 B2 RxD

    GND A5 -- B5 GND

    If one end doesn't provide hardware handshake, whilehardware handshake can't be disabled on the other side, thenwe need a cable with shortened handshake signals.

    3-wire cross cable with handshake shorts

    RxD A2 B2 RxD

    RTS A7 ->|

    CTS A8

  • 7/28/2019 RS232 Standards

    6/12

    RxD A2 B2 RxD

    RTS A7 -> B8 CTS

    CTS A8 B8 CTS

    CTS A8 |B1 DCD

    ->|B6 DSR

    DCD A1|

  • 7/28/2019 RS232 Standards

    7/12

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

    Here is the wiring of a cable, which allows to connect two DTEdevices to the DCE connector of Ethernut 1 or Ethernut 2.

    RxD A2 -> B2 RxD

    TxD A3

  • 7/28/2019 RS232 Standards

    8/12

    RxD A2 B3 RxD

    RTS A7 -> B7 CTS

    CTS A8 C3 RxD

    DSR A6 B1 DCD

    RxD A2 -> B2 RxD

    TxD A3 B9 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, Ethernut1 and 2 boards allow to reconfigure RTS/CTS lines as

    http://www.ethernut.de/img/rs232c5c3hs-3.pnghttp://www.ethernut.de/img/rs232fdspy-3.pnghttp://www.ethernut.de/img/rs232c5c3hs-3.pnghttp://www.ethernut.de/img/rs232fdspy-3.pnghttp://www.ethernut.de/img/rs232c5c3hs-3.png
  • 7/28/2019 RS232 Standards

    9/12

    secondary RxD/TxD lines. The following sniffer cable makes useof this feature.

    DCD A1 -> B1 DCD

    RxD A2 -> B2 RxD

    TxDA3

    B9 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 A1 -> B1 DCD

    RxD A2 -> B2 RxD

    TxD A3 B9 RI

    RxD A2 -> C2 RxD

    TxD A3 -> C6 DSR

    GND A5 -- C5 GND

    http://www.ethernut.de/img/rs232-enut3-sniffer.pnghttp://www.ethernut.de/img/rs232-enut1-sniffer.pnghttp://www.ethernut.de/img/rs232-enut3-sniffer.pnghttp://www.ethernut.de/img/rs232-enut1-sniffer.png
  • 7/28/2019 RS232 Standards

    10/12

    Software

    Typically, RS-232 ports can be used like normal files. They canbe open or closed and you can read data from and write data topreviously opened ports under program control.

    A basic software is the so called terminal emulator. It will sendcharacters you type on the keyboard to the RS-232 port anddisplay characters on the screen, which are received from theRS-232 port. Furthermore, as its name suggests, it emulatesone or morecomputer terminals. This means, that it interpretsspecial control characters and performs the related actions, likeclearing the screen, scrolling in a specific direction, changingthe character font etc. TheVT52 control codes are quitepopular with tiny embedded systems, because they are simpleto implement and consume less memory than other moreadvanced emulations.

    Last not least a terminal emulator provides menus or commandline options to configure the RS-232 interface parameters, like:

    o BaudrateA 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.

    o Number of data and stop bitsWhile 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.

    o ParityThis bit adds safety at the cost of additional overhead. Typically no parity bit is transmitted.

    o HandshakeTodays 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.

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

    http://en.wikipedia.org/wiki/Computer_terminalhttp://en.wikipedia.org/wiki/Computer_terminalhttp://en.wikipedia.org/wiki/Computer_terminalhttp://vt100.net/http://vt100.net/http://vt100.net/http://en.wikipedia.org/wiki/Computer_terminal
  • 7/28/2019 RS232 Standards

    11/12

  • 7/28/2019 RS232 Standards

    12/12

    o MinicomOthers are available as well.

    Unix

    Serial port devices may be named /dev/ttyC0, /dev/ttyC1 etc.Check your /dev directory.

    Thetip utilityruns on the command line and is available onmany UNIX systems. The following command starts tip for thefirst 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. Fortunatelythey are cheap, but before buying one, make sure that OS Xdrivers 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 byentering the following command in a Terminal window:

    $ screen /dev/tty.usbserial0 115200

    Other terminal emulator are:

    o ZTermShareware, which costs US$ 20. Some users are quite satisfied, others hate it or claim, that it i s badly supported.

    o minicomThis 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.

    http://alioth.debian.org/projects/minicom/http://alioth.debian.org/projects/minicom/http://www.iti.cs.tu-bs.de/cgi-bin/UNIXhelp/man-cgi?tiphttp://www.iti.cs.tu-bs.de/cgi-bin/UNIXhelp/man-cgi?tiphttp://www.iti.cs.tu-bs.de/cgi-bin/UNIXhelp/man-cgi?tiphttp://homepage.mac.com/dalverson/zterm/http://homepage.mac.com/dalverson/zterm/http://pdb.finkproject.org/pdb/package.php/minicomhttp://pdb.finkproject.org/pdb/package.php/minicomhttp://pdb.finkproject.org/pdb/package.php/minicomhttp://homepage.mac.com/dalverson/zterm/http://www.iti.cs.tu-bs.de/cgi-bin/UNIXhelp/man-cgi?tiphttp://alioth.debian.org/projects/minicom/