Hi,
komme nicht auf die richtigen Ergebnisse...
Habe einen undefinierte Anzahl von Bytes und möchte diesen 2byte CRC16
Prüfsumme hinzufügen.
Benutze folgende Funkion aus dem Forum:
1 | u16 calcCRC16r(u16 crc, u16 c, u16 mask)
|
2 | {
|
3 | unsigned char i;
|
4 | for(i=0;i<8;i++)
|
5 | {
|
6 | if((crc ^ c) & 1) { crc=(crc>>1)^mask; }
|
7 | else crc>>=1;
|
8 | c>>=1;
|
9 | }
|
10 | return (crc);
|
11 | }
|
und möchte es so aufrufen (5 Daten-Bytes):
1 | u16 crc = 0x0000;
|
2 | u16 crcData = 0;
|
3 |
|
4 | crcData = (ConfigGlobal.myAdress << 8) | ConfigGlobal.masterAdress;
|
5 | crc = calcCRC16r(crc, crcData, CRC16_POLYNOM); // Byte 1+2
|
6 | crc = calcCRC16r(crc, (8<<1) | 1, CRC16_POLYNOM); // Byte 3+4
|
7 | crc = calcCRC16r(crc, (!ConfigGlobal.EndModule) << 8, CRC16_POLYNOM); // Byte 5 + x
|
8 | // war das Richtig???? und jetzt??? wie bekomme ich in byte 6 + 7 die Prüfsumme????
|
9 | crc = calcCRC16r(crc, 0, CRC16_POLYNOM);
|
Habe folgende Daten als Beispiel "05fe080101" (hex)...
laut Online Calculator sollte 0x7ABC als Prüfsumme rauskommen, nur kommt
bei mir nicht....
Was mache ich falsch???