Skip to main content
ldong.1
Associate III
August 8, 2022
Solved

CRC5 creation method and example.

  • August 8, 2022
  • 2 replies
  • 6555 views

Hi. I'm working with L9369 H-bridge driver and i want to know how to calculate CRC code in C programming.

it's polynomial is X^5+X^2+1 and initial value is 0x1F(1 1111)

  1. Do you have any documentation regarding CRC implementation in C code?

i got CRC documentable attched document, but i think it's 26 bit and responding CRC value is not matched.

2.i want to know X^5+X^2+1 polynomial's CRC Lookup Table and how to use lookup table in C code. i calculated it by manual, and have some result. i want to know i calculate it correctly.

0->0x0

1-> 0x5

2->0xa

3->0xf

4->0x14

5->0x11

.....

255-> 0x14 

3. i want to know how to use lookup table below 2 cases. and sample code.

when i try to calucate CRC value with lookup-table, it's result is different to the value calculated by manual.

(please let me know how to calculate in case of CRC initial(0x1F) value apply, not apply case)

0x1234 ( 0001 0010 0011 0100)

0x2D40CFF(0010 1101 0100 0000 1100 1111 1111)

4. I attached excel file that i calculate CRC value by manual.

atttched document says 26 bit stream is  "0 0000:0011 0 0000:0000:0000:0000" and CRC value is 0x0B. My CRC value is 0x15(with initial CRC), 0x1A(with out initial CRC)

i don't know why the result is different to me. please help to solve it.

thank you.

thank you.

This topic has been closed for replies.
Best answer by Tesla DeLorean

I'm computing the CRC over 26 bits, when completed the high order 5-bits are the remainder, then I pull them back into the low order[4..0]

crc = (crc >> 27) & 0x1F; // Recover, align, mask computed value

Now if I appended the 5-bit CRC and ran those 31 bits, the remainder for the correct CRC would drop to zero.

2 replies

Tesla DeLorean
Guru
August 8, 2022

Prior thread https://community.st.com/s/question/0D53W00001gxfOrSAI/reqeust-for-l9369-crc-calculation-documentation

TX: [0 0000:0011 0 0 0000:0000:0000:0000 01011]
0180000B (32) [0B]
CRC:0B -> 0180000B
 
TX: [0 0000:0010 0 1 0000:0000:0000:0000 11110]
0120001E (32) [1E]
CRC:1E -> 0120001E
 
TX: [0 0000:0100 0 0 0000:0000:0000:0000 01111]
0200000F (32) [0F]
CRC:0F -> 0200000F
 
0 10 0000:0011 0000:0101:0111:0000 0:1111
4060AE0F (32) [0F]
CRC:0F -> 4060AE0F
 
RX: [0 00 0000:0000 0000:0000:0000:0000 10001]
00000011 (32) [11]
CRC:11 -> 00000011
 
RX: [0 10 0000:0011 0000:0101:0111:0000 01111]
4060AE0F (32) [0F]
CRC:0F -> 4060AE0F
 
RX: [0 00 0000:0010 0000:1001:0011:0011 01111] Table 6c, seems inconsistent
0041266F (32) [0F]
CRC:0A -> 0041266A
 
RX: [0 00 0000:0011 0000:0101:0111:0000 00110]
0060AE06 (32) [06]
CRC:06 -> 0060AE06
 
RX: [1000:1000:1111:1111:1111:1111:1111:0010]
88FFFFF2 (32) [12]
CRC:12 -> 88FFFFF2
 
RX: [0 00 1111:1101 0000:0001:0001:1111 00000]
1FA023E0 (32) [00]
CRC:00 -> 1FA023E0
 
RX: [0 00 0000:0011 0000:0101:0111:0000 00110]
0060AE06 (32) [06]
CRC:06 -> 0060AE06

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
ldong.1
ldong.1Author
Associate III
August 9, 2022

hello. thank for reply. i'm modifying your example code for calculate data input with polynomial '100101', it's hard to implement. please help me to make getting CRC code function.

and i calculated your example, it seem that CRC code is wrong.

please check belows.

  1. i calculated first Tx message's CRC, but i can't get CRC 0x01011 with initial value 0x1F. i think this example don't care CRC initial value.

TX: [0 0000:0011 0 0 0000:0000:0000:0000 01011]

-> payload is 0x60000, CRC is 0x0B(without initial value)

2.i calculated sencond Tx Message

TX: [0 0000:0010 0 1 0000:0000:0000:0000 11110]

->payload is 0x40000, CRC is 0x0F(without initial value)

Tesla DeLorean
Guru
August 8, 2022

Table 9 test values seem good

Table 9
TX: [0 1001:0000 0 0 0000:0000:0000:0000 01111]
4800000F (32) [0F]
CRC:0F -> 4800000F
 
RX: [0 00 0000:0000 0000:0000:0000:0000 10001]
00000011 (32) [11]
CRC:11 -> 00000011
 
TX: [0 0000:0011 0 1 0000:0000:0000:0000 01011]
01A0000B (32) [0B]
CRC:0B -> 01A0000B
 
RX: [1000:0000:1111:1111:1111:1111:1110:0101]
80FFFFE5 (32) [05]
CRC:05 -> 80FFFFE5
 
TX: [0 0000:0011 0 0 0000:0000:0000:0000 01011]
0180000B (32) [0B]
CRC:0B -> 0180000B
 
RX: [0 00 0000:0011 0000:0101:0111:0010 01100]
0060AE4C (32) [0C]
CRC:0C -> 0060AE4C
 
TX: [0 0000:0011 0 0 0000:0000:0000:0000 01011]
0180000B (32) [0B]
CRC:0B -> 0180000B
 
RX: [0 10 0000:0011 0000:0101:0111:0010 00101]
4060AE45 (32) [05]
CRC:05 -> 4060AE45
 
TX: [0 1111:1101 0 1 0000:0000:0000:0000 00000]
7EA00000 (32) [00]
CRC:00 -> 7EA00000
 
RX: [0 00 0000:0011 0000:0101:0111:0000 00110]
0060AE06 (32) [06]
CRC:06 -> 0060AE06
 
TX: [0 0000:0011 0 0 0000:0000:0000:0000 01011]
0180000B (32) [0B]
CRC:0B -> 0180000B
 
RX: [0 00 1111:1101 0000:0000:0001:1111 11100]
1FA003FC (32) [1C]
CRC:1C -> 1FA003FC

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..