CRC16 help to find polynom for algoritm

Good evening!
I am using arduino uno to read data from industrial refrigerator (using RS232).
I`m getting message from reefer like this in hex: "3000EF000500000C00120188FAAB40"
Last two bytes is CRC16, I can detect it by online decoders, for example: http://www.lammertbies.nl/comm/info/crc-calculation.html , it writes that it is simple CRC16 alghoritm.

So, I`ve tried such code, but can`t get exact result:

``````#define POLYNOM		0x8005   // Define the used polynom from one of the aboves

unsigned int crc16(unsigned int crcValue, unsigned char newByte)
{
unsigned char i;

for (i = 0; i < 8; i++) {

if (((crcValue & 0x8000) >> 8) ^ (newByte & 0x80)){
crcValue = (crcValue << 1)  ^ POLYNOM;
}else{
crcValue = (crcValue << 1);
}

newByte <<= 1;
}

return crcValue;
}

/***** EXAMPLE *****/

unsigned int exampleOfUseCRC16 (unsigned char *Data, unsigned char len){

unsigned int crc;
unsigned char aux = 0;

crc = 0x0000; //Initialization of crc to 0x0000 for DNP
//crc = 0xFFFF; //Initialization of crc to 0xFFFF for CCITT

while (aux < len){
crc = crc16(crc,Data[aux]);
aux++;
}

return (~crc); //The crc value for DNP it is obtained by NOT operation

//return crc; //The crc value for CCITT
}

//byte buf[]={0x30,0x00,0xEF,0x00,0x05,0x00,0x00,0x0C,0x00,0x12,0x01,0x18,0xFC};
byte buf[]={0x30,0x00,0xEF,0x00,0x05,0x00,0x0,0x0C,0x00,0x12,0x01,0x88,0xFA};//,0xAB,0x40};crc16

void setup(){
Serial.begin(9600);
Serial.println( exampleOfUseCRC16(buf,13),HEX);

}

void loop(){}
``````

Code returns 0AC9, not AB40

I tried a lot of other polynoms, but result still not like in original system.

Please, someone has idea about how make the same CRC16 from message like refrigerator has?

I get CRC-16 checksum of 0x40AB

It may be that they are sending the MSB first.

If you have another hex string to try, you will know.

ieee488:
I get CRC-16 checksum of 0x40AB

It may be that they are sending the MSB first.

If you have another hex string to try, you will know.

Yes, indeed.

Simply use the AVR LIBC function named '_crc16_update()' to create the CRC:

``````#include <util/crc16.h>

byte buf[]={0x30,0x00,0xEF,0x00,0x05,0x00,0x0,0x0C,0x00,0x12,0x01,0x88,0xFA};

void setup(){
Serial.begin(9600);
uint16_t crc=0;
for(int i=0;i<13;i++) crc= _crc16_update(crc,buf[i]);
Serial.println(crc,HEX);
}

void loop(){
}
``````