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.

[FAQ] [参考译文] [常见问题解答] TPS274C65:CRC 计算函数示例

Guru**** 2322270 points
Other Parts Discussed in Thread: TPS274C65
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/power-management-group/power-management/f/power-management-forum/1515831/faq-tps274c65-crc-calculation-function-example

器件型号:TPS274C65

工具/软件:

 TPS274C65器件具有可选的循环冗余校验(CRC)功能、可确保正确发送和接收每个 SPI 帧(SPI 格式:COPL = 0、CPHA = 1)。 此 CRC 计算基于 CRC-4-ITU 标准、多项式为 x4  + x + 1、起始值为1111。 有关更多信息、请参阅 TPS274C65数据表。 请参阅下面有关如何计算 CRC 位的代码示例:

uint8_t crc_encode(uint8_t send_rec_bytes[3])
{
  uint8_t crc_start = 0x0F;
  uint8_t crc_polynomial = 0x03;
  uint8_t crc_result = crc_start;
  uint8_t bitnum = 0;
  uint8_t bytenum = 0; 

for (bytenum = 0;bytenum < 3;bytenum++)
 {
    for(bitnum = 0; bitnum < 8; bitnum++)
    {
      if((((send_rec_bytes[bytenum] >> (7-bitnum)) & 0x01) ^ ((crc_result & 0x08) >> 3)) > 0)
        crc_result = crc_polynomial ^ ((crc_result << 1) & 0x0F);

      else
        crc_result = (crc_result << 1) & 0x0F;
    }

  }

  for(bitnum = 0; bitnum < 4; bitnum++)
  {
    if(((crc_result & 0x08) >> 3) > 0)
      crc_result = crc_polynomial ^ ((crc_result << 1) & 0x0F);
    else
      crc_result = (crc_result << 1) & 0x0F;
  }

  return crc_result;
}

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    有关更多信息、请点击页面右上角的红色"提出新问题"按钮创建新帖子。

    谢谢、

    Patrick

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    很好的例子!