I am having problem reproducing the CRCCU calculation on the host computer using C. I am using the SAM4L MCU and CCITT-16 which I understand has a polynomial of 0x11021. The result doesn't match any of the online calculators or any of the test programs I have found. Does anyone have an example that matches the algorithm use in the hardware?

Also, the Technical Support link at the top of this page doesn't seem to connect to a valid web page.

## CRCCU calculation problem

### Re: CRCCU calculation problem

The polynomial for CCITT-16 implemented is 0x1021 (the most significant bit is assumed in the algorithm and not listed in the polynomial define). The implementation of the CRC-CCITT depends on the initial value (also no reverse byte, reverse result or swap result). Here is a website that you can put some ASCII characters and see that it matches the SAMx hardware CRC generator.

http://www.lammertbies.nl/comm/info/crc ... ation.html

For the ASCII string "ABCDEFG" results in the CRC-CCITT (0xFFFF) = 0x47D0.

Here is a code snippet for the D21 which should be close or the same for the SAM4L.
Hope that helps

-Chris

http://www.lammertbies.nl/comm/info/crc ... ation.html

For the ASCII string "ABCDEFG" results in the CRC-CCITT (0xFFFF) = 0x47D0.

Here is a code snippet for the D21 which should be close or the same for the SAM4L.

Code: Select all

```
uint8_t mytestCRC[] = "ABCDEFG";
crc = CalCRC16((uint8_t *)&mytestCRC, 7);
```

Code: Select all

```
uint16_t CalCRC16(uint8_t *pSrc, uint32_t len)
{
uint32_t i;
/* disable the CRC engine */
DMAC->CTRL.reg &= ~DMAC_CTRL_CRCENABLE;
/* initialize start CRC value for the CRC16 */
DMAC->CRCCHKSUM.reg = 0xFFFF;
/* configure the CRC engine */
DMAC_CRCCTRL_Type crcctrl =
{
.bit.CRCSRC = DMAC_CRCCTRL_CRCSRC_IO_Val, /* I/O interface */
.bit.CRCPOLY = DMAC_CRCCTRL_CRCPOLY_CRC16_Val, /* CRC-16 (CRC-CCITT) */
.bit.CRCBEATSIZE = DMAC_CRCCTRL_CRCBEATSIZE_BYTE_Val, /* Byte bus access */
};
DMAC->CRCCTRL.reg = crcctrl.reg;
/* enable the CRC engine */
DMAC->CTRL.reg = DMAC_CTRL_CRCENABLE;
/* write all values that are used for the CRC calculation */
for (i = 0; i < len; i++)
{
DMAC->CRCDATAIN.reg = *pSrc++;
}
/* clear the busy bit */
DMAC->CRCSTATUS.bit.CRCBUSY = true;
/* get final CRC value */
return ((uint16_t) DMAC->CRCCHKSUM.reg);
}
```

-Chris

### Re: CRCCU calculation problem

I found the problem. Atmel is using the low bit instead of the high bit so reversing the values before calculation did the trick. Here is a calculator that matches (click CCITT and check the 'reverse data bytes' to get the correct value).

http://www.zorc.breitbandkatze.de/crc.html

The SAM4L calculates 0x1541 for ABCDEFG.

Thanks Chris for your answer.

http://www.zorc.breitbandkatze.de/crc.html

The SAM4L calculates 0x1541 for ABCDEFG.

Thanks Chris for your answer.

Return to “SAM4 Cortex-M4 MCU”

### Who is online

Users browsing this forum: No registered users and 2 guests