CRC Cyclic redundancy check code(Cyclic Redundancy
Check), It is the most commonly used error checking code in the field of data communication, Its feature is that the length of information field and verification field can be arbitrarily selected. Cyclic redundancy check(CRC) It is a data transmission error detection function, Polynomial calculation of data, And attach the result to the back of 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, NamelyCRC Bit number.

POLY: Shorthand for build items, with16 Binary representation. for example:CRC-32 That is0x04C11DB7, Ignore the highest"1", That is, the complete build item is0x104C11DB7.

INIT: This is the algorithm start register(crc) Initialization presets for, Hexadecimal representation.

REFIN: Whether each byte of the data to be tested reverses by bit,True orFalse.

REFOUT: After calculation, Before exclusive or output, Whether the whole data is reversed by bit,True orFalse.

XOROUT: The final result is obtained after the calculation result is exclusive of this parameter.CRC value.

 

commonCRC The parameter model is as follows:


CRC Algorithm name

Polynomial formula

width

polynomial

Initial value

Result exclusive or value

Input value reversal

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 algorithm.:0xcbf43926.



On-lineCRC 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 andSTM32 Consistent hardware algorithm:0x379e9f06.



STM32 OfCRC Example program



3. C program source code

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

Point free download address:https://www.etdev.net/thread-20-1-1.html
<https://www.etdev.net/thread-20-1-1.html>