Pololu Simple User Manual

Page 100

Advertising
background image

CRCTable[i] = getCRCForByte(i);

}

}

unsigned char getCRC(unsigned char message[], unsigned char length)

{

unsigned char i, crc = 0;

for (i = 0; i < length; i++)

crc = CRCTable[crc ^ message[i]];

return crc;

}

int main()

{

unsigned char message[3] = {0x83, 0x01, 0x00};

int i, j;

buildCRCTable();

message[2] = getCRC(message, 2);

for (i = 0; i < sizeof(message); i++)

{

for (j = 0; j < 8; j++)

printf("%d", (message[i] >> j) % 2);

printf(" ");

}

printf("\n");

}

Pololu Simple Motor Controller User's Guide

© 2001–2014 Pololu Corporation

6. Using the Serial Interface

Page 100 of 101

Advertising