板子:M471
例程:CRC_CCITT
main函数部分
/*---------------------------------------------------------------------------------------------------------*/
/* MAIN function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
const uint16_t u16CRCSrcPattern[] = {0x3231, 0x3433, 0x3635, 0x3837};
uint32_t i, u32TargetChecksum = 0xA12B, u32CalChecksum = 0;
/* Init System, peripheral clock and multi-function I/O */
SYS_Init();
/* Init UART0 for printf */
UART0_Init();
printf("\n\nCPU [url=home.php?mod=space&uid=72445]@[/url] %d Hz\n", SystemCoreClock);
printf("+---------------------------------------------+\n");
printf("| CRC-CCITT Polynomial Mode Sample Code |\n");
printf("+---------------------------------------------+\n\n");
printf("# Calculate [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38] CRC-CCITT checksum value.\n");
printf(" - Seed value is 0xFFFF \n");
printf(" - CPU write data length is 16-bit \n");
printf(" - Checksum complement disable \n");
printf(" - Checksum reverse disable \n");
printf(" - Write data complement disable \n");
printf(" - Write data reverse disable \n");
printf(" - Checksum should be 0x%X \n\n", u32TargetChecksum);
/* Configure CRC controller for CRC-CCITT CPU mode */
CRC_Open(CRC_CCITT, 0, 0xFFFF, CRC_CPU_WDATA_16);
/* Start to execute CRC-CCITT operation */
for(i = 0; i < sizeof(u16CRCSrcPattern) / sizeof(u16CRCSrcPattern[0]); i++)
{
CRC_WRITE_DATA((u16CRCSrcPattern[i]));
}
/* Get CRC-CCITT checksum value */
u32CalChecksum = CRC_GetChecksum();
printf("CRC checksum is 0x%X ... %s.\n", u32CalChecksum, (u32CalChecksum == u32TargetChecksum) ? "PASS" : "FAIL");
/* Disable CRC function */
CLK_DisableModuleClock(CRC_MODULE);
while(1);
}
虽然跑了例程,
但是对CRC部分还是不怎么理解
之前做CRC校验,会有个CRC函数,通过校验函数来判断数据的正确性。
像这种CRC的例程,其目的是校验数据么?怎么操作的。
另外,CRC的这几个例程,CCITT是个什么意思?
可能在高手看来,我的问题很简单,但我确实没搞明白,希望有时间的高手可以帮忙解答
|