SLAA476B February 2011 – July 2019 BQ2040 , BQ2040 , BQ2060A , BQ2060A , BQ2063 , BQ2063 , BQ2083-V1P3 , BQ2083-V1P3 , BQ2084-V143 , BQ2084-V143 , BQ2084-V150 , BQ2084-V150 , BQ2085-V1P3 , BQ2085-V1P3 , BQ20Z40-R1 , BQ20Z40-R1 , BQ20Z70-V160 , BQ20Z70-V160 , BQ20Z80A-V110 , BQ20Z80A-V110 , BQ28400 , BQ28400 , BQ78PL114 , BQ78PL114 , BQ78PL116 , BQ78PL116 , LM5145 , LM5145 , MSP430F5500 , MSP430F5500 , MSP430F5501 , MSP430F5501 , MSP430F5502 , MSP430F5502 , MSP430F5503 , MSP430F5503 , MSP430F5504 , MSP430F5504 , MSP430F5505 , MSP430F5505 , MSP430F5506 , MSP430F5506 , MSP430F5507 , MSP430F5507 , MSP430F5508 , MSP430F5508 , MSP430F5509 , MSP430F5509 , MSP430F5510 , MSP430F5510 , TPS40057 , TPS40057 , TPS40170 , TPS40170
This function implements the cyclic redundancy check (CRC) algorithm to generate the PEC byte. It has been derived from the CRC16 and CRC32 functions presented in CRC Implementation With MSP430 MCUs and has been modified to output a CRC-8 error check byte [8]. It performs XOR operations in the order the bits are received using the CRC-8 polynomial: C(x) = x8 + x2 + x1 + 1. The calculation is done on all bytes including device addresses, Read/Write bits, and SBS commands. However, it does not include the START, repeated START, ACK, NACK, or STOP bits.
Function Definition
unsigned short crc8MakeBitwise(unsigned char CRC, unsigned char Poly, unsigned char *Pmsg, unsigned int Msg_Size) {...}
Inputs
Name | Type | Description | Example Value |
---|---|---|---|
CRC | unsigned char | Initial value of the CRC byte | CRC8_INIT_REM |
Poly | unsigned char | CRC-8 polynomial 0x07 (the ‘1’ in the polynomial 0x107 is implied) | CRC8_POLY |
*Pmsg | unsigned char | Input stream for which the CRC-8 PEC byte is computed. | Data stream parsed into an array of byte-size elements |
Msg_Size | unsigned char[] | Number of bytes in the input bit stream | 5 (for five bytes) |
Return
Name | Type | Description |
---|---|---|
unsigned short | unsigned short | The computed CRC-8/PEC byte. |
Example Function Call
To calculate the CRC-8/PEC byte with a five-element array:
unsigned char crc_msg[5];
crc_generated = crc8MakeBitwise(CRC8_INIT_REM, CRC8_POLY, crc_msg, crc_msg_size);