This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

bq76930003 crc 效验算法



 看了数据手册,没明白这个CRC算法,知道的大神能说明一下吗? 我是单字节读取,CRC应寄存器地址和读取的数据计算,但是具体怎么计算呢?红线标注的这个多项式中的X又代表哪项的值呢?

  • ***************************************************************************
    //CRC效验程序
    ***************************************************************************/ 
    unsigned char cal_crc(unsigned char *ptr, unsigned char len)
     {
    	unsigned char i;
    	unsigned char crc=0;
    	while(len--!=0)			 //5次循环
    	{
    		for(i=0x80; i!=0; i/=2)   //8次for循环
    		{
    			if((crc&0x80)!=0)	 //判断最高位是否是1
    				{crc*=2; crc^=0x07;} /* 余式CRC乘以2再求CRC */
    			else 
    				crc*=2;
    			if((*ptr&i)!=0) 
    				crc^=0x07; /* 再加上本位的CRC */
    		}
    		ptr++;
    	}
    	return(crc);
    }