CRC Cyclic redundancy check code (Cyclic Redundancy
Check), It is the most commonly used error checking code in the field of data communication , Its characteristic is that the length of information field and check field can be selected arbitrarily . Cyclic redundancy check (CRC) Is a data transmission error detection function , Polynomial calculation of data , The result is attached to the frame , The receiving device performs a similar algorithm , To ensure the correctness and integrity of data transmission .

 

CRC Explanation of algorithm parameter model :

NAME: Parameter model name .

WIDTH: width , Namely CRC Number of bits .

POLY: Shorthand for generated items , with 16 Base representation . for example :CRC-32 That is 0x04C11DB7, Ignoring the highest "1", That is, the complete build item is 0x104C11DB7.

INIT: This is the register at the beginning of the algorithm (crc) Initialization preset value of , Hexadecimal representation .

REFIN: Is each byte of the data to be tested bit reversed ,True or False.

REFOUT: After calculation , Before XOR output , Is the whole data bit reversed ,True or False.

XOROUT: The calculated results are XOR with this parameter CRC value .

 

common CRC The parameter model is as follows :


CRC Algorithm name

Polynomial formula

width

polynomial

Initial value

Result XOR value

Input value inversion

Output value reversal


CRC-4/ITU

4+x+1

4

03

00

00

true

true


CRC-5/EPC

4+x3+1

5

09

09

00

false

false


CRC-5/ITU

5+x4+x2+1

5

15

00

00

true

true


CRC-5/USB

5+x2+1

5

05

1F

1F

true

true


CRC-6/ITU

6+x+1

6

03

00

00

true

true


CRC-7/MMC

7+x3+1

7

09

00

00

false

false


CRC-8

8+x2+x+1

8

07

00

00

false

false


CRC-8/ITU

8+x2+x+1

8

07

00

55

false

false


CRC-8/ROHC

8+x2+x+1

8

07

FF

00

true

true


CRC-8/MAXIM

8+x5+x4+1

8

31

00

00

true

true


CRC-16/IBM

16+x15+x2+1

16

8005

0000

0000

true

true


CRC-16/MAXIM

16+x15+x2+1

16

8005

0000

FFFF

true

true


CRC-16/USB

16+x15+x2+1

16

8005

FFFF

FFFF

true

true


CRC-16/MODBUS

16+x15+x2+1

16

8005

FFFF

0000

true

true


CRC-16/CCITT

16+x12+x5+1

16

1021

0000

0000

true

true


CRC-16/CCITT-FALSE

16+x12+x5+1

16

1021

FFFF

0000

false

false


CRC-16/X25

16+x12+x5+1

16

1021

FFFF

FFFF

true

true


CRC-16/XMODEM

16+x12+x5+1

16

1021

0000

0000

false

false


CRC-16/DNP

16+x13+x12+x11+x10+x8+x6+x5+x2+1

16

3D65

0000

FFFF

true

true


CRC-32

32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1

32

04C11DB7

FFFFFFFF

FFFFFFFF

true

true


CRC-32/MPEG-2

32+x26+x23+x22+x16+x12+x11+x10+x8+x7+x5+x4+x2+x+1

32

04C11DB7

FFFFFFFF

00000000

false

false

 

1. close #define STM32_CRC Macro definition , The calculation results are consistent with the mainstream algorithms :0xcbf43926.



on-line CRC calculation :https://www.lammertbies.nl/comm/info/crc-calculation.html
<https://www.lammertbies.nl/comm/info/crc-calculation.html>



2. open #define STM32_CRC Macro definition , Calculation results and STM32 The hardware algorithm is consistent :0x379e9f06.



STM32 Of CRC Sample program



3. C program source code

Source code download address :https://download.csdn.net/download/kezunhb/10670548
<https://download.csdn.net/download/kezunhb/10670548>

Download address for free points :https://www.etdev.net/thread-20-1-1.html
<https://www.etdev.net/thread-20-1-1.html>