URL: <http://savannah.nongnu.org/bugs/?37901>
Summary: CRC-CCITT calculation incorrect Project: AVR C Runtime Library Submitted by: mojo Submitted on: Tue 11 Dec 2012 13:42:22 GMT Category: Library Severity: 3 - Normal Priority: 5 - Normal Item Group: libc code Status: None Percent Complete: 0% Assigned to: None Originator Email: Open/Closed: Open Discussion Lock: Any Release: 1.8.0 Fixed Release: None _______________________________________________________ Details: Using _crc_ccitt_update() gives the wrong result. You can verify the result by comparing it with known good implementations, e.g. the XMEGA CRC module, the Boost libraries (http://www.boost.org/doc/libs/1_41_0/libs/crc/index.html), or any number of online calculatored (e.g. http://www.zorc.breitbandkatze.de/crc.html or http://www.lammertbies.nl/comm/info/crc-calculation.html). I wrote the following code that works, and allows communication between an XMEGA with CRC module and one without when CRC functions are needed: uint16_t inline crc16_update(uint16_t crc, uint8_t data) { crc = (uint8_t)(crc >> 8) | (crc << 8); crc ^= data; crc ^= (uint8_t)(crc & 0xFF) >> 4; crc ^= (crc << 8) << 4; crc ^= ((crc & 0xFF) << 4) << 1; return(crc); } For reference the correct CRC-CCITT value of "HELLO" (5 bytes ASCII) is 0x49D6. The _crc_ccitt_update() function gives 0x258A. _______________________________________________________ Reply to this item at: <http://savannah.nongnu.org/bugs/?37901> _______________________________________________ Message sent via/by Savannah http://savannah.nongnu.org/ _______________________________________________ AVR-libc-dev mailing list AVR-libc-dev@nongnu.org https://lists.nongnu.org/mailman/listinfo/avr-libc-dev