Design of error detection method in serial communication based on 51 single chip microcomputer

Publisher:WanderlustGazeLatest update time:2011-10-15 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

0 Introduction
For the 8051 chip structure based on the flash controller, generally, when performing data transmission, the data is first transmitted to the buffer of the flash controller through the serial port. Since the buffer size is 512 bytes, the maximum amount of data transmitted each time is 512 bytes. The transmission data amount of the three error detection methods discussed in this article is all 512 bytes.


1 Error detection method
The block diagram of the hardware development platform of the serial data communication system based on 8051 is shown in Figure 1. When using this platform for data transmission, there are usually three data error detection methods.

1.1 Parity Check
Parity check is a common method in error detection. It uses the number of 1s in the data as the error detection flag. If the number of 1s is an odd number, the error detection flag is 1, and if the number of 1s is an even number, the error detection flag is 0. The parity bit is detected at the sending and receiving ends at the same time. If the same result is obtained, it means that there is no error in the data transmission process; if different results are obtained, it means that an error has occurred in the data transmission process. At this time, 8051 will send an error retransmission signal to let the PC send data again.
1.2 Cyclic Redundancy Check (CRC)
CRC uses the principle of division and remainder for error detection. If the original data is a polynomial JP(x), P(x) is divided modulo 2 by the generated polynomial G(x), and the remainder R(x) is used as the generated CRC check code, which can be expressed by the formula:
P(x)=Q(x)·G(x)+R(x)
In the above formula, Q(x) is the quotient obtained by division. The sender sends the original data P(x) and the generated CRC check code R(x) to the receiver. The receiver calculates another CRC check code R'(x) based on the received data P'(x), and then compares the two CRC check codes to determine whether an error occurred during the transmission process. If an error occurs, the sender retransmits. The polynomial G(x) generated by the CRC8 used in this article is: x2+x5+x4+1.

1.3 Hamming Code
Hamming code is to add a certain amount of redundancy to a set of codes to form a new set of data. The newly added redundant data is called the check bit. If an information bit is wrong, it will cause several groups of parity check results to be wrong. Therefore, according to the error detection of the parity group, the information bit and nature of the error can be determined. Hamming code has the following characteristics:
Code length: N = 2m-1
Information code bit: k = 2m-m-1
Supervisory code bit: r = Nk = m, where m ≥ 2 positive integers
Since the error detection object in this article is serial port transmission, 8 bits of data are sent at a time, so the required redundant bits are 4 bits. The Hamming code used in this article is (12, 8), and its encoding consists of 8 bits of data and 4 bits. Let the data be a0, a1, a2, a3, a4, a5, a6, a7 respectively. The check bits are a8, a9, a10, a11, which can be determined according to the following formula:



2 Test environment and principle
The test platform of this article is divided into two parts, namely the PC serial port sending part and the 8051 serial port receiving part. The PC sends data through the serial port, and the unit of each serial port transmission is 8 bits. The 8051 receives the data sent by the PC through the serial port. Due to hardware limitations, the maximum buffer for storing data in the 8051 is 512 bytes. Therefore, the data on the PC side is only sent 512 bytes each time. The total test data size is 8 K bytes, and it takes 16 times to transmit 8 K bytes of data. The baud rate of the serial port transmission is 57600. The 8051 receives data from the PC, 512 bytes of data each time, and performs error detection. If an error is detected, a retransmission request is sent to the PC. If no error is detected, a command to continue transmission is sent to the PC.
In order to improve the transmission efficiency, different data transmission structures can be used for parity check, CRC check, and Hamming code check without affecting error detection.
Parity check calculates 1 bit of parity for every 8 bits of data sent. After calculating the 8 bits of parity, the parity bit is sent to 8051. The data D is 512 bytes, the group is 64 bytes, and the data is 8 bits. The data structure is shown in Figure 2.

During CRC check, 1 byte of check bit is generated for every 512 bytes of data and sent to 8051. Its data structure is shown in Figure 3. Among them, D is 512 bytes, data is 512 bytes, and CRC byte is 8 bits. That is, a CRC check value is obtained for every 512 bytes. Since the Hamming code uses (12, 4), 4 bits of check bits are generated for every 8 bits of data. Therefore, its data structure is shown in Figure 4. In the figure, D is 512 bytes of data and data is 8 bits of data.

3 Test result analysis
This paper comprehensively compares the actual efficiency of three error detection methods in the same environment. The experimental results are listed in Table 1.

Table 1 is the theoretical value calculated based on the length of the sent data and the baud rate. The actual test value is tested by calling the time function on the PC. In order to improve the decoding efficiency of the Hamming code, this paper decodes it on the 8051 through assembly language. By analyzing the data in the table, it can be seen that CRC check has the best error detection efficiency, low error rate, and moderate time consumption.


4 Conclusion
This paper compares a large amount of data of three error detection methods in serial port transmission and analyzes their error detection results and efficiency. In parity check, in order to improve the error detection speed, the 8051 end can use assembly language to directly read the parity flag in the flag register. In Hamming code, C language and assembly language can be used for programming respectively. Among the three error detection methods, parity check takes the least time and has the fastest error detection speed, followed by CRC8, and the slowest error detection is Hamming code. CRC8 has the lowest error rate, followed by Hamming code, and the probability of error in parity check is relatively high.
Because it is serial communication, the probability of error is relatively small. Therefore, when transmitting large files, parity check is generally used for error detection. CRC is only used in situations where the error rate is required to be higher. Hamming code is generally rarely used in error detection occasions.

Reference address:Design of error detection method in serial communication based on 51 single chip microcomputer

Previous article:Chinese Character Input in 51 Single-Chip Microcomputer Display and Control System
Next article:Interface Design between 51 Single Chip Microcomputer and A/D Converter MAX195

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号