Serial port is a very universal device communication protocol on the computer (do not confuse it with universal serial bus or USB). Most computers contain two serial ports based on RS232. The serial port is also a general communication protocol for instruments and equipment; Many GPIB compatible devices also have RS-232 ports. At the same time, the serial communication protocol can also be used to obtain the data of remote acquisition equipment.

The concept of serial communication is very simple. The serial port sends and receives bytes by bit. Although it is slower than parallel communication by byte, the serial port can use one line to send data and another line to receive data at the same time. It is very simple and can realize long-distance communication. For example, when IEEE488 defines the parallel traffic state, it stipulates that the total equipment line shall not exceed 20m, and the length between any two equipment shall not exceed 2m; For the serial port, the length can reach 1200 meters.

 Transmission format and receiving process of RS232 serial communication 

Serial communication parameters:

a) Baud rate: the data transmission rate specified in RS-232-C standard is 50, 75, 100, 150, 300, 600, 1200, 2400, 4800, 9600 and 19200 baud per second.

b) Data bits: the standard values are 5, 7 and 8 bits. How to set depends on the information you want to transmit. For example, the standard ascii code is 0 ~ 127 (7 bits); The extended ASCII code is 0 ~ 255 (8 bits).

c) Stop bit: used to represent the last bit of a single packet. Typical values are 1, 1.5 and 2 bits. Because the number is timed on the transmission line, and each device has its own clock, there may be a small synchronization between the two devices in the communication. Therefore, the stop bit not only indicates the end of transmission, but also provides an opportunity for the computer to correct clock synchronization.

d) Parity bit: a simple error detection method in serial communication. For even and odd parity, the serial port will set the parity bit (one bit after the data bit) and use a value to ensure that the transmitted data has even or odd logical high bits. For example, if the data is 011, for even check, the check bit is 0 to ensure that the number of digits with high logic is even. If it is odd check, check bit 1, so there are three logical high bits.

Transmission format of serial communication:

In serial communication, when the line is idle, the TTL level of the line is always high and the reverse RS232 level is always low. The RS232 line at the beginning of a data is high level, and RS232 is low level at the end. Data is always transmitted bit by bit from low to high. When the oscilloscope reads, the left side is the high position of the data.

For example, for hexadecimal data 55aah, when 8-bit data bit and 1-bit stop bit transmission are adopted, its waveform on the signal line is shown in Fig. 1 (TTL level) and Fig. 2 (RS-232 level).

55h = 01010101b, after taking the reverse 10101010b, add a start bit 1 and a stop bit 0. The data format of 55h is 1010101010b;

Aah = 10101010b, after taking the reverse 01010101b, add a start bit 1 and a stop bit 0, and the data format of 55h is 1101010100b;

 Transmission format and receiving process of RS232 serial communication 

  Receiving process of serial communication

(asynchronous communication: the receiver and transmitter have their own clocks; synchronous communication: the transmitter and receiver are controlled by the same clock source. RS232 is asynchronous communication)

(1) When starting communication, the signal line is idle (logic 1). When a jump from 1 to 0 is detected, the “receiving clock” will be counted.

(2) When 8 clocks are counted, detect the input signal. If it is still low, confirm that this is the “start bit” rather than the interference signal.

(3) After the receiving end detects the start bit, it detects the input signal once every 16 receiving clocks, and takes the corresponding value as d0 bit data. If it is logic 1, it is used as data bit 1; If it is logic 0, it is regarded as data bit 0.

(4) Detect the input signal once every 16 receiving clocks, and take the corresponding value as D1 bit data., Until all data bits are entered.

(5) Check bit P (if any).

(6) After receiving the specified number of data bits and check bits, the communication interface circuit hopes to receive the stop bit s (logic 1). If logic 1 is not received at this time, it indicates that an error has occurred, and the “frame error” flag is set in the status register. If there is no error, parity check all data bits. If there is no check error, send the data bits from the shift register to the data input register. If the check is wrong, set the parity error flag in the status register.

(7) After receiving all the information of this frame, take the high level on the line as the idle bit.

(8) When the signal becomes low again, it starts to enter the detection of the next frame.

  Transmission format and receiving process of RS232 serial communication

The crystal oscillator of 11.0592m is commonly used in single chip microcomputer. This strange number has its origin:

The baud rate is 9600bps, and each bit width T1 = 1 / 9600s

Crystal oscillation period T2 = 1 / 11.0592/1000000s

Single chip microcomputer machine cycle T3 = 12 * T2


That is, for 9600bps serial port, the single chip microcomputer samples it at a rate of 96 times.

If the single chip microcomputer crystal oscillator is used incorrectly, it will produce error code for serial port acceptance.

Leave a Reply

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