能否给一个DAC7760的CRC校验的例子

使用CRC校验一直不成功,我是从高位到低位做CRC校验,发送过去一直不成功,以下是我的算法:

  s_spiReadCommandBuffer_temp[0]=READ_DAC_REG;
  s_spiReadCommandBuffer_temp[1]=0x00U; //Bit 15: Bit 0  Data word   
  s_spiReadCommandBuffer_temp[2]=READ_STATUS_REG;   

  s_spiReadCommandBuffer_temp[3]=GetCrc8(&s_spiReadCommandBuffer_temp[0],3U);

#define AL2_FCS_COEF ((1 << 7) + (1 << 6) + (1 << 5))

UBYTE GetCrc8(unsigned char * data, int length)/*check by the last byte*/
{
   UBYTE cFcs = 0;
   int i, j;
   
   for( i = 0; i < length; i ++ )
   {
      cFcs ^= data[i];
      for(j = 0; j < 8; j ++)
      {
         if(cFcs & 1)
         {
            cFcs = (UBYTE)((cFcs >> 1) ^ AL2_FCS_COEF);
         }
         else
         {
            cFcs >>= 1;
         }
      }
   }
   

   
 
   return cFcs;
 
}

是否可以帮忙看一下哪里有问题???

1 个回复