How to handle errors in RS232 communication
RS232 (RecommendedStandard232) refers to a digital serial communication interface standard, which is mainly used to connect data communication devices. But with the popularity of high-speed network, RS232 communication has been less and less attention. However, in some special fields, RS232 is still an indispensable interface standard, such as medical, instrumentation, computer control, etc.. In RS232 communication, due to noise, mutual interference and other reasons, data transmission will inevitably occur errors. In this article, we will introduce the error handling method in RS232 communication.
One, parity check and CRC check
RS232 protocol parity check and CRC check are common error detection checksum method. Parity check by detecting the number of 1's in a byte to determine whether the number of 1's in the byte is even or odd. The CRC checksum, on the other hand, obtains a checksum code by cyclic redundancy checking the data against a known generating polynomial. Using these two checksum methods can effectively reduce the BER in communication.
Two, timeout detection
Since the RS232 communication in the data transmission can not guarantee real-time, especially in the serial communication, if the receiver is processing data, and at the same time there are multiple data streams incoming, data loss, disorder and so on may occur. In order to avoid this situation, you can use the timeout detection method, in the set time did not receive the data, it is considered that the communication error.
Three, retransmission mechanism
In the case of the discovery of erroneous data, the retransmission mechanism can be used to resend the erroneous data to ensure the correctness of the data. However, it should be noted that the retransmission mechanism increases the communication time and needs to be evaluated well when controlling the communication.
Four, buffer mechanism
RS232 communication, when the data transmission speed is greater than the processing speed, it may cause data loss or deadlock phenomenon. At this time, you can use the buffer mechanism, the data stored in the buffer, waiting for the completion of the processing and then the transmission of data.
Fifth, increase the data detection mark
Usually in data transmission, there will be a start bit, data bits, check bits and stop bits and other markers to identify the data, but in the RS232 communication, these markers may be transmitted because of the noise and other reasons and lose recognition. To solve this problem, data detection markers can be added, such as a 32-bit identification code at the head and tail of the packet, to ensure that the data is correct.
In general, error handling is very important in RS232 communication. Through the use of parity check, CRC check, timeout detection, retransmission mechanism, buffering mechanism and increase the data detection mark, etc., you can ensure the correctness of the data, to ensure the stability and reliability of communication.