Rs232 Serial Communication Projects

RS232 is a serial communications standard which enables data to be transferred in serial form between two devices. Data is transmitted and received in serial ‘bit stream’ from one point to another. Standard RS232 is suitable for data transfer to about 50 m, although special low-loss cables can be used for extended distance operation. Four parameters specify an RS232 link between twodevices. These are baud rate, data width, parity, and the stop bits, and are described below:

• Baud rate: the baud rate (bits per second) determines how much informa- tion is transferred over a given time interval. A baud rate can usually be selected between 110 and 76 800 baud, e.g. a baud rate of 9600 corresponds to9600 bits per second.

• Data width: the data width can be either 8 bits or 7 bits depending upon the nature of the data being transferred.

• Parity: the parity bit is used to check the correctness of the transmitted or

received data. Parity can either be even, odd, or no parity bit can be specified at all.

• Stop bit: the stop bit is used as the terminator bit and it is possible to specify

either one or two stop bits.

Serial data is transmitted and received in frames where a frame consists of:

• 1 start bit

• 7 or 8 data bits

• optional parity bit

• 1 stop bit

In many applications 10 bits are used to specify an RS232 frame, consisting of 1 start bit, 8 data bits, no parity bit, and 1 stop bit. For example, character ‘A’ has the ASCII bit pattern ‘01000001’ and is transmitted as shown in Fig. 6.1 with 1 start bit, 8 data bits, noparity, and 1 stop bit. The data is transmitted least significant bit first.

When 10 bits are used tospecify the frame length, the time taken to transmit or receive each bit can be found from the baud rate used. Table 6.1 gives the time

SNAG-0065_thumb

RS232 Connectors

As shown in Fig. 6.2, two types of connectors are used for RS232 commu- nications. These are the 25-way D-type connector (known as DB25) and the 9-pin D-type connector (also known as DB9). Table 6.2 lists the most commonly used signal names for both DB9 and DB25 type connectors. The used signals are:

SNAG-0066_thumb

SNAG-0067_thumb

SG: signal ground. This pin is used in all RS232 cables.

RD: received data. Data is received at this pin. This pin is used in all two-

way communications.

TD: transmit data. Data is sent out from this pin. This pin is used in all

two-way communications.

RTS: request tosend. This signal is asserted when the device requests data to

be sent.

CTS: clear tosend. This signal is asserted when the device is ready toaccept

data.

DTR: data terminal ready. This signal is asserted toindicate that the device is

ready.

DSR: data set ready. This signal indicates, by the device at the other end,

that it is ready.

CD: carrier detect. This signal indicates that a carrier signal has been

detected by a modem connected to the line.

In some RS232 applications it is sufficient to use only the pins SG, RD, and TD. Also, in some applications (e.g. when two similar devices are connected together) it is necessary to twist pins RD and TD so that the transmit pin of one device is connected to the receive pin of the other device and vice versa.

RS232 Signal Levels

RS232 is bi-polar and a voltage of +3 to +12 V indicates an ON state (or SPACE), while a voltage of -3 to -12 V indicates an OFF state (or MARK). In practice, the ON and OFF states can be achieved with lower voltages.

SNAG-0068_thumb

Standard TTL logic devices, including the 89C2051 microcontroller, operate with TTL logic levels between the voltages of 0 and +5 V. Voltage level converter ICs are used to convert between the TTL and RS232 voltage levels. One such popular IC is the MAX232, manufactured by MAXIM, and operaters with +5 V supply. The MAX232 is a 16-pin DIL chip incorporating tworeceivers and two transmitters (see Fig. 6.3) and the device requires four external capacitors for proper operation.

The 89C2051 microcontroller can output TTL level RS232 signals from its TXD (or pin P3.1) pin and it can receive TTL level RS232 signals from its RXD (or pin P3.0) pin. The microcontroller can be connected to external RS232 compatible equipment via a MAX232 type voltage converter IC.

Controlling the RS232 Port

Before the serial port can be used it is necessary to set various registers:

SCON: this is the serial port control register. It should be set to hexade- cimal 0x50 for 8-bit data mode.

TMOD: this register controls the timers for baud rate generation and it should be set tohexadecimal 0x20 to enable timer 1 to operate in 8-bit auto-reload mode.

TH1: this register should be loaded with a constant so that the required baud rate can be generated. Table 6.3 shows the values to be loaded

into TH1 and the corresponding baud rates for two different clock rates.

TR1: this register starts/stops the timer and it should be set to 1 to start timer 1.

TI: this register should be set to1 toindicate ready totransmit.

SNAG-0069_thumb

Leave a comment

Your email address will not be published. Required fields are marked *