CRC calculation for PIC16/PIC18/PIC32 controller

Status
Not open for further replies.

ajit_nayak87

Member level 5
Joined
Oct 30, 2017
Messages
86
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
981
Dear all,
I am looking for CRC calculation . I have found code and its working fine.
I found few question Here

  • How to selected polynomial value??
  • if i want to extend range how can change

Below polynomial calculation for 8 bit , if i like to change for 16 bit and 32 bit controller how can change same below code.

How


Here length is 30 how can select polynomial value is there any excel sheet and how to read it and how to put below values.
Code:
unsigned int crc_fn(unsigned char *dpacket,unsigned int len)    // CRC Function(Error calcualtion)
{
     unsigned int crc = 0xffff,poly = 0xa001;

                
     for(i=0;i<len;i++)
     {
        crc^= dpacket[i];
        for(j=0;j<8;j++)
        {
              if(crc & 0x01)
              {
                   crc >>= 1;
                   crc ^= poly;
              }
              else
                     crc >>= 1;
        }
     }
     return (crc);     
}
 

Below polynomial calculation for 8 bit , if i like to change for 16 bit and 32 bit controller how can change same below code.

The calculation scheme mainly depends on the used CRC polynomial, in this case CRC-16. The same code would be used with 16 or 32 bit processors. A big performance improvement can be achieved by using table method instead of bitwise calculation.
 

@easyrider **broken link removed**

I have gone through link. Is there any ccode where i can use function 3 & function 1 modbus RTU
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…