Thứ Ba, 6 tháng 8, 2013

Tìm hiểu về chuẩn RS-232 trong DB9,DB25 và cách kết nối với cáp RJ45

Connecting two devices using RS-232 sounds simple, but nearly every day we help a customer get a converter, isolator or other RS-232 device working by helping correct the RS-232 cabling connections. This FAQ will help you troubleshoot and correct such problems.

Usually inputs are connected to inputs and outputs to outputs. People don't realize that there are two types of RS-232 ports, DTE and DCE type, and that the signal names and pin numbers are the same, but signal flow is opposite! The pin labeled Tx can be input, and Rx the output.

The two ports types are complementary, the Output signals on a DTE port are Inputs to a DCE port, and Output signals on a DCE port are Inputs to a DTE port. The signal names match each other and connect pin for pin. Signal flow is in the direction of the arrows. (see figures below)






Modem Cable - Straight Cable DB9 to DB9




Modem Cable - Straight Cable DB25 to DB25

 

HOW CAN I IDENTIFY DTE OR DCE TYPE CONNECTIONS?


What devices have DTE type RS-232 ports? A DTE device is "Data Terminal Equipment", this includes Computers, Serial Printers, PLC's, Video Cameras, Video Recorders, Video Editors, and most devices which are not used to extend communications. Think COMPUTER for DTE.

What devices have DCE type RS-232 ports? A DCE device is "Data Communications Equipment", this includes devices intended to plug directly into a DTE port, PDA cables, Modems and devices that extend communications like a modem, such as RS-422, RS-485, or Fiber Optic converters or Radio Modems. Think MODEM for DCE.

Modem Cable - Straight Conversion DB9 to DB25Rule of Thumb: When connecting a DTE device to a DCE device, match the signal names. When connecting two DTE or two DCE devices together, use a Crossover cable. (TD crosses to RD, RTS to CTS, DTR to DSR as shown in Modem to Modem connections. (see 9PMMNM) The cable for two computers (DTE) also simulates modem connections to CD/DSR, so it is commonly called a "Null Modem" cable. 

Modem Cable - Crossover Cable DB9 to DB9 




Modem Cable - Crossover Cable DB25 to DB25




Modem Cable - Crossover Cable DB25 to DB25

 


Are My Devices Wired As DTE or DCE? - How to Check


DTE or DEC - Diagram





  1. Use Rule of Thumb - If the device plugs into the computer serial port and works normally, the device is wired as DCE (or the connection cable is a crossover type that makes it work as a DCE). If the device connects to the computer port using a "null modem" crossover cable, it is wired as DTE.




  2. Use RS-232 Line Tester - A quick and easy way to determine the DTE/DCE port type is to use a RS-232 line tester such as the 9PMTT. The tester can show the signal state of any active RS-232 data lines using LED's lighting Red or Green. Active data lines are output from a device, they may be either High or Low.


    DTE or DEC - Diagram


    Just plug the tester into either of the two devices, see which lines are lit, unplug it, then plug it in to the other device, see which lines are lit. (see figures).


    DTE or DEC - Diagram


    If the same light (TD or RD) is lit, use a crossover cable or null modem connector that swaps the connections for pins #2 and #3 and other pins as needed.


    DTE or DEC - Diagram


    If the device is "port powered" check the active side, then plug in the port powered device and see if other (TD or RD) LED is lit. If not, try swapping the leads with a null modem cable, see if the other LED now lights. If not, you may not have enough voltage on the handshaking lines of the port to steal power from.




  3. Use a DC Voltmeter - Technicians with a DC voltmeter can use it to measure the DC level from signal ground (pin#5 on DB9, pin#7 on DB25) on the connector to pin #2 or pin #3. When the unit is powered and not sending data, the output line will have a DC voltage of minus polarity, 3 volts to 11 volts will be typical. The other pin will have little or no voltage. For example, we measure -11 volts on pin#2 of a DB9 connector and the line is labeled RD or Rx, then the device is wired as DCE. If we measure the voltage on pin#3, it is DTE.


    Measure pin #2 and  pin #3 to ground (pin # 5 - DB9) (pin #7 -- DB25) on the on the cable from the first device, the on the device you want to connect. If the cable and device have voltage on the same pin, you need to use a crossover or null modem connector that swaps pins #2 & #3 and the other pins. (For DB9 see model 9PMMNM, for DB25 see232DTE)


    Electrically active handshaking lines will be negative when not asserted or positive when asserted. (for reference, see line tester figures). Active handshaking lines can be found by measuring each pin for voltage. Output lines will have voltage. On a DTE, DTR and RTS will have voltage if used. On a DCE, DSR and CTS will have voltage, and if a modem with CD (Carrier Detect) and RI (Ring Indicator) these last two will be low until Ring is detected or a Carrier connection is made. If handshaking lines don't have voltage when the device is powered on and ready, the device doesn't output them, they may be looped back, RTS to CTS and DTR to DSR. You can turn off the device power and measure for continuity (zero ohms) between pins to confirm if they are looped back.




Other RS-232 Connection Problems





  1. Handshaking lines RTS and CTS not interconnected, DTR and DSR not interconnected. Swap as needed.

  2. Programs may use the RTS/CTS connection to check that a device is ready to receive data and respond. If there is No CTS connection, the program will never send data, but wait a long time or timeout with an error. The RTS line may need to be looped back to the CTS input. Data errors can occur if the device actually requires handshaking.

  3. Programs may also use the DTR/DSR line connection to check that a cable is connected or that the device is turned on. If there is No DSR signal, the DTR line may need to be looped back to the DSR input. Some devices use DTR handshaking.

  4. Each signal required for unit operation must be carried through by the isolator, modem or RS-422 or fiber optic converter. The primary "2 Channels" for RS-232 are Receive & Transmit. There are 2 data flow control channels, RTS and CTS. If these are missing, data is lost, characters missing, or files scrambled.

  5. Connections to Telephone Modem/FAX modem - Make sure CD & RI lines are connected.


Yost serial device wiring


Introduction in the Yost wiring standard


The wiring of RS232 has always been a problem. Originally the standard was defined for DTE, data terminal equipment to DCE, data communication equipment connection, but soon people started to use the communication interface to connect two DTEs directly using null modem cables. No standard was defined for null modem connections with RS232 and not long after their introduction, several different wiring schemes became common. With DECConnect, Digital Equipment Corporation tried to define their own standard for serial interconnection of computer devices with MMJ modified modular jack connectors. This interfacing standard became available on most of their hardware, but it wasn't adopted by other computer manufacturers. Maybe because DEC used an non-standard version of the modular jack.

UTP and FTP cables with RJ45 connectors became the de-facto standard in office cabling systems, and people started looking for ways to transmit RS232 signals over this cabling system. The RS-232D standard (more properly called EIA/TIA 561) was the official attempt for a standard to transmit RS232 over RJ45. Unfortunately this attempt didn't twist the cable internally. Therefore it primarily remained a standard for DTE to DCE connection in a world where the primary use of RS232 was to interconnect DTEs directly.

Very interesting is the RS232 to RJ45 wiring standard proposed by Dave Yost in 1987, based on earlier wiring schemes used at Berkeley University. He tried to define a standard comparable to DECConnect, where both DTEs and DCEs could be connected with one cable type. This standard was published in the Unix System Administration Handbook in 1994, and has since that moment been a wiring standard for many organisations. We will discuss this standard in detail here.

Goals of the Yost device wiring standard


The mess with RS232 wiring is widely known. It was the reason for starting this website. Dave Yost wanted to solve that mess once and for all, reaching as much as possible of the following goals:

  1. All cable connectors should have the same connector type (RJ45)

  2. All cable connectors should have the same connector gender (male)

  3. DTEs and DCEs should have the same connector wiring

  4. All cables should be identical (except for length)

  5. No need for null modems or other special cables for specific situations


These goals are very close to the goals DEC wanted to achieve with DECConnect. The Yost standard has however one basic advantage. Because RJ45 connectors are used, eight pins are available which makes it possible to transfer almost all RS232 signals. Therefore the Yost standard can be used with much more equipment than DECConnect.

The Yost cable


One cable for all solutions is the basis of the Yost standard. This cable is not a straight through patch cable with two RJ45 connectors crimped to each end, but a cross-cable where pin 1 is connected to pin 8, pin 2 to 7 etc. The basic layout of this cable is shown below. In this picture flat cable is used, which is specially designed for use with RJ45 connectors. Do not use cross cables that are sold in some computer stores. Those cables cross some pairs to make the connection of two computers with ethernet network cards possible without a hub, but these cables are not recommended for Yost systems.

 
Basic Yost cable with two RJ45 connectors cross connected

Basic Yost cable with two RJ45 connectors cross connected




























































RJ45 plug 1RJ45 plug 2Function
18CTSRTS
27CDDTR
36RxTx
45Signal ground
54Signal ground
63TxRx
72DTRCD
81RTSCTS

I have used the DTE signal names here, just as is common with the DECConnect interface. DTE is the rule, DCE is the exception in that approach. The signal ground has been split in two lines to get a symmetric layout. Two common RS232 signals are missing on the RJ45 connector. The ring indicator RI is often not necessary because most modems also signal incoming rings with the text "RING" on the data lines. Data set ready DSR is not implemented because it can easily be emulated by connecting the DTR and DSR lines in the adapter at the DTE side.

If twisted pair cable is used with the RJ45 connectors, the following pairs are advised to minimize cross-talk between the lines: 1-2, 3-4, 5-6 and 7-8. When twisting this way, both data lines are twisted with their own signal ground line, adding some noise immunity. Twisting of the handshake lines is less critical. The exact color-scheme to connect the twisted pair cable to the RJ45 connectors is not important for the functionality of the cable, but it is important for yourself to use only one color-scheme to prevent errors. If you don't know which color-scheme to use, I advice the following which is a modified version of the EIA/TIA-568B color coding.
Yost cable with twisted pair wiring

Yost cable with twisted pair wiring

Yost DTE adapter wiring


Now we know how the cables are wired, it is time to define the adapter wiring for various equipment. Depending of the type of equipment, DB9 or DB25 connectors are used. Layouts for both connectors to a RJ45 socket for DTE equipment is shown here. The colors are defined by the Yost standard. The DTR to DSR connection is optional. Please use the manual of the device or software to decide if this loop is necessary. It doesn't harm most of the time if you connect both lines, even with systems that don't use the DSR input signal.

 
Yost DB9 to RJ45 serial DTE adapter wiring

Yost DB9 to RJ45 serial DTE adapter wiring 
Yost DB25 to RJ45 serial DTE adapter wiring

Yost DB25 to RJ45 serial DTE adapter wiring











































































RJ45FunctionColorDB9DB25 
1CTSBlue85 
2CDOrange18 
3RxBlack23 
4SGRed57 
5SGGreen57 
6TxYellow32 
7
 
DTR
DSR
Brown
 
4
6
20
6
 
optional
8RTSWhite74 

A special note about printers


In the Yost standard, Dave Yost defines printers as DCE devices which is IMHO not correct. From an historical point of view, printers are just the predecessors of the terminal, with the teletype as intermediate. Also, the serial RS232 wiring diagrams I know for printers all use a modified null modem version for the connection to a computer, rather than a straight through connection which would be the case when the printer was wired as DCE.

But although the definition of printers as DCE might not be correct, the notes in the Yost standard about special precautions with the handshaking signals still apply. As there is no standard for wiring the handshaking signals of serial printers, my advice is to look at my serial printer page or—if available—in the technical manual of your device to find out which RS232 handshaking signals are used. Then wire the adapter accordingly.

Yost DCE adapter wiring


The wiring of a Yost RS232 to RJ45 adapter for a DCE is more or less a mirror of the DTE adapter wiring. The Yost standard defines the wiring scheme for both DB9 and DB25 connectors. Because DB9 connectors are rarely used on DCEs, there is only a picture of the larger version here. The table lists the pinouts for DB9 when needed in a specific situation.

 
Yost RJ45 to DB25 serial DCE adapter wiring

Yost RJ45 to DB25 serial DCE adapter wiring


































































RJ45FunctionColorDB9DB25
1RTSBlue74
2DTROrange420
3TxBlack32
4SGRed57
5SGGreen57
6RxYellow23
7CDBrown18
8CTSWhite85

0 nhận xét:

Đăng nhận xét