Home | Forum | DAQ Fundamentals | DAQ Hardware | DAQ Software Input Devices | Data Loggers + Recorders | Books | Links + Resources |
AMAZON multi-meters discounts AMAZON oscilloscope discounts . The standardization of the RS-232 serial port as part of the IBM PC and its compatibles has led to this communications interface being used for many stand-alone loggers and other instruments that have interfaced to the PC. With the advent of smart instrumentation such as digital transmitters and their use in a distributed data acquisition and control system, the requirements of interfacing multiple devices on a multi-drop network has led to the extensive use of the RS-485 communications interface. This section reviews the fundamental definitions and basic principles of digital serial data communications. It details two of the most popular and common interface standards used in data acquisition and control systems (RS-232 and RS-485). In addition, the most common industrial protocols are examined, including methods for detecting errors in communication, an important consideration in noisy industrial environments. A section on troubleshooting and testing serial data communications circuits has been included for completeness. AMAZON multi-meters discounts AMAZON oscilloscope discounts In the past, Ethernet has been usually thought of as an office networking system. Now many manufacturers are using Ethernet and industrial fieldbuses as communication systems to interconnect data acquisition devices. This can take the form, among others, of connecting computers that are using plug-in data acquisition cards or data loggers that are networked together. Fieldbuses such as Profibus and Foundation Fieldbus are being used to interconnect devices that are doing data acquisition. There are currently several hybrid analog and digital standards available for communication between field devices and between field devices and a master system. Only a fully-compatible digital communication standard will provide the maximum benefits to end users and one such standard, currently being proposed, is the Foundation FieldBus Definitions and basic principles All data communications systems have the following components: • The source of the data (e.g. a computer). Also required is circuitry that converts the signal into one that is compatible with the communications link, called a transmitter or line driver. • The communications link (twisted-pair cable, coaxial cable, radio, telephone network etc), which transfers the message to the receiver at the other end. • The receiver of the data where the signal is converted back into a form that can be used by the local electronics circuitry. Both the receiver and the transmitter must agree on a number of different factors to allow successful communications between them, the most important being: • The type of electrical signals used to transmit the data • The type of codes used for each symbol being transmitted • The meaning of the characters • How the flow of data is controlled • How errors are detected and corrected The hardware rules that apply to the physical interface and its connections are known as interface standards, while the software rules which apply to the format and control of data flow and the detection and correction of errors are generally referred to as the protocol. All data communication is based on the same binary system used in computers. Each basic unit of information is called a BIT (BInary digIT), and it can be one of two values: '0' or '1'. These are termed logic 0 and logic 1. Inside a computer, a bit is usually represented by a voltage; typically, 5 V is logic 1, and 0 V is logic 0. In data communications, a logic 1 is also referred to as a mark and a logic 0 as a space. In a data communications link, the 1s and 0s may be indicated by a +/- voltage. Other methods can involve audio tones, with one frequency for logic 1 and a different frequency for logic 0. Some advanced techniques allow several bits to be encoded in a single voltage change: this is how you can use a 14.4 kbps modem on a telephone line with a nominal band width of only around 3 kHz. A string of bits is a binary number. It can be interpreted simply as a numerical value (in binary, hexadecimal or some other numbering system) or it may be translated into a character according to an agreed code. For example, in the ASCII system the binary value 1000100 represents 'D'. ___1.1 Transmission modes - simplex and duplex In any communication system connecting two devices, data can be sent in one direction only, or in both directions. A simplex system is one that is designed for sending messages in one direction only. This is shown in Figure 1. A duplex system is designed for sending messages in both directions. Two types of duplex systems exist: • Half duplex occurs when data can flow in both directions but only in one direction at a time as shown in Figure 2. First one end transmits and the other end receives. After what is called the line turnaround time, the roles are reversed. Figure 2: Half duplex communications • In a full duplex system, shown in Figure 3, the data can flow in both directions at the same time. Figure 3: Full duplex communications ___1.2 Coding of messages To transfer a message across a communications interface, both the sender and receiver must, among other things, agree on the meaning of the binary digital patterns transferred, or the code. Encoding is the process of converting the message data into a standard binary code for transfer over the data communications link. The number of bits in a code determines the total number of unique characters that are possible. The most common character set used for digital data communications in the Western world is the American Standard Code for Information Interchange, or ASCII code. This code assigns a binary field of 7-bits to represent each character, giving 128 (27 ) unique characters made up of: • Upper and lower case letters, and numerals 1 to 9 • Various punctuation marks and symbols • A set of control codes (the first 32 characters) that are used by the communications link itself and are not printable On a computer keyboard, ASCII control codes are generated by pressing the Control key [Ctrl] and another key. For example, [Ctrl]-[A] generates the ASCII code SOH. A communications link set up for 7-bit data strings can only handle hexadecimal values from 00 to 7F. For full hexadecimal data transfer, an 8-bit link is needed, with each packet of data consisting of a byte (two hexadecimal digits) in the range 00 to FF. For this reason, an 8-bit link is often referred to as transparent because it can transmit any value. In this case, a character can still be interpreted as an ASCII value if required (in which case the eighth bit - the most significant bit is ignored). It’s worth mentioning that the full hexadecimal range can in fact be transmitted over a 7-bit link by representing each hexadecimal digit as its ASCII equivalent. Thus the hexadecimal number 8E would be represented as the two ASCII (hexadecimal) values 38 45 ('8' 'E'). The disadvantage of this technique is that the amount of data to be transferred is almost doubled, and extra processing is needed at each end. ASCII (American Standard Code for Information Interchange) is the most commonly used code for encoding characters for data communications. It’s a 7-bit code with only 27 = 128 possible combinations of the seven binary digits (bits). Each of these 128 codes is assigned to a specific control code or character, as specified by the these standards: • ANSI - X3.4 • ISO - 646 • CCITT alphabet #5 An ASCII table records the bit value of every character defined by the code. There are many different forms of the table, but they all contain the same basic information. The values in the table may be expressed in decimal (DEC), ranging from 0-127, or in binary (BIN), ranging from 0000000 to 1111111, or in hexadecimal (HEX) numbers, ranging from 00 to 7F. (See Table ___2 For examples of binary to hexadecimal conversions.) A condensed form of the table showing characters and control codes is presented in Table ___1. The control codes and their meanings are listed in Table ___3. Table 1 shows the code for each character in hexadecimal and binary values. It takes the form of a matrix in which the MSB (most significant bits) are along the top and the LSB (least significant bits) are down the left-hand side. Table 1 ASCII table Some examples of the HEX and BIN values are given below: Table 3 ASCII control codes and their meanings ___1.3 Format of data communications messages It’s not reasonable to expect that a device can send a string of characters across a communications link and that the receiver at the other end will know what to do with the data. Any message must be presented according to some pre-arranged rules. Consequently, data is usually arranged in a particular format, with additional information added so that the message can be effectively transmitted and understood at the receiving end. Consider a simple asynchronous system such as RS-232, for which it’s common practice to send one character at a time. The format of a typical character frame is indicated in Figure ___4. Figure 4: Format of a typical serial asynchronous data message Initially the data communications link is in the idle state: the line is in the mark state, held to a constant negative voltage. The transmitter then sends a start bit to indicate that it’s transmitting a character. The start bit is in the opposite voltage state to the idle voltage and allows the receiver to synchronize to the character that follows the start bit. The receiver reads in the individual bits of the character as they arrive. At the end of the data bits, a parity bit may be included to allow the receiver to detect any possible errors in the character frame. After the parity bit, optionally 1, 1½ or 2 stop bits follow (1½ stop bits is a logic 1 held for 50% longer than 1 stop bit). The stop bit effectively puts the communication line back into an idle state. After the last stop bit is transmitted down the line, a start bit can be transmitted for the next character. The parity bit included at the end of the character is effectively a fingerprint of the character to enable the receiver to identify whether any errors have occurred in the transmission. Even parity means that the total number of logic 1 bits in the data together with the associated parity bit must be an even number. The UART (see p. 210) works out if there is an even or odd number of 1 bits and sets the parity bit to 0 or 1 to make the total count, including the parity bit, even. Odd parity is done in a similar way, except that the UART sets the parity bit to be 1 or 0 to ensure that the total number of bits in the message, again, including the parity bit, is an odd number. Two more options are available for the parity bit. Mark parity always sets the parity bit to 1, whilst space parity sets the parity bit to a 0. While mark and space parity obviously don’t allow the receiver to detect any errors in the character frame, they are sometimes used when there are timing problems. Statistically, in selecting even or odd parity, there is a 60% chance of the receiver detecting a parity error. The parity scheme works based on an odd number of bits being in error in the character frame. An even number of bits in error won’t be detected by the parity detection scheme. Thus due to the availability of more sophisticated error-checking schemes today, (such as block check calculation and cyclic redundancy check), the parity bit is sometimes set to no parity (that is, there is no parity bit at all in the character frame). In summary, the optional settings for asynchronous transmission of characters are: • Start bits 1 • Data bits 5, 6, 7, 8 • Parity bits even, odd, mark, space or none • Stop bits 1, 1½ or 2 As there cannot be half a bit, 1½-stop bits means that the mark length is 50% longer than for one stop bit. ___1.4 Data transmission speed The maximum rate at which data can be transferred from the source to the receiver on a communications interface depends on a number of factors: • Type and complexity of the circuitry at each end (interface) • Communication link (twisted-pair, coaxial cable, radio etc) • Distance between the sender and receiver • Amount of data being transferred • The overhead associated with the data transfer • The acceptable rate of error The lower the data rate, the less complex are the requirements of the communication link, the source and receiver circuitry and the lower the errors due to timing and noise problems. Data transfer rates are usually measured in bits per second or bps. This is an indication of the useful data that has been transmitted to the receiver. For example, in Figure ___4 the useful data is only seven bits, whilst the total number of bits transmitted was ten. The additional three bits are viewed as overhead bits for the data communication. The baud rate (named in recognition of Maurice Emile Baudot) can be considered the physical rate, or signaling speed at which data bits can be transmitted and correctly received on the communications interface. Referring to Figure ___4, if each bit occupied a time of 1 milli second (ms), the total baud rate would be 1 / 1 ms = 1000 baud. This is the signaling speed. The data transfer rate, on the other hand, can be calculated as: 7 data bits / 10 ms = 700 bits per second (bps) The actual data transfer rate is therefore 30% less than the baud rate for this example of a total of 10 bits in the frame. Baud rates are usually quoted in standard values such as 50, 110, 300, 600, 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200 baud. It’s common practice in industry to use the terms baud rate and data transfer rate interchangeably, unless it’s specifically noted that they are not equal. When using modems and sophisticated encoding techniques, a single signal change on the line can indicate several encoded bits. This means that the data rate (in bps) is far greater than the baud rate (the reverse of the situation quoted in the previous example). RS-232-C interface standard The Electronic Industries Association (EIA) RS-232 interface standard is probably the most widely known of all serial data interface standards. It was developed for a single purpose clearly stated in its title, and defines 'Interface between Data Terminal Equipment (DTE) and Data Communications Equipment (DCE) employing serial binary data interchange'. It was issued in the USA in 1969 by the engineering department of the EIA. Bell Laboratories and leading manufacturers of communications equipment also cooperated to clearly define the interface requirements when connecting data terminals to the Bell telephone system. Almost immediately, shortcomings resulted in minor revisions to the standard, becoming EIA-232-C still widely used today. The current revision is EIA/TIA-232-E (1991), which brings it into line with the international standards CCITT V.24, CCITT V.28, and ISO-2110. Some users contest the statement that EIA-232 is a 'standard', because its interpretation has been responsible for many problems in interfacing equipment from different manufacturers. It should be emphasized that EIA-232 standard defines the electrical and mechanical details of the interface and does not define a protocol. The EIA-232 standard consists of three major components, which define: • Electrical signal characteristics Electrical signals such as the voltage levels and grounding characteristics of the interchange signals and associated circuitry. • Interface mechanical characteristics The mechanical characteristics of the interface between the DTE and DCE. This section dictates that the interface must consist of a plug and socket, and that the socket will normally be on the DCE. The familiar DB-25 connector is specified together with a smaller 26-pin alternative connector. • Functional description of the interchange circuits This section defines the function of the data, timing and control signals used at the interface between DTE and DCE. Very few of the definitions in this section are relevant to applications for data communications for data acquisition and control. ___2.1 Electrical signal characteristics Figure ___5: Connections between a computer (DTE) and a stand-alone controller (DCE) The RS-232 standard is designed for the connection of two devices: data terminal equipment (DTE), such as a computer or printer, and data communications equipment (DCE), such as a modem. DCEs are now also called data circuit-terminating equipment in the RS-232-D/E standard. This definition was required since the RS-232 standard is often used to interface items of equipment that are not communication devices. A typical connection between a computer (DTE), which transmits data on pin 2 and receives data on pin 3 of a 25-way DB connector, to a stand-alone controller (DCE) that receives data on pin 2 and transmits data on pin 3 is shown in Figure ___5. At the RS-232 receiver the following signal voltage levels are defined: • +3 V to +25 V for transmission of logic 0 • -3 V to -25 V for transmission of logic 1 • +3 V to -3 V for an undefined logic level To meet these voltage requirements at the receiver and to overcome any voltage drops that occur along the communications lines, the RS-232 transmitter must produce slightly higher voltages. These are in the range: • +5 V to +25 V for transmission of logic 0 • -5 V to -25 V for transmission of logic 1 • +5 V to -5 V for an undefined logic level In practice, many EIA-232 transmitters operate very close to their margin of safety, e.g. at +7 and -7 volts. This can be acceptable for short cable runs, where it’s hoped that there will be no voltage problems. Unfortunately, increased error rates can be expected at the receiver because of induced external interference voltages. The voltage levels associated with the internal electronics of DTE and DCE devices are commonly -5 V to +5 V and are therefore not directly compatible with the signal levels associated with the communications interface. Consequently, at the transmitting end, a Line Driver is necessary in each data and control line to amplify this voltage to the higher level required on the EIA-232 interface. Modem power supplies, such as those used in PCs, usually have a standard +12 V to -12 V voltage output that can then be used for the line driver output. This falls within the voltage range specified by the EIA-232 standard and is the voltage level most commonly used these days. At the receiving end, a Line Receiver is necessary for each data and control line to reduce the voltage level to the -5 V to +5 V level required by the internal electronics. Figure ___6: EIA-232 transmitters and receivers The EIA-232 standard defines twenty-five (25) electrical connections, which are each described in more detail in Section ___2.3. The electrical connections are divided into the four groups shown below: • Data lines • Control lines • Timing lines • Special secondary functions The data lines are used for the transfer of data. Pins 2 and 3 are used for this purpose. Data flow is designated from the perspective of the DTE interface. Hence, the 'transmit line', on which the DTE transmits (and DCE receives), is associated with pin 2 at the DTE end and pin 2 at the DCE end. The 'receive line', on which the DTE receives (and DCE transmits), is associated with pin 3 at the DTE end and pin 3 at the DCE end. Pin 7 is the common return line for the transmit and receive data lines. Control lines are used for interactive device control, commonly known as 'hardware handshaking', and regulate the way in which data flows across the interface. The four most commonly used control lines are as follows: • RTS - request to send • CTS - clear to send • DSR - data set ready (or DCE ready in EIA-232-D/E) • DTR - data terminal ready (or DTE Ready in EIA-232-D/E) It’s important to note that the handshake lines operate in the opposite voltage sense to the data lines. When a control line is active (logic 1), the voltage is in the range +3 to +25 volts and when deactivated (logic 0), the voltage is zero or negative. Hardware handshaking is usually the cause of most of the interfacing problems. Manufacturers sometimes omit certain of these control lines from their EIA-232 equipment or assign unconventional purposes to them. Consequently, many applications don’t use hardware handshaking but instead use only the three data lines (transmit, receive and signal common ground) with some form of software handshaking. The control of data flow is then part of the application program. Most of the systems encountered in data communications for data acquisition, instrumentation and control, use some sort of software based protocol in preference to hardware handshaking. Simple examples of software handshaking protocols are the ETX/ACK, where the transmitter software is in control of the handshake, and XON/XOFF, where the receiver software controls the handshake. There is a relationship between the allowable speed of data transmission and the length of the cable connecting the two devices, on the EIA-232 interface. Briefly, as speed increases, the quality of the transition of the data signal from one voltage level to another (e.g. from -25 V to +25 V) becomes increasingly dependent on the capacitance and the inductance of the cable. The rate, at which voltage can 'slew' from the one logic level to the other, depends mainly on the cable capacitance, which increases with cable length. The length of the cable is thus limited by the number of data errors that are acceptable during transmission. The EIA 232-D&E standard specifies the limit of total cable capacitance to be 2500 pF. With typical cable capacitances of 50 pF/ft, the maximum cable length would appear to be 50 ft, but in practice, longer cable lengths appear to be possible with lower data transmission rates. The common data transmission rates used with EIA-232 are 110, 300, 600, 1200, 2400, 4800, 9600 and 19200 baud. Based on field tests, Table ___4 shows a practical relationship between selected baud rates and the cable length supporting reliable transmission. Table ___ 4 indicates that much longer cable lengths are possible at lower baud rates. These values don’t take into account the effects of noise, which can adversely affect the maximum cable length supported at a given baud rate. Table ___4 Demonstrated maximum cable lengths with EIA-232 interface ___2.2 Interface mechanical characteristics Although not specified by RS-232C, the DB-25 connector (25 pin D-type) has become so closely associated with RS-232 that it’s accepted as the de facto standard. On some RS-232 compatible equipment, where not all the control lines are required for handshaking, the smaller DB-9 connector (9 pin D-type) is commonly used. The pins of the DB-9 connector are usually allocated as follows: • Pin 2 - receive data • Pin 3 - transmit data • Pin 7 - signal ground While this pin configuration is likely to be adhered to by manufacturers at the computers communications interface, it’s possible (and often likely) that the data receive and transmit lines on remote stand-alone systems are on different pins of the DB-9 connector. It’s there fore wise to consult the manufacturers' data sheets. The common RS-232 pin assignments for both the DB-9 and DB-25 connectors are shown in Table 5, below. 1 Received line signal Shield 2 Received data Transmitted data 3 Transmitted data Received data 4 DTE ready Request to send 5 Signal common/ground Clear to send 6 DCE ready DCE ready 7 Request to send Signal ground/common 8 Clear to send Received line signal 9 Ring indicator + Voltage (testing) 10 - Voltage (testing) 11 Unassigned 12 __ 13 Sec clear to send 14 Sec transmitted data 15 Transmitter signal DCE element timing 16 Sec received data 17 Receiver signal DCE element timing 18 Local loopback 19 Sec request to send 20 DTE ready 21 Remote loopback/signal quality detector 22 Ring indicator 23 Data signal rate 24 Transmit signal DTE element timing 25 Test mode Table ___5 -- Table of the common DB-9 and DB-25 pin assignments for EIA-232 ___2.3 Functional description of interchange circuits The EIA circuit functions are defined, with reference to the DTE, as follows: • Pin 1: Protective ground (shield) A connection is seldom made between the protective ground pins at each end. Their purpose is to prevent hazardous voltages, by ensuring that the DTE and DCE chassis are at the same potential at both ends. However, there is a danger that a path could be established for circulating earth currents, so, usually the cable shield is connected at one end only. • Pin 2: Transmitted data (TXD) This line carries serial data from pin 2 on the DTE to pin 2 on the DCE. The line is held at MARK (or a negative voltage) during periods of line idle • Pin 3: Received data (RXD) This line carries serial data from pin 3 on the DCE to pin 3 on the DTE. • Pin 4: Request to send (RTS) The RTS line is a request to send from the DTE to the DCE. This line is used in conjunction with the CTS line to do hardware control. The DCE won’t enable the CTS line until the DTE enables its RTS line. • Pin 5: Clear to send (CTS) When a half-duplex modem is receiving, the DTE keeps RTS inhibited. When it becomes the DTE's turn to transmit, it advises the modem by asserting the RTS pin. When the modem asserts the CTS, it informs the DTE that it’s now safe to send data. • Pin 6: Data set ready (DSR): This is also called DCE ready. In the answer mode, the answer tone and the data set ready are asserted two seconds after the telephone goes off hook. • Pin 7: Signal ground (common) This is the common return line for the data transmit and receive signals. The connection, pin 7 to pin 7 between the two ends, is always made. • Pin 8: Data carrier detect (DCD) This is also called the received line signal detector. Pin 8 is asserted by the modem when it receives a remote carrier and remains asserted for the duration of the link. • Pin 20: DTE ready (or data terminal ready) DTE Ready enables, but does not cause, the modem to switch onto the line. In originate mode, DTE Ready must be asserted in order to auto dial. In answer mode, DTE Ready must be asserted to auto answer. • Pin 22: Ring indicator This pin is asserted during a ring on the line. • Pin 23: Data signal rate selector (DSRS) When two data rates are possible, the higher is selected by asserting pin 23. ___2.4 The sequence of operation of the EIA-232 interface The following description of one particular operation of the EIA-232 interface is based upon a half duplex data interchange. It should be noted that full duplex communication is generally used today; however, a half duplex description is given as it encompasses that of full duplex operation. Figure ___7 gives a graphical description of the operation with the initiating user terminal (or DTE) and its associated modem (or DCE) on the left of the diagram and the remote computer and its modem on the right. The following sequence of steps occur: • The initiating user manually dials the number of the remote computer. • The receiving modem asserts the ring indicator line (RI-pin 22) in a pulsed ON/OFF fashion as per the ringing tone. The remote computer already has its data terminal ready line (or DTR-pin 20) asserted to indicate that it’s ready to receive calls. (Alternatively, the remote computer may assert the DTR line after a few rings.) The remote computer then sets its request to send line (RTS-pin 4) to ON. • The receiving modem then answers the phone and transmits a carrier signal to the initiating end. It also asserts the DCE ready (DSR-pin 6) after a few seconds. • The initiating modem then asserts the data carrier detect line (DCD-pin 8). The initiating terminal asserts its DTR (if it’s not already high). The modem then responds by asserting its data set ready line (DSR-pin 6). The receiving modem then asserts its clear to send line (CTS-pin 5), which permits the transfer of data from the remote computer to the initiating side. • Data is then transferred from the receiving DTE on pin 2 (transmitted data) to the receiving modem. The receiving remote computer can then transmit a short message to indicate to the originating terminal that it can proceed with the data transfer. The originating modem transmits the data to the originating terminal on pin 3. • The receiving terminal then sets its request to send line (RTS-pin 4) to OFF. The receiving modem then sets its clear to send line (CTS-pin 5) to OFF as well. • The receiving modem then switches its carrier signal OFF. • The originating terminal detects that the data carrier detect signal has been switched OFF on the originating modem and then switches its RTS line to the ON state. The originating modem then indicates that transmission can proceed by setting its CTS line to ON. • Transmission of data then proceeds from the originating terminal to the remote computer. • When the interchange is complete, both carriers are switched OFF (and in many cases the DTR is set to OFF). This means that the CTS, RTS and DCE ready (or DSR) lines are set to OFF. Note that full duplex operation requires that transmission and reception occur simultaneously. In this case, there is no RTS/CTS interaction at either end. The RTS line and CTS line are left ON with a carrier to the remote computer. Figure ___7: Example operation of an EIA-232 data interchange Break detect: To gain the attention of the receiver, a transmitter may hold the data line in a space condition (+ voltage) for a period longer than that required for a complete character. This is called a 'break' and receivers can be equipped with a break detect to detect this condition. It’s useful for interrupting the receiver even when it’s in the middle of a stream of characters being sent. Obviously, the break detect time is a function of the baud rate. ___2.5 Examples of RS-232 interfaces Although, the RS-232-C interface standard defines only a point-to-point connection on the communications link, there are circumstances when more than one device is required to be connected to the PC. An example of this would be the connection of multiple digital transmitters to a PC that has only one RS-232-C standard communications port. Whilst the RS-232 interface is not designed to be used in a multi-drop system, it’s possible to connect the modules to the PC using a daisy-chain network. In a daisy-chain configuration, each transmit-signal line output is wired to the 'receive input' signal line of the next digital transmitter in the daisy chain. This wiring sequence must be followed until the output of the last digital transmitter in the chain is wired to the receive input of the host. For the daisy-chain network to work correctly all digital transmitters must be set to the same baud rate, they must be uniquely addressable and must be able to echo any data received at the receive input to its transmit output. All characters transmitted by the host computer are received by each digital transmitter in the chain, and then passed on until the information is echoed back to the host. Commands sent from the host are examined by all digital transmitters. The device which is addressed, responds by transmitting its response on the daisy-chain network, rippling through any other modules before reaching its destination at the receive input of the host computer. The daisy-chain must be carefully implemented to avoid pitfalls inherent in its structure. As the daisy-chain is a series-connected structure, any break in the communications link or failure of any of the devices connected will make the network inoperable. Where the distance between the host computer and several remote devices is beyond the capacity of a normal RS-232 communications link, the network shown in Figure ___7 can be implemented. The communications link at either end is still RS-232. ___2.6 Main features of the RS-232 interface standard The following are some of the main features of equipment that use the EIA-232 interface standard: • Communication is point-to-point • They are suitable for serial, binary, digital, data communication (data is sent bit by bit in sequence) • Most EIA-232-C communications data is in the ASCII code, although that is not part of the standard • Communication is asynchronous (fixed timing between data bits, but variable time between character frames) • Communication is full-duplex (both directions simultaneously) with a single wire for each direction and a common wire • Voltage signals are: 1. Logic 1: -3 volts to -25 volts 2. Logic 0: +3 volts to +25 volts • The communications signal voltages are 'unbalanced', making them more susceptible to noise • They provide reliable communication up to about 15 m (50 ft) • Data rates of up to about 20 kbps are possible. In spite of its popularity and extensive use, it should be remembered that the EIA-232 interface standard was originally developed for interfacing data terminals to modems. In the context of modem requirements, EIA-232 has several weaknesses, most of which have arisen as a result of the increased requirements for interfacing other devices such as PCs, digital instrumentation and other peripheral devices in industrial plants - such as digital variable speed drives, power system monitors, etc. The main limitations of EIA-232 when used for data communications or data acquisition and control in an industrial environment are as follows: • The point-to-point restriction is a severe limitation when several 'smart' instruments are used • The distance limitation of 15 m end to end is too short for most control systems. The 115 kbps rate is too slow for many applications • The -3 to -25 volts and +3 to +25 volts signal levels are not directly compatible with the modem standard power supplies in computers of ±5 volts and ±12 volts As a result of these limitations, a number of other communications interfaces have been developed. The RS-422 and RS-485 interface standards are increasingly being used for data acquisition and control systems. The most popular of these, the RS-485 standard (of which RS-422 is effectively a limited version), is discussed in the following sections. RS-485 interface standard The EIA RS-485 is the most versatile of the EIA standards, and is an expansion of the RS 422 standard. The RS-485 standard was designed for two-wire, half duplex, balanced multidrop communications, and allows up to 32 line drivers and 32 line receivers on the same line. It incorporates the advantages of balanced lines with the need for only two wires (plus signal common) cabling. RS-485 provides reliable serial communications for: • Distances of up to 1200 m • Data rates of up to 10 Mbps • Up to 32 line drivers permitted on the same line • Up to 32 line receivers permitted on the same line The line voltages range between -1.5 V to -6 V for logic '1' and +1.5 V to +6 V for logic '0'. The line driver for the RS-485 interface produces a 5 V differential voltage on two wires. For full-duplex systems, four wires are required. For a half-duplex system, only two wires are required. A major enhancement of RS-485 is that a line driver can operate in three states (called tri state operation), logic '0', logic '1' and high-impedance. In the high-impedance state, the line driver draws virtually no current and appears to be disconnected from the line. This 'disabled' state can be initiated by a control pin on the line driver integrated circuit. This feature allows 'multidrop' operation where up to 32 line drivers can be connected on the same line, although only one line driver can be active at any one time. Each terminal in a multidrop system must therefore be allocated a unique address to avoid any conflict with other devices on the system. RS-485 includes current limiting in cases where contention occurs. The RS-485 interface standard is very useful for data acquisition and control systems where many digital transmitters or stand-alone controllers may be connected together on the same line. Special care must be taken in software to co-ordinate which devices on the network become active. Where there is more than one slave device on the network, the host computer acts as the master, controlling which transmitter/receiver will be active at any given time. The two-wire transmission line does not normally require special termination. On short lines however, the leading and trailing edges of data pulses will be much sharper if terminating resistors, approximately two times the characteristic impedance (Z_o) of the line, are fitted at the extreme ends. These resistors are typically between 100 and 500 ohm and reduce the effect of reflections at the ends of the line. For twisted pairs, the characteristic impedance is typically between 100 to 120 ohm. During operation, there maybe periods of time when all RS-485 line drivers are off and the communications lines are in 'idle'. In this condition, the lines are susceptible to noise pickup, which can be interpreted as random characters on the communications line. A solution to this problem is to incorporate 1 k-ohm bias resistors as indicated in the terminated multidrop network of Figure 8. These resistors will maintain the data lines in a mark condition when the system is 'idle'. Figure 8: RS-485 multidrop networks ___3.1 RS-485 repeaters RS-485 line drivers are designed to drive up to 32 receivers on a network. This limitation can be overcome by employing an RS-485 repeater. The repeater is a two-port device that re transmits data received on one side, at full voltage levels, to the network on the other side. Consequently, another 31 devices may be connected for each repeater used, as shown in Figure ___9. Figure ___9: RS-485 multidrop networks The main features of the four most common EIA interface standards are compared below: Mode of operation: Unbalanced Differential Max no. of drivers & receivers on line 1 Driver 1 Receiver 32 Drivers 32 Receivers Maximum cable length 15 m 1,200 m Maximum data rate 20 kbps 10 Mbps Maximum common mode voltage 25 V +12 V to -7 V Driver output signal ± 5.0 V min ± 25 V max ± 1.5 V min ± ___0 V max Driver load >3 k? 60 ? Power 'On' n/a 100 microA -7V=Vcm =12V Driver output resistance (high-Z state) Power 'Off' 300 ? 100 microA -7V=Vcm =12V Receiver input resistance_ 3 k? to 7 k? >12 k? Receiver sensitivity ±3.0 V ± 200 mV -2V=Vcm =12V Table ___6 --- Comparisons of main features of EIA-232 and EIA-485 The 20 mA current loop Another commonly used technique, based on EIA-232 but NOT part of the standard, is the current loop. This uses a current signal rather than a voltage signal. As shown in Figure ___10 a separate pair of wires is used for the transmitter current loop and receiver current loop. Figure ___10: The 20 mA current loop interface A current level of 20 mA, or sometimes 60 mA, is used to indicate a logic-1 and 0 mA, a logic-0. The use of a current signal enables a far greater separation distance to be achieved than with a standard EIA-232 voltage connection. This is due to the higher noise immunity of the 20 mA current loop that can drive long lines (up to 1 km) but at reasonably slow bit rates (up to a typical maximum of 9600 baud). This interface is mainly used between printers and terminals in an industrial environment. Serial interface converters Interface converters are increasingly important today with the movement away from RS 232C to the industrial interface standards such as RS-485. Since many industrial devices still use RS-232 ports, it’s necessary to use these converters to interface the device to other network standards. In addition, interface converters are sometimes used to increase the effective distance between two RS-232 devices, especially in noisy environments. The block diagram of an RS-232 / RS-485 converter is shown in Figure ___11. Figure ___11: Block diagram of an RS-232 / RS485 converter The RS-232/RS-485 interface converters provide bi-directional full-duplex conversion for synchronous or asynchronous transfer between an RS-232 and RS-485 node. These converters may be powered from an external AC source, typically a wall mounted transformer. Some smaller units can be powered from the handshaking pins 9 and 10 (+12V) of the RS 232 port, although for industrial applications externally powered units are recommended. When the communications network is operating over long distances, a useful feature of interface converters is optical isolation. This protects both the computer and the equipment, remotely attached to the communications equipment, from power surges picked up over long communication lines. Typical specifications for an RS-232/RS-485 converter are: • Data transfer rate up to 1 M_baud • DCE/DTE switch selectable • Converts all data and control signals • LEDs for status of data and control signals • Powered from AC source or self-powered from pins 9 & 10 of EIA-232 port • Optically isolated (optional) • DB-25 connector (male or female) • DB-37 connector (male or female) The signal flow diagram for an RS-232 / RS-485 converter is shown in Figure 12. Figure ___12: Signal flow diagram for RS-232 / RS-485 converter Protocols A protocol is essentially a common set of rules governing the exchange of data between the transmitter and receiver of a communications network, and is normally associated with the packaging of data transmitted on the communications interface. A protocol is essential to the correct operation of the communication system and determines a number of important features including: • Initialization: This initiates the protocol parameters and starts the transmission of data across the link. • Framing and frame synchronization This defines the beginning and end of a frame and ensures that the receiver can synchronize with the frame. • Flow control: This ensures that the rate at which the receiver reads the data in from the transmitter is matched and no data is lost. • Line control: This applies to half duplex links where the transmitter indicates to the receiver when it can 'turn the line around' and commence transmitting in the opposite direction. • Error control: Typical techniques used here are block redundancy checks and cyclic redundancy checks. • Timeout control: This applies to the transmitter when it doesn't receive an acknowledgement within a pre-defined period of time and assumes the receiver never received the original message. Just as there are a number of human languages, there are a considerable number of communication protocols that have been defined at different times by computer vendors and international bodies. Protocols on serial communications hardware linking the PC to data acquisition and control hardware are typically ASCII based. This allows much easier troubleshooting of communication problems where the level of understanding of industrial communication systems may be fairly low. In addition, a high level of integrity of data transfer is required where the PC controls critical equipment over the communications link. In an industrial environment where there may be a lot of electrical noise, a high degree of error checking, such as cyclic redundancy checks, is used. Several of the most commonly used protocols are discussed below. 7.1 Flow control protocols Cooperative flow control, in which the transmitter and receiver operate under a common set of rules, is called a flow control protocol. Below are described the two most popular flow control protocols. Character flow protocols (XON/XOFF)--This is a popular flow control protocol that has two characters assigned as XON (start) or XOFF (stop). Typically, the ASCII characters DC3 (Ctrl-S) and DC1 (Ctrl-Q) are assigned to XOFF and XON respectively. For example, consider a transmitter, a PC, sending a stream of characters to a printer. When the printer buffer fills to a certain predefined level, say 66%, it transmits an XOFF character back to the PC, instructing it to stop transmitting characters. Once the printer buffer has emptied to a preset level, say 33%, the printer sends an XON character to the PC, which then resumes transmission of the characters. A variation of this protocol is that the PC will resume transmission of the character stream when any character is received from the printer. Whole line protocols (ETX/ACK) The ETX/ACK protocol, designed by IBM, is based on the transmitter appending an ETX character after each line of data and waiting for the receiver's ACK, requesting the next line of data. ___7.2 ASCII-based protocols The use of ASCII-based protocols is popular because of their simplicity and ease of troubleshooting. Their main disadvantage is that they are slow and unwieldy, especially when the system requires considerable amounts of data to be transmitted at high speeds. Consequently, the ASCII protocol is normally only used for slow systems with one master talking to a limited number of slaves. ASCII protocols are also popular for stand-alone instruments where a serial interface has been added, with no major design changes, to the existing system. Essentially, this means that the additional serial port is treated like another keypad by the instrument. Protocol structure: A simple command/response ASCII protocol, used for communications between a personal computer and a digital transmitter is shown in Figure ___13. The host computer always generates the command sequence. Communications are initiated by using command messages containing the address of the device and a two character ASCII command code. All analog data is returned as a nine-character string consisting of a sign, five digits, a decimal point, and two additional digits. The $ character is used to indicate a request from the master and the * character a response from the slave device. Both the command and response messages are terminated by a [CR] character. Figure ___13: Short form command and response messages In this example, the command above reads from the digital transmitter at address 1 and receives a value of 72.10 in the response message. A variation of the short form command and response messages is their long form equivalents. To ensure greater message integrity, and increase reliability, long form messages are included with a block checksum at the end of the message. In addition, the command message is echoed back within the response message from the slave device. The long form command is initiated using the # character instead of the $ character. An example of long form messages is shown in Figure ___14. Figure ___14: Long form command and response messages The calculation of the block checksum is performed simply by adding the hexadecimal values of all the ASCII characters in the message and converting the resulting hexadecimal number into its ASCII equivalent digits. This is shown in Figure ___15 below. Note that where the summation is greater than 0 × FF, the most significant digit is discarded. Figure ___15: Block checksum calculation Errors If the remote device receives a message with an error it will respond with the ? character. Alternatively, there may be no response at all if an incorrect address or a command prompt has been used. Typical error response messages are indicated in Figure ___1 ___ Figure ___16 Typical error response message for an ASCII based protocol. Error detection There are three popular forms of error checking used in many protocols. These are, in order of increasing error-detecting capability: • Character redundancy checks • Block redundancy checks • Cyclic redundancy checks ___8.1 Character redundancy checks Character redundancy checks rely on the transmitter and receiver agreeing to use even or odd parity to calculate the parity bit to append to each character. For example, if even parity is defined for a link, the 7-bit data byte ASCII 0110001 becomes 01100011, that is, a 1 is appended to the preceding seven bits to ensure that there are even numbers of 1 in the byte. The receiver checks that the arriving 8-bit byte has even parity. If it does, it extracts the first seven bits as data. If the received byte has odd parity, the receiver reports an error. ___8.2 Block redundancy checks In this method, an additional character called the block check character is calculated and added to the stream of characters transmitted down the communications channel. For example, transmission of the three characters A B Z would have a block check character (BCC) calculated, which is added to the end. The two different techniques for calculating this block check. character are indicated in Table 7. The techniques are: Vertical longitudinal block redundancy check This method relies on the calculation of even or odd parity for each individual character and then for all the characters in a block. The mechanism is indicated in the following table. Arithmetic checksum--This checksum is calculated by adding all the bits and then discarding the carry bits. A parity bit is also calculated for each individual character. Table ___7: Two techniques for block redundancy checks ___8.3 Cyclic redundancy checks A more effective way of checking for errors is the cyclic redundancy check scheme that has a worst-case error checking ability of 99.9969%. There is thus minimal likelihood of errors slipping through undetected by the receiver. The mechanism of operation of the CRC is fairly straightforward and is based on the following approach for a typical message which can be of variable length: • Take the MESSAGE and multiply by 216 • Divide (using modulo 2 arithmetic) by an arithmetic divisor (typically the CRC CCITT which is 1000 100 00001 00 001) to obtain a quotient and remainder. The remainder is the CRC checksum. • Append the CRC checksum to the message. The receiver carries out the same calculation and compares the result with the checksum received. Troubleshooting & testing serial data communication circuits When trouble shooting a serial data communications interface, a logical approach needs to be followed, to avoid wasting many frustrating hours trying to find the problem. A procedure similar to that outlined below is recommended: • Check the basic parameters---Are the baud rate, stop/start bits and parity set identical for both devices? These are usually set on DIP switches in the device. However, the modern trend is to wards using software configuration from a terminal for these basic parameters. • Identify which is DTE or DCE---Examine the documentation to establish what actually happens at pins 2 and 3 of each device. At the DTE device, pin 2 is used for transmission of data and should have a negative voltage (Mark), whilst pin 3 is used for the receipt of data (passive) and should be at approximately 0 volts. Conversely, at the DCE device, pin 3 should have a negative voltage, whilst pin 2 should be at 0 volts. If no voltage can be detected on either pin 2 or 3, then the device is probably not EIA 232 compatible and could be connected according to another interface standard, such as EIA-422, EIA-485, etc. • Clarify the needs of the hardware handshaking---When used, this causes the greatest difficulty and the documentation should be carefully studied to yield some clues about the handshaking sequence. • Check the actual protocol used---This is seldom a problem but, when the above three points still don’t yield results, it’s possible that there are irregularities in the protocol structure between the DCE and DTE devices. From a testing point of view, section 2.1.2 in the EIA-232-C interface standard sounds too good to be true. It states that: '…The generator on the interchange circuit shall be designed to withstand an open circuit, a short circuit between the conductor carrying that interchange circuit in the interconnecting cable, and any other conductor in that cable including signal ground, without sustaining damage to itself or its associated equipment…' In other words, any pin may be connected to any other pin, or even earth, without damage and, theoretically, one cannot blow anything up! This does not mean that the EIA-232 interface cannot be damaged. The incorrect connection of incompatible external voltages can damage the interface, as can static charges! When a data communication link won't work, the following five very useful devices can be used to assist in analyzing the problem: • A digital multimeter (and paper clips?) • An LED • A breakout box • PC based protocol analyzer (including software) • Dedicated protocol analyzer (e.g. Hewlett Packard) ___9.1 The breakout box The breakout box, as shown in Figure 17 is an inexpensive tool that provides most of the information necessary to identify and fix problems on data communications circuits. Figure 17: Breakout box showing test points. A breakout box is connected into the data cable, to bring out all conductors in the cable to accessible test points. Many versions of this equipment are available on the market, from 'homemade' versions using a back-to-back pair of male and female DB-25 sockets, to fairly sophisticated test units with built in diodes, switches and test points. Breakout boxes usually have a male and a female socket, and by using 2 standard serial cables, the box can be connected in series with a communication link. The 25 test points can be monitored by LEDs, a simple digital multimeter, an oscilloscope, or a protocol analyzer. In addition, a switch in each line can be opened or closed while trying to identify where the problem is. The major weakness of the breakout box is that, while one can interrupt any of the data lines, it does not help much with the interpretation of the flow of bits on the data communication lines. A protocol analyzer is required for this purpose. ___9.2 Null modem Null modems look like DB-25 'straight-through' connectors and are often used when interfacing two devices of the same gender (e.g. DTE-DTE, DCE-DCE) or devices from different manufacturers with different handshaking requirements. A null modem, as shown in Figure 18, has appropriate internal connections between handshaking pins that 'trick' the terminal into believing conditions are correct for passing data. A similar result can be achieved by soldering extra 'loops' inside the DB-25 plug. Null modems generally cause more problems than they cure and should be used with extreme caution (preferably avoided!). Figure 18 Null modem connections ___9.3 Loop back plug This is a hardware plug that loops back the transmit data pin to the receive data pin and similarly for the hardware handshaking lines. This is another quick way of verifying the operation of the serial interface without connecting to another system. ___9.4 Protocol analyzer A protocol analyzer is used to display the actual bits on the data line, as well as the special control codes, such as X-ON, X-OFF, LF, CR, etc. The protocol analyzer can be used to monitor the data bits as they are sent down the line and compared with what should be on the line. This helps to confirm that the transmitting terminal is sending the correct data and that the receiving device is receiving it. The protocol analyzer is useful in identifying incorrect setting of baud rate, parity, stop bit, noise or incorrect wiring and connection. It also makes it possible to analyze the format of the message and look for protocol errors. When the problem has been shown not to be due to the connections, baud rate, bits, or parity, then the content of the message will have to be analyzed for errors or inconsistencies. Protocol analyzers can quickly identify these problems. Purpose-built protocol analyzers are expensive devices and it’s often difficult to justify the cost when it’s unlikely that the unit will be used very often. Fortunately, software has been developed that enables a normal PC to be used as a protocol analyzer. The use of PCs, as test devices for many applications, is a growing field. ___9.5 The PC as a protocol analyzer The PC is proving to be a useful tool for monitoring serial line activity. The general means of configuring such a package is discussed in the following paragraphs. Basic setup parameters---The initial step is to con figure the package appropriately. This requires the following basic parameters to be appropriately set up: • Baud rate, parity, stop and data bits • Handshaking requirements (e.g. Request to Send and Data Terminal Ready) • Base address and interrupt settings of board. Generally, these items can be saved to a file for future use (where one can easily recall the required configuration). Other items that require attention are: Time stamping: This allows the user to put a time value next to all activity on a port. This is especially useful where the protocol analyzer may be receiving data from two different sources at the same time and the exact time of arrival of each data item needs to be determined. Archiving: Here one can save the data coming in on the serial port, (to a hard disk, for example), by specifying the destination of the archive file and giving the length of the archival file. Trigger pattern setup: This simply means that incoming characters are sequentially scanned against a predefined pattern, called the trigger pattern, until a match is detected. When the correct sequence of characters is detected, the data is saved to a file on the disk. This avoids the user being swamped by the vast quantity of data that can be encountered in protocol work. Display of the incoming data: This is probably the most commonly used feature of a protocol analyzer. A specific display menu is selected to show the data coming into or leaving the protocol analyzer. Hardware features: The protocol analyzer is normally used in conjunction with a breakout box to effectively perform any hardware debugging required. Figure 19 indicates the typical connections used for a PC based protocol analyzer. It should be noted that a PC should have two serial ports in order to adequately perform two way signal monitoring for two devices, both transmitting and receiving. Figure 19: Typical PC based protocol analyzer connection NEXT: Distributed and stand-alone loggers/controllers |
Updated:
Tuesday, March 18, 2014 6:09
PST