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.

CC1350: CRC implementation on CC1350's launchpad

Part Number: CC1350

Hi guys, How do I calculate the CRC of my received packet from cc1350 launchpad(cc1350 chip is transmitter ) ? 

I sent my RF packets by CC1350 transmitter, and Im sampling those packets, I succeeded to see my packets as binary values, and all what I want to do is to calculate the CRC of my received packet.

I note that the received packet is in binary values.

In addition, what's the CRC in my transmitter ?

  • In general in order to calculate the CRC we are doing XOR with bits of the data packet, but there're many crc implementations, so what the crc implementation does the cc1350 launchpad have? thanks alot.

  • Im transmit my packets by smartRF studio alongside hardware cc1350 chip(launchpad)

  • First of all, why do you want to calculate the CRC yourselves when the radio does it for you? CRC calculation is enabled by the pktConf.bUseCrc in the RX and TX commands. Info regarding the CRC, and how it can be changes can be found here:

    Siri

  • Im building my own receiver, I mean Im building and coding my own received for RF cc1350 packets ... so that's why I want to know what type of crc implementation does the cc1350 launchpad has ..

    in the file you attached there's no explanation on how could I calculate the crc of my received packet ..!

    to be more clear I sent for instance one RF packet by my transmitter (cc1350 plays as transmitter) and in my own receiver I get that packet which it's for instance [10101010101010101010101010101010111111111111001010101000] so I want to calculate the CRC of my received packet in order to know if my packet is valid or not ! 

    thanks alot..

  • Any file that explain how can I calculate the CRC in my cc1350 launchpad would be appreciated to attach it because all what I want is how can I calculate crc of my received packet.

    thanks

  • The link I sent you contain the C code you need to check your CRC on the receive side also.

    Assume you transmit a packet that is 5 bytes long and the CC1350 automatically calculates CRC and add it to the packet.

    what you send on the air will for example be:

    Preamble, sync word, length byte (0x03), payload (0x01, 0x02, 0x03), CRC1, CRC0

    On the receiver you must make sure you receive all your data int he data entry, including the CRC bytes. You can store the received data in a variable called rxBuffer.

    rxBuffer[] = {0x03, 0x01, 0x02, 0x03, CRC1, CRC0).

    To manually check the CRC you do:

    // check CRC
    checksum = CRC_INIT;
    
    for(i = 0; i < sizeof(rxBuffer); i++)
    {
        checksum = culCalcCRC(rxBuffer[i], checksum);
    }
        
    if(checksum == 0)
    {
        crcOK = true;
    }
    else
    {
        crcOK = false;
    }
    

    Siri

  • Hi Siri, I appreciate your help alot!

    but what is that "automatically cc1350 calculate it" ? I need to know how does he calculate it in order to be able to decode the CRC in my received packet!

    secondly , regarding to the code you wrote in c, what's the value of CRC_INIT? Im using matlab and I have yet succeeded to find the started index of my received packet and all what Im trying to do is to find the CRC of my received packet and compare it to my crc before my packet gets transmitted  (still dont know my crc before transmitting) and then decide if the are the same then the packet is ok, otherwise it's not ok. 

    thirdly, my algorithm that I sugggested it in my second note above isn't good for determining of my pack ok or not ok? if so, then what's good algorithm to find if my received packet is ok by CRC method?

    thanks alot

  • I am afraid I do not understand what in my answer is unclear and how I can explain this.

    1) First of all, I do not understand why you need to calculate the CRC yourself as long as you you can tell the CC1350 to automatically generate a CRC that it sent with the packet, and then automatically check the CRC to tell you if the packet is OK or not. You do not have to care about what the CRC is, because the chips is doing this automatically for you.

     2) If you for some reason want to calculate the CRC yourself and add it to the payload you are sending, you can turn off CRC in the API, and then use the code I sent you to generate the CRC. The C code will give you the exact same CRC as the chip will automatically calculate and automatically add.

    If you open the first link that I sent you, you will find the value for CRC_INIT.

    The code I have sent you is good for calculating the CRC (on the transmitter side) and checking the CRC (on the receiver side).

    The way the CRC works is that if you first generate a CRC over for example 6 bytes, you get a two byte CRC (this is what is added to your packet on the TX side). If you, on the RX side, generate a CRC over the received 8 bytes (the payload+ the two CRC bytes that are appended), the CRC will be 0. This indicated that the CRC is OK.

    #define CRC16_POLY  0x8005
    #define CRC_INIT    0xFFFF
    
    uint16_t calcCRC(uint8_t crcData, uint16_t crcReg)
    {
        uint8_t i;
        for (i = 0; i < 8; i++)
        {
            if (((crcReg & 0x8000) >> 8) ^ (crcData & 0x80))
            {
                crcReg = (crcReg << 1) ^ CRC16_POLY;
            }
            else
            {
                crcReg = (crcReg << 1);
            }
            crcData <<= 1;
        }
        return crcReg;
    }
    
    void *mainThread(void *arg0)
    {
        uint8_t txBuffer[] = {5, 1, 2, 3, 4, 5};
        uint8_t rxBuffer[] = {5, 1, 2, 3, 4, 5, 0, 0}; // Two last bytes are for CRC
        uint16_t checksum;
        bool crcOK = false;
        uint8_t i;
    
        checksum = CRC_INIT; // Init value for CRC calculation
    
        for (i = 0; i < sizeof(txBuffer); i++)
        {
            checksum = calcCRC(txBuffer[i], checksum);
        }
    

    After running the code above, the checksum will be 0xA884

    Assuming that you are manually adding this to you payload and send it over the air.

    On the RX side, you will have the following in your receive buffer:

    rxBuffer[] = {0x05, 0x01, 0x02, 0x03, 0x04, 0x05, 0xA8, 0x84}

    checksum = CRC_INIT;
    
    for(i = 0; i < sizeof(rxBuffer); i++)
    {
        checksum = calcCRC(rxBuffer[i], checksum);
    }
    
    if(checksum == 0)
    {
        crcOK = true;
    }
    else
    {
        crcOK = false;
    }
    
    

    You can try the code above, and see if you change a bit in the rxBuffer, crcOK will be false (checksum != 0)

    Siri

  • I understand you but my problem that I have sent RF packets good? Im sampling those RF packets by a dongle and I have the file of what I sampled as binary file (ofcourse there's noise -irrelevant data- ) so my rxbuffer isn't one fixed RF packet as what you show me in your example ! .. so again my problem is finding if the recived packet are ok or not ok, this means to walk over every packet on the received data (binary file) and see if the received packet is valid or not ...and here Im stuck!!!

    to clarify more lets assume I'm receiving data with noise (because they are RF data) , the packet that I transmit is 1 1 0 1 (for instance) , I have transmitted three packets and once I sampled, the received packet is

    1 1 0 1 1 1 (I added the crc at the end which they are 1 1 ) , so the binary file will include like this:

    [00000000110111000011011100000000000000000110111] that's the rx buffer(where there's zero it's noise while sampling the packets that I transmit)

    now all what I need is to check if those three packets in my case (the example that I attached) is valid or not, so I want to check if crc is okay or not okay ..

    could you help me how could I do that in c programming for instance?

  • Siri could you please help me ?really thanks alot

  • Not sure if I understand your set-up. 

    What exactly is your TX and RX side? 

    If I wanted to send a file I would divide it into multiple RF packets. A RF packet have a maximum length but I would keep the payload length less than ~200 bytes if possible since the probability for a bit error will be fairly large if you send a packet with 2000 bytes (as an example). Meaning that if your file is 1000 byte long I would send it as 5 packets of 200 bytes each. For each of the packets the CC1350 will calculate and append a 2 byte CRC. When receiving this packet the RX side will calculate the CRC of the received packet and compare this with the attached CRC. If the calculated and attached CRC are equal the chip regard the packet as correct received. 

    This is straight forward and is done automatically. Based on what I read in this thread it sounds like you want to do it more complicated but I don't see any upside of writing application code to calculate CRC when you can let the chip do it for you.  

  • but my problem isn't exactly the CRC , I want to decode the RF packets manually , Im sampling them by a dongle but an I get IQ SAMPLES .. so I need to convert IQ samples to binary value (0/1), how do I do that?

  • I mean by that, Im doing manually the receiver side .. in order to decide if the packet is ok or not ok ..

  • Not sure if I understand your set-up. 

    What exactly is your TX and RX side? What type of dongle is it?  

    Why are you using I/Q samples? 

  • Hi @

     it would be appreciated please if you could to explain what my rxbuffer[] should include, I mean in your first example it didn't include the preamble and syncword bytes why? could I include them inside rxbuffer ? thanks alot.

    I mean by first example, this what you wrote above:

    Preamble, sync word, length byte (0x03), payload (0x01, 0x02, 0x03), CRC1, CRC0

    On the receiver you must make sure you receive all your data int he data entry, including the CRC bytes. You can store the received data in a variable called rxBuffer.

    rxBuffer[] = {0x03, 0x01, 0x02, 0x03, CRC1, CRC0).

    could my rxBuffer[] include the preamable and syncword byte and still working? for instance lets assume my preamble is 0x07 , syncword 0x09 so could I include them inside my rxbuffer[] and it would be like this :rxBuffer[] = {0x07,0x09, 0x03, 0x01, 0x02, 0x03, CRC1, CRC0}. will code that you attached still working to check my CRC of the received packet? thanks.

  • Back to square one to be able to understand your setup: 

    How do you generate rxBuffer? Is it the output of

    /* Enter RX mode and stay forever in RX */
        RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx,
                                                   RF_PriorityNormal, &callback,
                                                   RF_EventRxEntryDone);

    or something else? 

  • it's something else not related to what you attached sir

  • Please enlighten me what "something else" is.