2022-08-08 03:26 AM
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)
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.
Solved! Go to Solution.
2022-08-09 08:01 PM
i think LSB is 5bit. not 6bit. isn't it? (CRC-5 's polynomial is 100101(6bit), so CRC value must be 5bit. [4..0].
you are right if (26 bit data) + (6 bit CRC) = 32bit, but i think CRC bit stream is 5 bit.
And in case of 24bit or 25bit, i think above code is not working properly.
because of initial seed value calculation, i think alignment between data & shifted initial value will not match. corret?
2022-08-09 08:36 PM
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.