Im working on a project where i going to communicate between a STM32F407VGT and a LTC6804 BMS chip. for communication im going to use SPI with 8Bit datasize. For the communication im going to use a Packet error code which is a 15-bit cyclic redundancy chech (CRC-16) calculation.
sending a message (0x00 0x01) should return CRC value (0x3D 0x6E). I have trid to use the CRC calculation in the SPI driver stm32f4xx_spi.h but i can't figure out how i can initialize the CRC register with a value of: 0x000000000010000.
Has anybody worked with the CRC calculation and knows if this is possible to initialize the crc polynomial calculation?.
Best Regards Helge
If you intended a 16-bit polynomial then it seems you mean the value zero (the least 16 bits of your constant).
But you talk about a 15-bit CRC and then post a number with 15 hexadecimal digits. And since each hexadecimal digit is 4 bits you seem to aim for a 60-bit CRC...
See this link for representation of different polynomials. en.wikipedia.org/.../Polynomial_representations_of_cyclic_redundancy_checks
The Polynomial i have to use is the same as CRC-15-CAN. Sorry for the mistake i made, the initializing of the polynomial has to be 0b000000000010000 15 bits.
From the LTC6804 datasheet:
Network Layer Packet Error Code The packet error code (PEC) is a 15-bit cyclic redundancy check (CRC) value calculated for all of the bits in a register group in the order they are passed, using the initial PEC seed value of 000000000010000 and the following characteristic polynomial: x15 + x14 + x10 + x8 + x7 + x4 + x3 + 1. To calculate the 15-bit PEC value, a simple procedure can be established:
15-bit wide with odd initialization, don't think the peripheral based CRC is going to help you at all here. A simple table driven method will suffice.
Table driven example posted here community.st.com/.../141411-stm32f407-spi-crccalculation
Thank you very much Clive. I will look into you solution for Table driven example. It seems to solve my problems quite easy. Im just wondering for the "Byte wide buffer method", how did you find the 256 CRCTable values?
Best regards Helge
It's easy to compute the table. Some programs save flash space by building the table directly after boot.
The tables were all calculated using the polynomial, and based on how many bit states you want to advance and the XOR math of the taps.
It might be more efficient from a coding standpoint to use the upper 15-bit than the lower, and seed it with 0x0020.