Thursday, December 23, 2010

RS-232 SERIAL COMMUNICATION STANDARD

In telecommunications, RS-232 (Recommended Standard 232) is a standard for serial binary serial single ended and control signals connecting between a DTE (Data terminal equipment)l like computer and a DCE (Data circuit-terminating equipment) like a modem.
Serial communication is the most simplistic form of communication between two devices.
It�s pretty intuitive once you see the pattern.
It�s what started networking!


First of all why serial communication ?

later commonly used in computer serial ports.

why is it important to learn about this standard???

The era of manually implementing logics by transistors and diodes is outdated,in this advanced digital world every logic can be simply achieved by writing a software program which can configure a target hardware (Micro controller or Micro processor) which behaves in accordance with the logic desired.

For this to carry,out we need to write a software program in a computer and use a proper compiler and assembler to convert High level software program(c,c++), in to a machine language known to the external hard ware.

So it is mandatory to interface or communicate computer with our hardwares like micro controllers or microprocessors, For this reason it is very much needed that we understand the communication standards,some of them are RS-232,USB etc which most pc'c now a days have.

Almost nothing in computer interfacing is more confusing than selecting the right RS232 serial cable. These pages are intended to provide information about the most common serial RS232 cables in normal computer use, or in more common language "How do I connect devices and computers using RS232?"

Now we shall discuss about RS-232.

"There are two versions of RS-232,they are:

1.RS-232 DB25(uses 25 pins)

Cannon 25
PinNameDirectionDescription
1SHIELD---Shield Ground
2TXD-->Transmit Data
3RXD<--Receive Data
4RTS-->Request to Send
5CTS<--Clear to Send
6DSR<--Data Set Ready
7GND---System Ground
8CD<--Carrier Detect
9-19N/C--
20DTR-->Data Terminal Ready
21N/C--
22RI<--Ring Indicator
23-25N/C--


2.RS-232 DB9(uses 9 pins)
Cannon 9
PinNameDirectionDescription
1CD<--Carrier Detect
2RXD<--Receive Data
3TXD-->Transmit Data
4DTR-->Data Terminal Ready
5GND---System Ground
6DSR<--Data Set Ready
7RTS-->Request to Send
8CTS<--Clear to Send
9RI<--Ring Indicator

Communication as defined in the RS232 standard is an asynchronous serial communication method. The word serial means, that the information is sent one bit at a time Usually first comes LSB. Asynchronous tells us that the information is not sent in predefined time slots. Data transfer can start at any given time and it is the task of the receiver to detect when a message starts and ends.the sampling rates must be same for both transmitter and receiver.
Receiver receives data by knowing the position of each data piece and delay. In order to ensure the quality of data transmission, we need to control the start of transmission. This is done by acknowledgment procedure. Lets take assymetrical type of interface RS232-C. Transmitter sends RTC (request to send) signal to receiver. In other hand receiver detects this signal, finishes previous operation and then sends to receiver CTS (clear to send) signal, what means that receiver is ready to accept data. Without CTS transmitter cannot start data transmission.



Note: Clock line - for asynchronous communication is internal only

This byte is sent assynchronously. This means that receiver doesn�t know when transmitter will start sending data. But anyway there is some means needed to inform about the start of transmission. For this is START bit used at the beginning of the transmitted data. Falling edge of START bit (from logical High� to Low�) informs receiver about start of transmission. After receiver detected the start signal, it starts reading data .

After last MSB bit is received, then follows Parity bit, which allows user to control received information by parity or he can skip the control. If control is selected, then bit will be Logic'1' if there will be even number of ones and Logic'0' otherwise. After byte is received, UART stores it in data register and informs that data is ready to take. Microcontroller has to read this byte before next byte is received. Otherwise data will be lost.

Usually hardware checking of received data is disabled, because it is substituted by CRC (cyclic redundance check) calculation and transmition. Receiver first receive the data array where is also a CRC code, then receiver recalculates CRC and compares to received one. If CRC codes doesn�t match than transmission is repeated.

Data bits are sent with a predefined frequency, the baud rate. Both the transmitter and receiver must be programmed to use the same bit frequency. After the first bit is received, the receiver calculates at which moments the other data bits will be received. It will check the line voltage levels at those moments.

With RS232, the line voltage level can have two states. The on state is also known as mark, the off state as space. No other line states are possible. When the line is idle, it is kept in the mark state.

START BIT: The data line has two states - on and off. An idle line is always on. When the instrument or computer wants to send data it sets the line to off - this is the Start Bit. The bits immediately after the start bit are therefore the data bits.
STOP BIT: The Stop Bit is present to allow the instrument and computer to re-synchronise should anything go wrong: noise on the line masking the start bit for example. The period of time between the start and stop bit is constant, according to the baud rate and number of data and parity bits. The stop bit is always on. If the receiver detects an off value when the stop bit should be present, it knows there has been an error.
SETTING OF STOP BIT :The stop bit is not actually 1 bit but a minimum length of time the line must be on at the end of each data transmission. On PCs this is normally equal to 1 or 2 bits, and you must specify this in the driver software. Although 1 stop bit is most common, selecting 2 will at worst slow the message down slightly.
(You might see an option to set the stop bit to 1.5. This is only used when the number of Data Bits is less than 7. If this is the case then ASCII characters cannot be transmitted and so 1.5 is rarely used.)

HANDSHAKING:

what is hand shaking?

The Handshaking represent ways, that the device can control data stream from transmitting device. Sometime, the device cann't transform receiving data, that receive from computer or another device. The device use Handshaking to terminated data stream. Its can applay Hardware's or Software's Handshaking.
hw handshaking : Hardware flow control is also known asRTS/CTS flow control. It uses two wires in your serial cable rather than extra characters transmitted in your data lines. Thus hardware flow control will not slow down transmission times like Xon-Xoff does.
When the computer wishes to send data it takes active the Request to Send line. If the modem has room for this data, then the modem will reply by taking active the Clear to Send line and the computer starts sending data. If the modem does not have the room then it will not send a Clear to Send.
sw handshaking:Software flow control, sometimes expressed as Xon/Xoff uses two characters Xon and Xoff. Xon is normally indicated by the ASCII 17 character where as the ASCII 19 character is used for Xoff.
The modem will only have a small buffer so when the computer fills it up the modem sends a Xoff character to tell the computer to stop sending data. Once the modem has room for more data it then sends a Xon character and the computer sends more data.
This type of flow control has the advantage that it doesn't require any more wires as the characters are sent via the TD/RD lines. However on slow links each character requires 10 bits which can slow communications down.

Parity:

parity in rs-232:Parity is the state of being either odd or even. In serial communications parity may be used to check for errors in the transmission of data. When performing a parity check, the instrument or PC sending messages counts the number of 1's in a group of data bits. Depending on the result, the value of another bit - the Parity Bit - is set. The device receiving the data also counts the 1's and checks whether the Parity Bit is as it should be.
types of parity:To perform a parity check the computer and the instrument must obviously agree on how they are calculating the Parity Bit. Are they setting it on for an even or odd number of 1's?
When a device uses Even Parity, the data bits and the parity bit will always contain an even number of 1's. The reverse is true for Odd Parity.
mark and space parity:Two other parity options often available in driver software are Mark and Space. These aren't effective in error checking. Mark means the device always sets the Parity Bit to 1 and Space always to 0.

MAXIMUM CABLE LENGTHS:

Cable length is one of the most discussed items in RS232 world. The standard has a clear answer, the maximum cable length is 50 feet, or the cable length equal to a capacitance of 2500 pF. The latter rule is often forgotten. This means that using a cable with low capacitance allows you to span longer distances without going beyond the limitations of the standard. If for example UTP CAT-5 cable is used with a typical capacitance of 17 pF/ft, the maximum allowed cable length is 147 feet.

The cable length mentioned in the standard allows maximum communication speed to occur. If speed is reduced by a factor 2 or 4, the maximum length increases dramatically. Texas Instruments has done some practical experiments years ago at different baud rates to test the maximum allowed cable lengths. Keep in mind, that the RS232 standard was originally developed for 20 kbps. By halving the maximum communication speed, the allowed cable length increases a factor ten!

RS232 cable length according to Texas Instruments
Baud rateMaximum cable length (ft)
1920050
9600500
48001000
24003000
The transmission rate of serial devices is called baud. It is the number of changes in the signal per second

Sampling does not occur immediately, so it must wait
?t+T
Cable length increases delay,assuming cable a transmission line, the capacitance is increased with the length so larger cables give more delays and the receiver mis reads the bit due to timing error.
VOLTAGE LEVELS:
RS-232 using two voltage levels. Logical 1 and 0. Logical 1 is sometimes calling as marking estate or quiescent state too, logical 0 is calling as space estate.

Logical 1 is indicate negative level, while logical 0 is indicate positive level. Allow voltage levels are state in table

Data signals
LevelTransmitterReceiver
Logical 0+5 V to +15 V+3 V to +25 V
Logical 1-5 V to -15 V-3 V to -25 V
Undefine-3 V to +3 V

Control signals
SignalsDriverTerminator
"Off"-5 V to -15 V-3 V to -25 V
"On"5 V to 15 V3 V to 25 V


RS-232 connections:


The RS232 connector was originally developed to use 25 pins. In this DB25 connector pinout provisions were made for a secondary serial RS232 communication channel. In practice, only one serial communication channel with accompanying handshaking is present. Only very few computers have been manufactured where both serial RS232 channels are implemented. Examples of this are the Sun SparcStation 10 and 20 models and the Dec Alpha Multia. Also on a number of Telebit modem models the secondary channel is present. It can be used to query the modem status while the modem is on-line and busy communicating. On personal computers, the smaller DB9 version is more commonly used today. The diagrams show the signals common to both connector types in black. The defined pins only present on the larger connector are shown in red. Note, that the protective ground is assigned to a pin at the large connector where the connector outside is used for that purpose with the DB9 connector version.

RS-232 DB9 to DB25:



RS232 serial loop back test plugs:

The following RS232 connectors can be used to test a serial port on your computer. The data and handshake lines have been linked. In this way all data will be sent back immediately. The PC controls its own handshaking. The first test plug can be used to check the function of the RS232 serial port with standard terminal software. The second version can be used to test the full functionality of the RS232 serial port with Norton Diagnostics or CheckIt.


Testing occurs in a few steps. Data is sent on the Tx line and the received information on the Rxinput is then compared with the original data. The signal level on the DTR and RTS lines is also controlled by the test software and the attached inputs are read back in the software to see if these signal levels are properly returned. The second RS232 test plug has the advantage that the ring-indicator RI input line can also be tested. This input is used by modems to signal an incoming call to the attached computer.

RS232 null modem cables

The easiest way to connect two PC's is using an RS232 null modem cable. The only problem is the large variety of RS232 null modem cables available. For simple connections, a three line RS232 cable connecting the signal ground and receive and transmit lines is sufficient. Depending of the software used, some sort of handshaking may however be necessary. Use the RS232 null modem selection table to find the right null modem cable for each purpose. For a Windows 95/98/ME Direct Cable Connection, the RS232 null modem cable with loop back handshaking is a good choice.

RS232 null modem cables with handshaking can be defined in numerous ways, with loopback handshaking to each PC, or complete handshaking between the two systems. The most common null modem cable types are shown here.


RS-232 spy cable(Monitor cable):

HALF DUPLEX:

To monitor the RS-232 serial communication between two devices with a PC. To do this you need the RS-232 monitor cable which is displayed in the next picture. Two sockets are connected straight through. The spy computer is connected to the third one. This monitor cable taps communication from two sources on only one RS-232 receiver port. This means that if the two devices happen to talk simultaneously, the monitored information will be garbage. In most circumstances communication protocols work half duplex, in which case this RS-232 cable will work without problems.

NOTE:Just knowing about RS-232 is not enough to interface with external hardware,because we cannot directly connect the output of RS-232 to External hardware like MC'c and MP'c which often are TTL logic Families,TTL logic families work with lower voltages generally with 5V.But the output from RS-232(o/p of computer) are raw bits which have voltage levels of -15V to -3V(for logic '0') and +3V to +15V(for logic '1'),these logic levels of pc o/p is not compatible with logic levels of TTL external hardware which has +2V to +5V( for logic'1') and 0V to 0.8V(for logic'0').

SO FOR TRANSLATION OF LOGIC LEVELS TO THE DESIRED LOGIC LEVELS OF EXTERNAL HARDWARE(TTL) WE NEED TO USE AN IC MAX232.to know how to connect this MAX232 to RS232 plz read my post IC MAX232 FOR INTERFACING RS-232 WITH EXTERNALHARDWARE


0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More