User`s guide
Page 10 of 21
Ph: 1-443-569-3603 Fax: 1-443-926-9402 Web: www.zephyr-technology.com
9700.0031 © Zephyr Technology 2010 2010-07-22
6.1.5. CRC
An 8-bit CRC is used and has a polynomial of 0x8C (CRC-8), with the accumulator being initialised to zero before
the CRC calculation begins. The following source code indicates the required implementation:
crc: The current CRC.
Ch: Value to add to the CRC calculation.
Void crc8PushByte(uint8_t *crc, uint8_t ch)
{
uint8_t i;
*crc = *crc ^ ch;
for (i=0; i<8; i++)
{
if (*crc & 1)
{
*crc = (*crc >> 1) ^0x8C;
}
else
{
*crc = (*crc >> 1);
}
}
}
pcrc: Pointer to running CRC to update (set this to something before first call).
Block: Pointer to the.block of data to push through.
Count: The number of bytes to push.
Return: The computed CRC (result also updated in pcrc if that is non-NULL).
Uint8_t crc8PushBlock(uint8_t *pcrc, uint8_t *block, uint16_t count)
{
uint8_t crc = pcrc ? *pcrc : 0;
for (; count>0; --count,block++)
{
crc8PushByte(&crc, *block);
}
if (pcrc) *pcrc = crc;
return crc;
}
6.1.6. ETX
The ETX field (End of Text) is a standard ASCII control character (0x03) and denotes the end of the message.