Checksum Calculation Algorithm
The checksum is calculated using Dallas APPLICATION NOTE 27 table method: Understanding and Using Cyclic Redundancy Checks with Dallas Semiconductor iButton Products. One can use the following algorithms to calculate the checksum with a polynom ^8 + a^5 + a^4 + 1 (C language):
Version 1:
1 U8 CRC8 (U8 b, U8 crc) 2 { 3 U8 i = 8; 4 do { 5 if ( (b ^ crc) & 0x01) { 6 crc = ( (crc ^ 0x18) >> 1 ) | 0x80; 7 } else { 8 crc >>= 1; 9 } 10 b >>= 1; 11 } while (--i); 12 return crc; 13 }
Version 2:
1 U8 CRC8(U8 data, U8 crc) 2 { 3 U8 i = data ^ crc; 4 crc = 0; 5 if(i & 0x01) crc ^= 0x5e; 6 if(i & 0x02) crc ^= 0xbc; 7 if(i & 0x04) crc ^= 0x61; 8 if(i & 0x08) crc ^= 0xc2; 9 if(i & 0x10) crc ^= 0x9d; 10 if(i & 0x20) crc ^= 0x23; 11 if(i & 0x40) crc ^= 0x46; 12 if(i & 0x80) crc ^= 0x8c; 13 return crc; 14 }