FrankBoesing / FastCRC

Fast CRC library for PC and ARDUINO
MIT License
149 stars 50 forks source link

MODBUS CRC does not seem to deliver correct value #32

Open holgersprute opened 2 years ago

holgersprute commented 2 years ago

Dear Frank,

thank you for your great work. I tried to use your library to calculate a CRC for MODBUS use. However, when I compare the output of your library for FastCRC16 MODBUS with the CRC Calculator https://crccalc.com/, then the output doesn´t match. For other CRC methods, the outputs are identical.

For example belowmodified example of yours delivers "0x25B4" as a result, while CRCCalc delivers "0x2590". REsults in case of KERMIT or CCITT are identical for your library and CRCCalc. Is there anything I do wrong, or is there an issue with the library?

/ FastCRC-Example (c) Frank Boesing 2014 /

include

include

FastCRC16 CRC16;

uint8_t buf[5] = {0x12, 0x34, 0x56, 0x78, 0x09 };

void setup() {

delay(1500); Serial.begin(115200);

Serial.println("CRC Example"); Serial.println();

Serial.print("MODBUS-CRC of \"");

for (unsigned int i = 0; i < sizeof(buf); i++) { Serial.print((char) buf[i]); }

Serial.print("\" is: 0x"); Serial.println( CRC16.modbus_upd(buf, sizeof(buf)), HEX );

}

void loop() { }

Thanks for checking, Holger

FrankBoesing commented 2 years ago

Yes, don't use _upd - it's for additional calls only and uses the last crc as seed.

Example: https://github.com/FrankBoesing/FastCRC/blob/master/examples/FastCRC_CRC16/FastCRC_CRC16.ino