SV: [Icc-avr] CheckSum

John Baraclough j_baraclough at zetnet.co.uk
Tue May 27 07:12:36 PDT 2008


Hi Steven,

Yes, you remembered correctly. That is the CRC16 calculation for the 
Modbus protocol. Of course, it works perfectly well for any other protocol.

All the best for now,
John
 

Steven Lose wrote:
>
> Hi Albert.
>
>  
>
> I got this CRC from John Baraclough (If I remenbor wrong then sorry to 
> the one I forgot)
>
>  
>
> Thanks anyway, works fine, I use it on all serial communication.
>
>  
>
>  
>
>  
>
>  
>
> unsigned int CalcCrc(unsigned char *Packet,unsigned char NumberOfBytes)
>
> {
>
>  #define POLYNOMIAL (unsigned int)0xa001
>
>  unsigned char ucByteCount,ucBitCount;
>
>  unsigned int uiCRC;
>
>  
>
>  uiCRC = 0xFFFF;                                       
>                                             
>                                                                 
>
>  
>
>  for(ucByteCount=0;ucByteCount<NumberOfBytes;ucByteCount++)
>
>  {
>
>   uiCRC ^= (unsigned int)(*Packet++);
>
>   for(ucBitCount=0;ucBitCount<8;ucBitCount++)
>
>   {
>
>    if(uiCRC & 0x0001)
>
>    {
>
>     uiCRC >>= 1;
>
>     uiCRC ^= POLYNOMIAL;
>
>    }
>
>    else
>
>     uiCRC >>= 1;
>
>   }
>
>  }
>
>  return uiCRC;
>
> }
>
>  
>
>  
>
> Med venlig hilsen / Best regards / mit freundlichen Grüßen
>
> *EC POWER A/S*
>
> *Steven Lose*
>
> Software Ingeniør
>
> Tlf.: +45 87434100
>
> Direkte tlf. +45 58286608
>
> Email: sl at ecpower.dk <blocked::mailto:bsl at ecpower.dk>
>
> www.ecpower.dk <http://www.ecpower.dk>
>
> ------------------------------------------------------------------------



More information about the Icc-avr mailing list