How are the start, data, and stop bits allocated for serial communication?

Serial port is the abbreviation of serial interface (serialport), also known as serial communication interface or COM interface.

Serial port is the abbreviation of serial interface (serialport), also known as serial communication interface or COM interface.

Serial communication refers to a communication mode that uses serial communication protocol (serialcommunication) to transmit data bit by bit on a signal line.

Serial ports are divided according to electrical standards and protocols, including RS-232-C, RS-422, RS485, etc.

1. Serial communication

In serial communication, data is transmitted on a single line with a width of 1 bit, and a byte of data is divided into 8 times, and the data is transmitted one by one in order from low to high.

The data of serial communication is transmitted bit by bit, and each bit sent by the sender has a fixed time interval, which requires the receiver to receive each bit at the same time interval as the sender. Not only that, the receiver must also be able to determine the beginning and end of an information group.

The two basic serial communication methods commonly used include synchronous communication and asynchronous communication.

1.1 Serial synchronous communication

Synchronous communication (SYNC:synchronousdatacommunication) means that at the agreed communication rate, the frequency and phase of the clock signal of the sending end and the receiving end are always the same (synchronous), which ensures that the two parties in the communication have exactly the same timing when sending and receiving data relation.

Synchronous communication combines many characters into an information group (information frame). The beginning of each frame is indicated by a synchronization character, and only one frame of information is transmitted in one communication. While transmitting data, it is also necessary to transmit a clock signal so that the receiver can use the hour hand signal to determine each information bit.

The advantage of synchronous communication is that the number of bits of information transmitted is almost unlimited, and the data transmitted by one communication has tens to thousands of bytes, and the communication efficiency is relatively high. The disadvantage of synchronous communication is that it is required to always maintain an accurate synchronous clock in communication, that is, the sending clock and the receiving clock must be strictly synchronized (the common practice is to use the same clock source for both devices).

In the subsequent serial communication and programming, only asynchronous communication will be discussed, so I won’t go into too much detail about synchronous communication here.

1.2 Serial asynchronous communication

Asynchronous communication (ASYNC: asynchronous datacommunication), also known as start-stop asynchronous communication, is transmitted in units of characters. There is no fixed time interval requirement between characters, and the bits in each character are transmitted at a fixed time.

In asynchronous communication, the synchronization between the sender and receiver is achieved by setting the start bit and stop bit in the character format. Specifically, before a valid character is officially sent, the transmitter first sends a start bit, then a valid character bit, and then sends a stop bit at the end of the character, and the start bit to the stop bit constitute a frame. Between the stop bit and the next start bit is an idle bit of indefinite length, and it is specified that the start bit is low level (logic value is 0), and the stop bit and idle bit are both high level (logic value 1). This ensures that there must be a next edge at the beginning of the start bit, which can mark the beginning of a character transmission. According to the start bit and stop bit, it is easy to realize the character definition and synchronization.

Obviously, when asynchronous communication is used, the sending and receiving ends can control the sending and receiving of data by their respective clocks. These two clock sources are independent of each other and can be asynchronous with each other.

The following briefly talk about the data sending and receiving process of asynchronous communication.

1.2.1 Data format of asynchronous communication

Before introducing the data sending and receiving process of asynchronous communication, it is necessary to figure out the data format of asynchronous communication.

Asynchronous communication stipulates that the transmission data format is composed of start bit, data bit, parity bit and stop bit, as shown in Figure 1 (the parity is not shown in the figure). Check bit, because the parity bit is not necessary, if there is a parity bit, the parity bit should be after the data bit and before the stop bit).

How are the start, data, and stop bits allocated for serial communication?

(1) Start bit: The start bit must be a logic 0 level that lasts for a bit time, marking the beginning of transmission of a character, and the receiver can use the start bit to synchronize its own receiving clock with the sender’s data.

(2) Data bit: The data bit immediately follows the start bit and is the real effective information in communication. The number of data bits can be agreed by both parties, generally 5, 7 or 8 bits. The standard ASCII code is 0~127 (7 bits), and the extended ASCII code is 0~255 (8 bits). When transmitting data, the low-order bits of the characters are transmitted first, and then the high-order bits of the characters are transmitted.

(3) Parity check bit: The parity check bit only occupies one bit and is used for odd or even check. The parity check bit is not necessary. If it is an odd parity, it is necessary to ensure that the transmitted data has an odd number of logic high bits in total; if it is an even parity, it is necessary to ensure that the transmitted data has an even number of logic high bits in total.

For example, suppose that the transmitted data bit is 01001100. If it is an odd parity, the odd parity bit is 0 (make sure there is an odd number of 1s in total), and if it is an even parity, the even parity bit is 1 (requires Make sure there is an even number of 1).

It can be seen that the parity bit is only a simple logic high or logic low bit for the data, and it will not make a substantial judgment on the data. The advantage of this is that the receiving device can know the state of a bit and it is possible to judge whether it has The noise interferes with the communication and whether the transmitted data is synchronized.

(4) Stop bit: The stop bit can be 1 bit, 1.5 bit or 2 bit, which can be set by software. It must be a logic 1 level, marking the end of transmitting a character.

(5) Idle bit: Idle bit means from the end of the stop bit of one character to the start of the next character, indicating that the line is in an idle state and must be filled with a high level.

1.2.2 The data sending process of asynchronous communication

After understanding the data format of asynchronous communication, you can send data according to the specified data format. The specific steps for sending data are as follows:

(1) After initialization or when there is no data to send, the sender outputs logic 1, which can have any number of free bits.

(2) When data needs to be sent, the sending end first outputs logic 0 as the start bit.

(3) Then you can start to output the data bits. The transmitter first outputs the lowest bit of data D0, then D1, and finally the highest bit of data.

(4) If there is a parity check bit, the sender outputs the check bit.

(5) Finally, the sender outputs a stop bit (logic 1).

(6) If there is no information to be sent, the sender outputs logic 1 (idle bit). If there is information to be sent, go to step (2).

1.2.3 The data receiving process of asynchronous communication

In asynchronous communication, the receiving end uses the receiving clock and baud rate factor to determine the length of time for each bit. Take the baud rate factor equal to 16 (the receiving clock shifts the receiving shift register every 16 clock cycles) as an example.

(1) Start communication, the signal line is idle (logic 1), when the transition from 1 to 0 is detected, it starts to count the receiving clock.

(2) When 8 clocks are counted, check the input signal. If it is still low, confirm that this is the start bit, not an interference signal.

(3) After the receiving end detects the start bit, it detects the input signal once every 16 receiving clocks, and uses the corresponding value as the D0 bit data.

(4) Check the input signal once every 16 receiving clocks, and use the corresponding value as D1 bit data until all data bits are input.

(5) Check the parity check bit.

(6) After receiving the specified number of data bits and the check bit, the communication interface circuit hopes to receive the stop bit (logic 1). If it does not receive the logic 1 at this time, it means that an error has occurred. Set ” Frame error” sign; if there is no error, all data bits are checked for parity. If there is no check error, the data bits are taken out of the shift register and sent to the data input register. If the check is wrong, set “parity” in the status register. Wrong” sign.

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

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

The above is the whole process of data sending and receiving in asynchronous communication.

1.3 Several concepts

In order to better understand serial communication, we also need to understand several basic concepts in serial communication.

(1) Sending clock: When sending data, first send the data to be sent into the shift register, and then under the control of the sending clock, the parallel data is shifted out bit by bit.

(2) Receive clock: When receiving serial data, the rising edge of the receive clock samples the received data, detects the data bits, and moves it into the shift register of the receiver, and finally forms a parallel data output.

(3) Baud rate factor: The baud rate factor refers to the number of clock pulses required to send or receive 1 data bit.

2. Serial connector

There are two commonly used serial ports, one is a 9-pin serial port (DB-9 for short), and the other is a 25-pin serial port (DB-25 for short). Each type of connector is divided into a male and a female. The needle-shaped connector is a male connector, and the hole-shaped connector is a female connector.

How are the start, data, and stop bits allocated for serial communication?

3. RS-232C standard

Commonly used serial communication interface standards are RS-232C, RS-422, RS-423 and RS-485. Among them, RS-232C as the electrical standard for serial communication interfaces defines the interface information for bit-wise serial transmission between data terminal equipment (DTE: dataterminalequipment) and data communication equipment (DCE: datacommunicationequipment), and rationally arranges the electrical signals and Mechanical requirements have been widely used worldwide.

3.1 Electrical characteristics

RS-232C stipulates electrical characteristics, logic levels and various signal functions, as follows:

On the TXD and RXD data lines:

(1) Logic 1 is -3~-15V voltage

(2) Logic 0 is a voltage of 3~15V

On control lines such as RTS, CTS, DSR, DTR and DCD:

(1) The signal is valid (ON state) is a voltage of 3~15V

(2) The signal is invalid (OFF state) is -3~-15V voltage

It can be seen that RS-232C uses positive and negative voltages to represent the logic state, which is the opposite of the requirement that transistor-transistor logic integrated circuits (TTL) use high and low levels to represent the logic state.

3.2 Signal line distribution

The RS-232C standard interface has 25 lines, including 4 data lines, 11 control lines, 3 timing lines, and 7 spare and undefined lines. So, how are these signal lines allocated on the pins of the 9-pin serial port and the 25-pin serial port?

Here is a brief introduction to these signal lines.

(1) The data device is ready (DSR), and the valid state (ON) means that the data communication equipment is in a usable state.

(2) The data terminal is ready (DTR), and the valid state (ON) means that the data terminal equipment is in a usable state.

These two device status signals are valid, which only means that the device itself is available, and does not mean that the communication link can start communication. Whether or not to start communication is determined by the following control signals.

(3) Request to send (RTS), used to indicate that the data terminal equipment (DTE) requests the data communication equipment (DCE) to send data.

(4) Allow to send (CTS), used to indicate that the data communication equipment (DCE) has prepared data and can send data to the data terminal equipment (DTE), which is a response to the request to send the signal RTS. Request to send (RTS) and permission to send (CTS) are used in a half-duplex communication system. In a full-duplex system, there is no need to use request to send (RTS) and permission to send (CTS) signals. Set them directly Just ON.

(5) Data carrier detection (DCD) is used to indicate that the data communication equipment (DCE) has connected to the communication link and informs the data terminal equipment (DTE) that it is ready to receive data.

(6) Ringing indication (RI). When the data communication equipment receives the ringing call signal sent by the exchange, it will enable the signal (ON) to notify the terminal that it has been called.

(7) Send data (TXD), data terminal equipment (DTE) sends serial data to data communication equipment (DCE) through this signal line.

(8) Receive signal (RXD), data terminal equipment (DTE) receives serial data from data communication equipment (DCE) through this signal line.

(9) Ground wire (SG, PG), respectively indicate signal ground and protection ground signal wires.

The Links:   SK60GB123 LM64C350

Related Posts

Leave a Reply

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