diff --git a/OneWire.cpp b/OneWire.cpp index cf34933..4499246 100644 --- a/OneWire.cpp +++ b/OneWire.cpp @@ -519,8 +519,11 @@ uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len) uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len) { uint8_t crc = 0; - + while (len--) { +#if defined(__AVR__) + crc = _crc_ibutton_update(crc, *addr++); +#else uint8_t inbyte = *addr++; for (uint8_t i = 8; i; i--) { uint8_t mix = (crc ^ inbyte) & 0x01; @@ -528,6 +531,7 @@ uint8_t OneWire::crc8(const uint8_t *addr, uint8_t len) if (mix) crc ^= 0x8C; inbyte >>= 1; } +#endif } return crc; } diff --git a/OneWire.h b/OneWire.h index 8753e91..b66b7eb 100644 --- a/OneWire.h +++ b/OneWire.h @@ -3,6 +3,10 @@ #include +#if defined(__AVR__) +#include +#endif + #if ARDUINO >= 100 #include "Arduino.h" // for delayMicroseconds, digitalPinToBitMask, etc #else