calculates CRC16 as per EN13757-4

[复制链接]
1207|11
 楼主| yutianhai 发表于 2017-12-4 08:22 | 显示全部楼层 |阅读模式
做个笔记:
#include "crc.h"
#include <stdint.h>
//------------------------------------------------------------------------------------------------
-------
// uint16 crcCalc(uint16 crcReg, uint8 crcData)
//
// DESCRIPTION:
// Calculates the 16-bit CRC. The function requires that the CRC_POLYNOM
// is defined, which gives the wanted CRC polynom.
//
// ARGUMENTS:
// uint8 crcData - Data to perform the CRC-16 operation on.
// uint16 crcReg - Current or initial value of the CRC calculation
//
// RETURN:
// The value returned is the 16-bit CRC (of the data supplied so far).
//------------------------------------------------------------------------------------------------
-------
uint16_t crcCalc(uint16_t crcReg, uint8_t crcData)
{
uint8_t i;
for (i = 0; i < 8; i++)
{
// If upper most bit is 1
if (((crcReg & 0x8000) >> 8) ^ (crcData & 0x80))
crcReg = (crcReg << 1) ^ CRC_POLYNOM;
else
crcReg = (crcReg << 1);
crcData <<= 1;
}
return crcReg;
}
// CRC_POLYNOM 0x3D65

dirtwillfly 发表于 2017-12-4 16:17 | 显示全部楼层
wwppd 发表于 2017-12-5 21:41 | 显示全部楼层
这个校验位是多少?
jkl21 发表于 2017-12-5 21:41 | 显示全部楼层
以前在FPGA上做过CRC校验,麻烦多了。
maqianqu 发表于 2017-12-5 21:42 | 显示全部楼层
EN13757-4是什么?
dspmana 发表于 2017-12-5 21:42 | 显示全部楼层
请问,msp430执行这个代码需要多个周期?
wwppd 发表于 2017-12-5 21:43 | 显示全部楼层
校验的速度应该快不了。
jkl21 发表于 2017-12-5 21:43 | 显示全部楼层
看到楼主做的应该是8位的CRC吧
maqianqu 发表于 2017-12-5 21:43 | 显示全部楼层
CRC16源代码网上有很多。
dspmana 发表于 2017-12-5 21:43 | 显示全部楼层
有很多的数据的是怎么实现的CRC算法的?
hotpower 发表于 2017-12-24 20:33 来自手机 | 显示全部楼层
本帖最后由 hotpower 于 2017-12-24 20:42 编辑

http://www.21ic.com/tools/HotPower/HotWC3_V1.23.html
hotpower 发表于 2017-12-24 20:34 来自手机 | 显示全部楼层
它可以自动生成CRC表格和CRC源码。可以生成5种算法
您需要登录后才可以回帖 登录 | 注册

本版积分规则

2

主题

18

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部