10 Serial Port Communication

 

In this lecture, serial port communication will be discussed in detail. Serial and parallel communication will be compared and contrasted, and RS232 standard will be discussed.

 

1. Introduction

 

Data transfer is the physical transfer of data, over a point-to-point or point-to-multipoint communication channel. While analog transmission is the transfer of a continuously varying analog signal over an analog channel, digital communications is the transfer of discrete messages over a digital or an analog channel. Data transmitted may be digital messages originating from a data source, for example a computer or a keyboard. It may also be an analog signal such as a phone call or a video signal, digitized into a bit-stream for example using pulse-code modulation (PCM) or more advanced source coding schemes.

 

Data is transferred by computer  in two ways:

 

● Parallel – 8 or more lines are used to transfer data to a device that is only a short distance.

● Serial – If data is to be transferred for long distance, serial communication is used. The data is sent one bit at a time.

 

1.1 Parallel communication

 

In parallel transmission, multiple bits are sent simultaneously on different channels within the same cable, or radio path, and synchronized to a clock. Parallel devices have a wider data bus than serial devices and can therefore transfer data in words of one or more bytes at a time. As a result, there is a speedup in parallel transmission bit rate over serial transmission bit rate. However, this speedup is a tradeoff versus cost since multiple wires cost more than a single wire, and as a parallel cable gets longer, the synchronization timing between multiple channels becomes more sensitive with distance. The timing for parallel transmission is provided by a constant clocking signal sent over a separate wire within the parallel cable; thus parallel transmission is considered synchronous.

 

1.2 Serial communication

 

Serial communication is a common method of transmitting data between a computer and a peripheral device such as a programmable instrument or even another computer. Serial communication transmits data one bit at a time, sequentially, over a single communication line to a receiver. It is also a most popular communication protocol that is used by many devices for instrumentation; numerous General Purpose Interface Bus(GPIB) devices also come with an RS-232 based port.

 

This method is used when data transfer rates are very low or the data must be transferred over long distances and also where the cost of cable and synchronization difficulties makes parallel communication impractical. Serial communication is popular because most computers have one or more serial ports, so no extra hardware is needed other than a cable to connect the instrument to the computer or two computers together.

 

Transmitter converts the byte of data into serial bits using parallel-in-serial-out shift register. Receiver has a serial-in-parallel-out shift register to receive the serial data and pack them into a byte. For Short distance, the digital signal can be transferred on a simple wire without modulation. To transfer data on the telephone line, it must be converted from 0s and 1s to audio tones. The device which performs 0s and 1s to audio tones is called a modem, “Modulator/Demodulator”.

 

Serial communication has two techniques:

 

1. Synchronous- transfer block of data(characters) at a time

2. Asynchronous- transfer single byte at a time

 

The following communications  are done by hardware:

 

a)    USART (universal synchronous-Asynchronous Receiver-transmitter)

b)    UART (universal asynchronous Receiver transmitter)

c)    8051 chip has a built-in UART

 

Serial data can be transmitted in three ways:

Simplex-It is a communication channel that sends information in one direction only (Fig.2(a)).

 

Half duplex : Half-duplex data transmission means that data can be transmitted in both directions on a signal carrier, but not at the same time which is shown in Figure 2(b).

 

 

Duplex : Full-duplex data transmission means that data can be transmitted in both directions on a signal carrier at the same time as shown in figure 2(c).

 

1.2.1 Synchronous communication

 

Synchronous communication requires that the clocks in the transmitting and receiving devices are synchronized – running at the same rate – so the receiver can sample the signal at the same time intervals used by the transmitter. No start or stop bits are required.

 

In synchronous transmission, the stream of data to be transferred is encoded and sent on one line, and a periodic pulse of voltage which is often called the “clock” or “strobe” is put on another line that tells the receiver about the beginning and the ending of each bit (or byte). In general, such synchronous transmission protocols are used for all the types of parallel communications. Figure.3 shows synchronous communication (data 61H) signal along with clock signal . In this the MSB bit first sent and LSB at end.

 

Synchronization can also be embedded into a signal on a single wire. In differential Manchester encoding, used in video-tape systems, each transition from a low to high or high to low represents a logical zero. A logical one is indicated when there are two transitions in the same time frame, i.e, one clock cycle.

 

 

1.2.2 Asynchronous communication

 

Asynchronous communication is used for character-oriented transmissions. Each character is placed in between start and stop bits, this is called framing.

 

● start bit is always one bit

 

● stop bit can be one or two bits

 

● start bit is always a 0 (low)

 

● stop bit(s) is 1 (high)

 

● LSB is sent out first

 

1.2.3 RS232 standards:

 

RS-232 standard is related to serial data communication between host systems, commonly known as Data Terminal Equipment, or DTE and a peripheral system termed, Data communication Equipment (also known as Data Circuit-Terminating Equipment) or DCE. To be more specific, the device that connects to the RS-232 interface is called a Data Communications Equipment (DCE) and the device to which it connects (e.g., the computer) is called a Data Terminal Equipment (DTE).

 

It was first introduced by the Electronics Industry Alliance (EIA) in the early 1960s and is commonly known as RS-232 (Recommended Standard 232). EIA-232 or RS-232 or RS-232 C is a complete serial communication protocol, which specifies signal voltages, signal timing, signal function, pin wiring, and the mechanical connections (i.e.: either 25-pin DB-25 or 9-pin DB-9). In 1987, the EIA released a new version of the standard and changed the name to EIA-232-D. And in 1991, the EIA teamed up with Telecommunications Industry association (TIA) and issued a new version of the standard called EIA/TIA-232-E. Many people, however, still refer to the standard name as RS-232C, or just RS-232. It is most widely used serial I/O interfacing standard for serial communication. Input and output voltage levels are not TTL compatible. 1 bit is represented by -3 to -25 V and 0 bit is +3 to +25 V and -3 to +3 is undefined. To connect RS232 to a microcontroller system, we must use voltage converters such as MAX232 to convert the TTL logic levels to the RS232 voltage levels, and vice versa. MAX232 IC chips are commonly referred to as line drivers.

IBM introduced the DB-9 version of the serial I/O standard.

 

 

 

The data communication can be achieved  through DTE and DCE.

 

1. DTE (data terminal equipment) refers to terminal and computers that send and receive data

2. DCE (data communication equipment) refers to communication equipment, such as modems

3. Simplest connection between a PC and microcontroller requires a minimum of three pins, TxD, RxD, and ground

 

The terms DTE and DCE are very common in the data communications technologies. DTE is short for Data Terminal Equipment and DCE stands for Data Communications Equipment. But what do they really mean? As the full DTE name indicates, this is a piece of device that ends a communication line, whereas the DCE provides a path for communication.

 

1.2.4 8051 connection to RS232

 

8051 has two pins namely RXD and TXD pins which are used for transferring and receiving data serially. TxD and RxD are part of the port 3 group (P3.0 and P3.1).Pin 11 (P3.1) of 8051 is assigned to TxD. Pin 10 (P3.0) of 8051 is designated as RxD. These pins are TTL compatible. It requires a line driver to make them RS232 compatible. The driver used for this is the MAX232 chip.

 

MAX232 converts from RS232 voltage levels to TTL voltage levels that are acceptable to 8051.It uses a +5 V power source , same as the source voltage of 8051.No dual power supplies are needed. MAX232 has two sets of line drivers for transferring and receiving data. Line drivers used for TxD are called T1 and T2.

 

Line drivers used for RxD are designated as R1 and R2. T1 and R1 are used together for TxD and RxD of the 8051. Second set is left unused. It requires four capacitors ranging from 1 to 22µF. MAX233 is used to save board space. It performs the same job as the MAX232.It eliminates the need for capacitors. It is much more expensive than the MAX232.

 

Null modem can also be used for interfacing 8051 with outside devices. Connection is very simple compared to other modems. In Null modem we have DCE, DTE and ground pins is there. DTE of 8051 connected to DCE of Null modem. DCE of 8051 should be connected to DTE of Null modem. Ground pin of both should connected.

 

1.2.5 Serial communication register

 

SBUF is a 8-bit register used for serial communication. To transmit a byte of data via the TxD line, it must be placed in the SBUF register. When a byte is written into SBUF, it is framed with the start and stop bits and transferred serially via the TxD line. SBUF holds the byte of data when it is received by 8051 RxD line. When the bits are received serially via RxD, the 8051 deframes it by removing the stop and start bits, making a byte out of the data received, and then placing it in SBUF. Baud rate in 8051 is programmable. It is done with the help of Timer1 and different oscillators. The baud rate of 8051 system should be matched with the baud rate of the system to be interfaced.

 

Figure.8 shows the SCON register structure. In this SMO and SM1 bits combined to specify the serial mode. Usually mode 2 is prefered because the UART in 8051 supports this mode. REN bit is used to enable the receiving the serial data. So this bit has to be set to enable serial communication.

2. Summary

 

In this lecture basic of serial communication is discussed. The Serial communication concepts with 8051 and RS232 I/O interface standard are discussed.

 

3. References

  1. The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D.McKinlay.

 

Supporting & Reference Materials

  1. The 8051 Microcontroller and Embedded Systems Using Assembly and C Second Edition Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay.