DAP CRC-6 algorithm is not correct on data sheet

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User17092
Level 1
Level 1
Hi Support team,
On DAP module TSv2.3, CRC-6 algorithm is not correct on section 1.8.3. We cannot get correct CRC value for transmitting packets. The result of function GetCrc cannot pass CRC Check at all.

Does anyone report similar issue?
Thanks!
0 Likes
5 Replies
User17092
Level 1
Level 1
Here are the codes from the document:

const unsigned crc6Polynom =0x03; // x**6 + x + 1
unsigned CalcCrc(unsigned crcValue, unsigned thisbit) {
unsigned m = crcValue & crc6Polynom;
while (m > 0) {
thisbit ^= (m & 1);
m >>= 1;
}
return (((thisbit << 6) | crcValue) >> 1);
}
// obtain CRC6 for sending (6 bit)
unsigned GetCrc(unsigned crcValue) {
unsigned crc6 = 0; int i;
for (i = 0; i < 6; i++) {
crcValue = CalcCrc(crcValue, 0);
crc6 |= (crcValue & 0x20) | (crc6 >> 1);
crcValue &= 0x1F; // remove output bit
}
return (crc6);
}
// Calculate CRC6
for (i = 1; i < nDataBits; i++) { // Startbit excluded
thisBit = (unsigned)((telegram >> i) & 0x1);
crcValue = CalcCrc(crcValue, thisBit);
}
/* now send telegram + GetCrc(crcValue) */

// Check CRC6
unsigned crcValue = 0x3f;
int i;
unsigned thisBit;
for(i=1; i thisBit = (unsigned)((telegram>>i)&0x1);
crcValue = CalcCrc(crcValue, thisBit);
}
if(crcValue!=0) { /* put error handler here */ }


This is not the standard CRC6 algorithm. The issue is function GecCrc.
0 Likes
User17092
Level 1
Level 1
Got this issue solved. The CRC algorithm on document is TOTALLY wrong.
0 Likes
User17829
Level 1
Level 1
Hi Robinliuy,

may I ask you to share how you could solve this problem ?

I'm currently facing same issue. Impossible to pass the CRC6 check. I got the same C-Like code in my reference document.

Thanks in advance.
Best regards.
0 Likes
ManojK
Employee
Employee
10 sign-ins First reply posted 5 sign-ins

Dear User17829,

Please refer the following piece of code for your query.

#include <stdio.h>
#include <stdint.h>

const unsigned crc6Polynom = 0x03; // x**6 + x + 1
unsigned CalcCrc(unsigned crcValue, unsigned thisbit)
{
    unsigned m = crcValue & crc6Polynom;
    while (m > 0)
    {
        thisbit ^= (m & 1);
        m >>= 1;
    }
    return (((thisbit << 6) | crcValue) >> 1);
}
// obtain CRC6 for sending (6 bit)
unsigned GetCrc(unsigned crcValue)
{
    unsigned crc6 = 0;
    for (int i = 0; i < 6; i++)
    {
        crcValue = CalcCrc(crcValue, 0);
        crc6 |= (crcValue & 0x20) | (crc6 >> 1);
        crcValue &= 0x1F; // remove output bit
    }
    return (crc6);
}
int main()
{
    int i = 0;
    /* Data: 0x55 LEN: 001000, CMD: 11010, Startbit: 1*/
    uint32_t telegram = 0b01010101001000110101;
    uint8_t nDataBits = 20 + 6; // Including crc bits

    // uint32_t telegram = 0b1001011000111110101;
    // uint8_t nDataBits = 19 + 6;

    // uint32_t telegram = 0b0000001100001010010101;
    // uint8_t nDataBits = 22 + 6;

    // Calculate CRC6
    unsigned crcValue = 0x3F;
    for (i = 1; i < nDataBits; i++)
    { // Startbit excluded
        unsigned thisBit = (unsigned)((telegram >> i) & 0x1);
        crcValue = CalcCrc(crcValue, thisBit);
    }
    /* now send telegram + GetCrc(crcValue) */
    printf("CalcCrc: 0x%02x\n", crcValue);
    telegram = telegram | crcValue << nDataBits - 6; // CRC6 + Telegram
    // Check CRC6
    crcValue = 0x3F;
    for (i = 1; i < nDataBits + 6; i++)
    { // No startbit, but with CRC
        unsigned thisBit = (unsigned)((telegram >> i) & 0x1);
        crcValue = CalcCrc(crcValue, thisBit);
    }
    if (crcValue != 0)
    { /* put error handler here */
        printf("CRC Error\n");
    }
}

 

Regards

ManojK

0 Likes
StanWang
Level 1
Level 1
First reply posted Welcome!

Dear sir,

i am also intersted in DAP.

could you please tell me where could find DAP module TSv2.3 ?

i could not search it from website.

thank you.

 

0 Likes