使用内置函数计算msp430f5438a的crc的方法

时间:2014-03-04 12:43:24

标签: crc msp430

我已经通过了CCITT和TI关于msp430的文档。是否可以使用任何内置函数计算MSP430F5438A的CRC?或者我必须为每个采集的数据计算CRC。

1 个答案:

答案 0 :(得分:0)

可以使用软件实现代替MSP430F5438A上的硬件外设。它可以实现如下:

unsigned short crc16(volatile unsigned char *sbuf,unsigned char len){
    unsigned short crc=0xFFFF;

    while(len){
        crc=(unsigned char)(crc >> 8) | (crc << 8);
        crc^=(unsigned char) *sbuf;
        crc^=(unsigned char)(crc & 0xff) >> 4;
        crc^=(crc << 8) << 4;
        crc^=((crc & 0xff) << 4) << 1;
        len--;
        sbuf++;
    }
    return crc;
}//crc16()

代码由Jens-Michael Gross提供@ e2e.ti.com(http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/19030.aspx