Skip to content
Arnd edited this page Dec 3, 2016 · 1 revision

crc8(buffer,buflen);

This uses the standard MAXIM crc8 algorithm as described at Understanding and Using Cyclic Redundancy Checks with Maxim 1-Wire and iButton Products to compute the cyclical redundancy checks. The standard Arduino 1-Wire library contains a very fast table lookup variation of this algorithm, but it consumes 255 bytes of program memory. Rather than reserve that large space the slower computational method is used in the DS-Family library.

The crc8 is used extensively within the library to ensure that the data being read from the 1-Wire microLAN devices is correct. It has been declared as a public function since it is can be used outside of the scope of 1-Wire to compute CRCs.


Example:

const uint8_t ONE_WIRE_PIN = 8;             // 1-Wire microLAN pin
DSFamily_Class ds(ONE_WIRE_PIN);            // Instantiate
char array1[4] ="hi!";
char array2[4] ="HI!";
Serial.print("String \"");
Serial.print(array1);
Serial.print("\" has a crc of ");
Serial.println(ds.crc8(array1,sizeof(array1));
Serial.print("String \"");
Serial.print(array2);
Serial.print("\" has a crc of ");
Serial.println(ds.crc8(array2,sizeof(array1));