I have used this C code posted by others in the forum. But i found that i can only do CRC for 7 bytes. Is it the problem of only 16 elements in the feedback array? or why?
/**************************************************************************** * * NAME: Crc8() * PURPOSE: Generate 8-bit CRC. * * SYNOPSIS: unsigned char Crc8(unsigned char b, unsigned char initCrc); * * INTERFACE PARAMETERS: * * Name FG-IO Description * ------------------- ----- ----------------------------------------- * b F I Data byte to CRC (MSBit first). * initCrc F I Initial CRC or CRC accumulator for * continuation. * <return value> O CRC. * * DESCRIPTION: * * The function returns the 8-bit CRC after including "b" with the * initial CRC "initCRC". * ****************************************************************************/ static const UCHAR code feedback[16] = { 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15, 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D }; UCHAR CRC8(UCHAR b, UCHAR CRC) { CRC = (CRC << 4) ^ feedback[((CRC) ^ b) >> 4]; CRC = (CRC << 4) ^ feedback[((CRC >> 4) ^ b) & 0x0F]; return (CRC); }