PeterPan321:
I am basically using the same CRC call, which someone else provided earlier(response #1). Still trying to understand how the 0x8C plynomial relates to the data sheet formula, CRC = X8 + X5 + X4 + 1.
1. In the core of DS18B20, the polynomial function that is used to calculate 8-bit CRC-check value is:
X8 + X4 + X3 + 1 (=10001100 = 0x8C) and not X8 + X5 + X4 + 1 (10011000 = 0x98). How do I know it? I have known it from the following codes (Line-11) of ONeWire.h Library.
byte dsCRC8(const uint8_t *addr, uint8_t len)//begins from LS-bit of LS-byte (OneWire.h)
{
uint8_t crc = 0;
while (len--)
{
uint8_t inbyte = *addr++;
for (uint8_t i = 8; i; i--)
{
uint8_t mix = (crc ^ inbyte) & 0x01;
crc >>= 1;
if (mix) crc ^= 0x8C;
inbyte >>= 1;
}
}
return crc;
}
2. Why has Dallas chosen this polynomial? The answer can be found in this paper refereed by @el_supremo. The choice is just not a chance or random; it has a solid Mathematical Foundation for which this book could be consulted: Information Transmission, Modulation, and Noise ; by Mischa Schwartz; Fourth Edition; 1990; McGaw-Hill Book Company.