Gast
#2542630
Hallo, Wintermonate sind SW-Spielmonate. Ich will bei meinem Datenprotokoll die bisherige 16bit Checksum durch CRC16 nach CCITT erstezen. Aber das funzt nicht. Ich will nicht nerven, habe auch fleißig rumgegoogelt und auch hier im Forum gesucht, aber ich stehe auf dem Schlauch. Nehmen wir mal an, die Nachricht besteht nur aus $55, $AA, dann müßte die CRC laut "Breitbandkatze" sowie laut http://www.lammertbies.nl/comm/info/crc-calculation.html übereinstimmend 0xF8E5 ergeben. Aber die Nutzung Funktion des AVR-libc: _crc_ccitt_update (crc16, data) ergibt 0x57a7. Parallel habe ich das LIBC-Beispiel auf VB-express implementiert. Die Funktion: Private Function crc_ccitt_update(ByVal crc As UInt16, ByVal idata As Byte) As UInt16 Dim xdata As UInt16 xdata = idata xdata = xdata Xor (crc And &HFF) xdata = (xdata Xor (xdata << 4)) And &HFF crc = (((xdata << 8) Or (crc And &HFF00)) Xor (xdata >> 4) Xor (xdata << 3)) Return crc ' data ^= lo8 (crc); ' data ^= data << 4; ' return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4) ' ^ ((uint16_t)data << 3)); End Function ergibt den Wert: 0xFDD5 Dieser stimmt weder mit dem ergebnis der ASM-Implementierung der libc laut crc16.h überein noch mit Breitbandkatze. Eine Implementierung aus einer anderen Quelle: Private Function crc_ccitt_update_5(ByVal crc As UInt16, ByVal idata As Byte) As UInt16 Dim xdata As UInt16 xdata = idata ' x = ((crc>>8) ^ data) & 0xff; xdata = ((crc >> 8) Xor xdata) And &HFF ' x ^= x>>4; xdata = xdata Xor (xdata >> 4) ' crc = (crc << 8) ^ (x << 12) ^ (x <<5) ^ x; crc = (crc << 8) Xor (xdata << 12) Xor (xdata << 5) Xor xdata crc = crc And &HFFFF Return crc End Function hingegen ergab den "richtigen" Breitbandkatzewert 0xF8E5 Ist die libc bzw crc16.h falsch? Muß ich ggf. das Makefile anpassen? Meines ist "Standard" laut AVR Studio? Osder hat einer eine korrekte schnelle Implementierung in ASM? Danke für Eure Mühen :-) Yogy