This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530 CRC calculation

Other Parts Discussed in Thread: CC2530

I would like to use CC2530 to calculate CRC check for 1byte data. According to CC253x User's Guide, the first to write two times RNDL, and then write a byte to the RNDH, read RNDH and RNDL, but the results of the calculation is always wrong. Is it something else to be noted or whether i missed any important thing?

Can you give revelant sample code?

Thanks.

  • Hi,

    Here is an example of using the random number generator in CRC mode:

    #include <ioCC2530.h>
    #define MSGLEN 5
    unsigned char msg[MSGLEN] = {0x11, 0x22, 0x33, 0x44, 0x55};
    unsigned char crc_ok;

    int main(void)
    {
        int i;
        unsigned char crcl, crch;
        // Calculate CRC over message
        RNDL = 0xFF; // Initialize CRC
        RNDL = 0xFF; // Initialize CRC
        for (i=0; i<MSGLEN; i++) {
            RNDH = msg[i]; // Enter data
        }
        crcl = RNDL;
        crch = RNDH;

        // Introduce error
        //msg[2] = 0x32;
       
        // Check CRC
        RNDL = 0xFF; // Initialize CRC
        RNDL = 0xFF; // Initialize CRC
        for (i=0; i<MSGLEN; i++) {
            RNDH = msg[i]; // Enter data
        }
        RNDH = crch;
        RNDH = crcl;
       
        if (RNDL == 0 && RNDH == 0) {
            // CRC OK
            crc_ok = 1;
        }
        else {
            // CRC not OK
            crc_ok = 0;
        }

        return crc_ok;
    }

    This code will give you crc_ok = 1. If you uncomment the msg[2] = 0x32; instruction, you will get crc_ok = 0.

    Note that the CRC polynomial used in the random number generator is not the same as the one used in IEEE 802.15.4, so it is not the same CRC as used in the radio.

  • Tanks hec. I have solved this problem.My main fault is compare this result to common CRC result,but the algorithms are very defferent,so i always think the result is wrong ,actually, with another algorithm ,it is right.

  • Does this means that the CRC value cannot be compared to any other CRC algorithm? It has to be written from the start?

    This is weird as the Datasheet says it implements "X^16 + X^15 + X^2 +1 (i.e. CRC16)" but in fact, the resulting value cannot be compared to any other CRC generator.

    If this is true, then how can one code the same CRC algorithm?

  • IAR will autmatically generate a checksum over the code it compiles and links. I used this CRC to embed in the OAD code image and then check the CRC using a S/W algo that they specified, in _hal_oad.c - see HalOADChkDL() and runPoly().

     

  • My question was a bit more general then OAD. I'm thinking in using the CRC for general data verification.

    After a bit more search, here is what I found: the above code that generates CRC using the LFSR

        RNDL = 0xFF; // Initialize CRC
        RNDL = 0xFF; // Initialize CRC
        for (i=0; i<MSGLEN; i++) {
            RNDH = msg[i]; // Enter data
        }
        crcl = RNDL;
        crch = RNDH;

    Is CRC16 but with Reflection Off (Because of the Big-Endian order).

       Width  : 16
       Poly   : 8005
       Init   : FFFF
       RefIn  : False
       RefOut : False
       XorOut : 0000
       Check  : AEE7
    

     

    By the way: runPoly() uses a different algorithm: CRC-16-CCITT (uses 0x1021 as Poly).

  • I want to use the Hardware CRC16 on CC2530,It's UserGuide  said that It's Poly is X^16+X^15+X^2+1,But I have test it for several times ,the result of CRC16 is not the same as the standard CRC16 (such as CRC16-IBM,CRC16-CCITT),Please tell me what Algorithm is used for the CRC16 on CC2530 and the Poly

     Thanks

  • The polynomial is as described in the user guide. The implementation is illustrated in Figure 14-1. The bytes written to RNDH will be input MSB first to the in_bit line of Figure 14-1.

    Could you please send your code for accessing the CRC generator (if it is not equal to the code I have posted previously in this thread), the data you are calculating CRC over, what result you get, what result you were expecting, and how you calculated your expected result?