Skip to content

Instantly share code, notes, and snippets.

@StuffAndyMakes
Created June 10, 2015 12:45
Show Gist options
  • Save StuffAndyMakes/ed0113cefdd5c59b7cae to your computer and use it in GitHub Desktop.
Save StuffAndyMakes/ed0113cefdd5c59b7cae to your computer and use it in GitHub Desktop.
CRC 8-bit
// CRC-8 - based on the CRC8 formulas by Dallas/Maxim
// code released under the therms of the GNU GPL 3.0 license
// Found at: http://www.leonardomiliani.com/en/2013/un-semplice-crc8-per-arduino/
uint8_t SerialPacket::_crc8(const uint8_t *data, uint8_t len) {
uint8_t crc = 0x00;
while (len--) {
uint8_t extract = *data++;
for (uint8_t tempI = 8; tempI; tempI--) {
uint8_t sum = (crc ^ extract) & 0x01;
crc >>= 1;
if (sum) {
crc ^= 0x8C;
}
extract >>= 1;
}
}
return crc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment