back.gif (853 octets) ECU: Serial port communication (RS232C protocol) flag-fr.gif (272 octets)


up.gif (853 octets) Introduction

You cannot skip it! This page is a recap of all the mandatory information you need to know before attempting to design an interface to the serrial port of your PC. In no way it pretends to exhaustively cover the serial communication subject; check the links section for more...

RS-232 stands for Recommend Standard number 232, and C is the latest revision of the standard. The serial ports on most computers use a subset of the RS-232C standard. The full RS-232C standard specifies a 25-pin "D" connector of which 22 pins are used. Most of these pins are not needed for normal PC communications, and indeed, most new PCs are equipped with male D type connectors having only 9 pins.

up.gif (853 octets) Electrical specifications

The electrical specifications of the serial port is contained in the EIA (Electronics Industry Association) RS232C standard.

Electrically speaking, whenever the serial port sends a logical one (1) a negative voltage (-3 and -25 Volts) is effected on the transmit pin. When the serial port sends a logical zero (0) a positive voltage (+3 and +25 Volts) is generated. When no data is being sent, the serial port's transmit pin's voltage is negative (1) and is said to be in a Mark state. Note that the serial port can also be forced to keep the transmit pin at a positive voltage (0) and is said to be the Space or Break state. (The terms Mark and Space are also used to simply denote a negative voltage (1) or a positive voltage(0) at the transmit pin respectively).

When transmitting a byte, the UART (serial port) first sends a Start Bit which is a positive voltage (0), followed by the data (general 8 bits, but could be 5, 6, 7, or 8 bits) followed by one or two Stop Bits which is a negative(1) voltage. The sequence is repeated for each byte sent.

The baud rate is the number of times the signal can switch states in one second. Therefore, if the line is operating at 9600 baud, the line can switch states 9,600 times per second. This means each bit has the duration of 1/9600 of a second or about 100 µsec.

When transmitting a character there are other characteristics other than the baud rate that must be known or that must be setup. These characteristics define the entire interpretation of the data stream.

The first characteristic is the length of the byte that will be transmitted. This length in general can be anywhere from 5 to 8 bits.

The second characteristic is parity. The parity characteristic can be even, odd, mark, space, or none.

The third characteristic is the amount of Stop bits. This value in general is 1 or 2.

Assume we want to send the letter 'A' over the serial port. The binary representation of the letter 'A' is 0100 0001. Remembering that bits are transmitted from least significant bit (LSB) to most significant bit (MSB), the bit stream transmitted would be as follows for the line characteristics 8 bits, no parity, 1 stop bit, 9600 baud.

LSB (0 1 0 0 0 0 0 1 0 1) MSB

The above represents (Start Bit x1) (Data Bits x8) (Stop Bitx1) in 10 consecutive bits.
To calculate the actual byte transfer rate simply divide the baud rate by the number of bits that must be transferred for each byte of data. In the case of the above example, each character requires 10 bits to be transmitted for each character. As such, at 9600 baud, up to 960 bytes can be transferred in one second.

Data getting out of the serial port flow through the TD or Tx line, while data entering the serial port flow through the RD or Rx line

up.gif (853 octets) Line protocol

The above discussion was concerned with the "electrical/logical" characteristics of the data stream. We will expand the discussion to line protocol.

Serial communication can be half duplex or full duplex. Full duplex communication means that a device can receive and transmit data at the same time. Half duplex means that the device cannot send and receive at the same time. It can do them both, but not at the same time. Half duplex communication is all but outdated except for a very small focused set of applications.

Half duplex serial communication needs at a minimum two wires, signal ground and the data line. Full duplex serial communication needs at a minimum three wires, signal ground, transmit data line, and receive data line. The RS232 specification governs the physical and electrical characteristics of serial communications. This specification defines several additional signals that are asserted (set to logical 1) for information and control beyond the data signals and signal ground.

These signals are the Carrier Detect Signal (CD), asserted by modems to signal a successful connection to another modem, Ring Indicator (RI), asserted by modems to signal the phone ringing, Data Set Ready (DSR), asserted by modems to show their presence, Clear To Send (CTS), asserted by modems if they can receive data, Data Terminal Ready (DTR), asserted by terminals to show their presence, Request To Send (RTS), asserted by terminals if they can receive data. The section RS232 Cabling describes these signals and how they are connected.

The above paragraph eluded to hardware flow control. Hardware flow control is a method that two connected devices use to tell each other electronically when to send or when not to send data. A modem in general drops (logical 0) its CTS line when it can no longer receive characters. It re-asserts it when it can receive again. A terminal does the same thing instead with the RTS signal. Another method of hardware flow control in practice is to perform the same procedure in the previous paragraph except that the DSR and DTR signals are used for the handshake.

Note that hardware flow control requires the use of additional wires. The benefit to this however is crisp and reliable flow control. Another method of flow control used is known as software flow control. This method requires a simple 3 wire serial communication link, transmit data, receive data, and signal ground. If using this method, when a device can no longer receive, it will transmit a character that the two devices agreed on. This character is known as the XOFF character. This character is generally a hexadecimal &H13. When a device can receive again it transmits an XON character that both devices agreed to. This character is generally a hexadecimal &H11.

up.gif (853 octets) Hardware

Serial Pinouts (D25 and D9 Connectors)

D-Type-25 Pin No.

D-Type-9 Pin No.

Abbreviation

Full Name

Pin 2

Pin 3

TD (Tx)

Transmit Data

Pin 3

Pin 2

RD (Rx)

Receive Data

Pin 4

Pin 7

RTS

Request To Send

Pin 5

Pin 8

CTS

Clear To Send

Pin 6

Pin 6

DSR

Data Set Ready

Pin 7

Pin 5

SG

Signal Ground

Pin 8

Pin 1

CD

Carrier Detect

Pin 20

Pin 4

DTR

Data Terminal Ready

Pin 22

Pin 9

RI

Ring Indicator

 

Abbreviation Full Name

Function

TD Transmit Data Serial Data Output (TXD)
RD Receive Data Serial Data Input (RXD)
CTS Clear to Send This line indicates that the Modem is ready to exchange data.
DCD Data Carrier Detect When the modem detects a "Carrier" from the modem at the other end of the phone line, this Line becomes active.
DSR Data Set Ready This tells the UART that the modem is ready to establish a link.
DTR Data Terminal Ready This is the opposite to DSR. This tells the Modem that the UART is ready to link.
RTS Request To Send This line informs the Modem that the UART is ready to exchange data.
RI Ring Indicator Goes active when modem detects a ringing signal from the PSTN

Pins assignements

Male Female

up.gif (853 octets) Links

Exhaustive information there (all very good)
http://www.beyondlogic.org/serial/serial.htm

http://www.wcscnet.com/Tutorials/SerialComm/Page1.htm
http://www.taltech.com/TALtech_web/resources/intro-sc.html#top
http://www.lammertbies.nl/comm/info/RS-232.html
http://www.arcelect.com/rs232.htm
http://www.cpcug.org/user/clemenzi/technical/Languages/SerialIO.htm
http://www.camiresearch.com/Data_Com_Basics/RS232_standard.htm

up.gif (853 octets) Résumé

Cette page contient à peu près tout ce que vous devez savoir avant de concevoir une interface pour le port série d'un ordinateur personnel.


up.gif (853 octets)