KMA215 All information provided in this document is subject to legal disclaimers. © NXP B.V. 2014. All rights reserved.
Product data sheet Rev. 1 — 24 February 2014 34 of 50
NXP Semiconductors
KMA215
Programmable angle sensor with SAE J2716 SENT
13.4.1 Software example in C
1 #include <stdio.h.>
2
3 int generate_crc(unsigned int data[], int arr_length)
4{
5 // generator polynomial
6 const int gpoly = 0x107; // initial value of checksum
7 int crc = 0xFF;
8 // print data values and calculate CRC
9 printf(“\nAddress\tValue\n”);
10 for (int index = 0; index <= arr_length-1; index++) {
11 printf(“0x%1X\t0x%04X\n”, index, data[index]);
12 for (int bitnr = 15; bitnr >= 0; bitnr--) {
13 crc <<= 1;
14 crc = (int) ((data[index] & (1u<<bitnr))>>bitnr);
15 if (crc & 0x100) crc ^= gpoly;
16 }
17 }
18 // print calculated checksum
19 printf(“\nCalculated Checksum: 0x%02X\n”, crc);
20 return crc;
21 }
22 int main_crc(void)
23 {
24 // data array for checksum calculation
25 // 8 LSB are CRC, fill with 0
26 unsigned int data[] = {0x0818, 0x0000, 0x0800,
27 0x0FFF, 0x0000, 0x0FFF,
28 0x0000, 0x0000, 0x0000,
29 0x0000, 0x0000, 0x0000,
30 0x0000, 0x0FFF, 0x0000};
31 // determine size of data array
32 int arr_length = sizeof(data) / sizeof(unsigned int);
33 // calculate checksum
34 generate_crc(data, arr_length);
35 return 1;
36 }
This example refers to the default register values. The checksum of this data sequence is
DBh.