Tool/software:
Hi all, i'm new here to this forum, I have started working with the TMAG5170A1 EV Kit, I have some questions regarding the CRC calculation, I found some code in the Forum
uint8_t calculateCRC( uint8_t data[] ) { int i = 0; uint8_t crc = 0x00; uint32_t n; // Build TX and RX byte array uint8_t d[32] = { 0 }; n = (data[0] << 24)|(data[1] << 16)|(data[2] << 8)|(data[3]); Serial.print(n, DEC); Serial.println(); while (n>0) { d[i] = n&1; n = n>>1; i++; } crc |= d[30] ^ d[26] ^ d[25] ^ d[24] ^ d[23] ^ d[21] ^ d[19] ^ d[18] ^ d[15] ^ d[11] ^ d[10] ^ d[9] ^ d[8] ^ d[6] ^ d[4] ^ d[3] ^ d[0] ^ 1; crc |= (d[31] ^ d[30] ^ d[27] ^ d[23] ^ d[22] ^ d[21] ^ d[20] ^ d[18] ^ d[16] ^ d[15] ^ d[12] ^ d[8] ^ d[7] ^ d[6] ^ d[5] ^ d[3] ^ d[1] ^ d[0] ^ 1 ^ 1) << 1; crc |= (d[31] ^ d[28] ^ d[24] ^ d[23] ^ d[22] ^ d[21] ^ d[19] ^ d[17] ^ d[16] ^ d[13] ^ d[9] ^ d[8] ^ d[7] ^ d[6] ^ d[4] ^ d[2] ^ d[1] ^ 1 ^ 1) << 2; crc |= (d[29] ^ d[25] ^ d[24] ^ d[23] ^ d[22] ^ d[20] ^ d[18] ^ d[17] ^ d[14] ^ d[10] ^ d[9] ^ d[8] ^ d[7] ^ d[5] ^ d[3] ^ d[2] ^ 1) << 3; Serial.print(crc); return crc; }
When I run this code with the following byte array {0x40, 0x7d, 0x83, 0x1}
I get a CRC value of 3, however in this same thread here, it seems a TI engineer attached an excel sheet there to help calculate the CRC values, the problem is that when running the code above with the shown byte data i get one value for CRC and when using this spreadsheet I get a completely different CRC value of 5, So I need to figure out which one is correct, sorry if my post seems a little too vague, I'm not sure what more details to post. Any help will be greatly appreciated.
Regards,