MSP430FR5739的CRC如何用
我有一块MSP430FR5739板子,我写了个CRC程序,可是不对。请高手指教。谢谢!
附代码:
#include "msp430fr5739.h"
unsigned int value; //写入到信息段A的8位数值
//函数声明
void write_SegA(char value);
void copy_A2B(void);
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
//FCTL2=FWKEY+FSSEL0+FN0; //定义时钟
CRCINIRES=0X0FFFF;
CRCDI_L=0X00035;
CRCDI_L=0X00034;
if(CRCINIRES==0x1737) //此处CRCINIRES的值是65535
;
else
;
while(1)
{
}
return 0;
}
没看到CRC相关的运算代码啊
这款芯片有硬件CRC代码。 这个芯片还真没用过,你看看这个资料:https://bbs.21ic.com/icview-150181-1-1.html 谢谢! #include "io430.h"
#include<stdio.h>
#include<stdlib.h>
typedefunsigned int uint16;
typedefunsigned char uint8;
uint8 data1 = { 0x35,0x34};
void InvertUint8(unsigned char *dBuf,unsigned char *srcBuf)
{
int i;
unsigned char tmp;
tmp = 0;
for(i=0;i< 8;i++)
{
if(srcBuf& (1 << i))
tmp|=1<<(7-i);
}
dBuf = tmp;
}
void InvertUint16(unsigned short *dBuf,unsigned short *srcBuf)
{
int i;
unsigned short tmp;
tmp = 0;
for(i=0;i< 16;i++)
{
if(srcBuf& (1 << i))
tmp|=1<<(15 - i);
}
dBuf = tmp;
}
unsigned int CRC16_MODBUS(unsigned char *puchMsg, unsigned int usDataLen)
{
unsigned short wCRCin = 0xFFFF;
unsigned short wCPoly = 0x8005;
unsigned char wChar = 0;
while (usDataLen--)
{
wChar = *(puchMsg++);
InvertUint8(&wChar,&wChar);
wCRCin ^= (wChar << 8);
for(int i = 0;i < 8;i++)
{
if(wCRCin & 0x8000)
wCRCin = (wCRCin << 1) ^ wCPoly;
else
wCRCin = wCRCin << 1;
}
}
InvertUint16(&wCRCin,&wCRCin);
return (wCRCin) ;
}
int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
unsigned int data;
data = CRC16_MODBUS(data1,2);
//data = CRC16_USB(data1,2);
printf("0x%x",data);//0xc9cb
return 0;
}
这段代码算出来是0x3717
页:
[1]