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.

CCS/MSP430FR5869: Can not successfully make a crc-16

Part Number: MSP430FR5869

Tool/software: Code Composer Studio

I've been reading through the documentation in the user guide for the MSP430FR58xx family regarding the CRC-16 module. 

I use two variables in the test code. One with a seed, and one with the test data, that I want the CRC of. I have also defined the "baseAddress", which is used with the crc-related functions. The code looks something like this (it's in C++)

Testcode:

"

uint16_t baseAddress = 0x0150;

uint16_t seed = 0;

uint16_t data = 123;

CRC_setSeed(baseAddress, seed);  //Initializing CRC module

CRC_set16BitData(baseAddress, data);  //Sending input data

CRC_set16BitData(baseAddress, seed);  //sending 16 0's to shift out the databits

uint16_t result = CRC_getResult(baseAddress);  //Storing the result in variable

"

I used uint16_t sizes as that is what the functions take as arguments.

The above code gives the following result (in hex): 0A59

When I use the "bitsReversed" functions the result is (in hex): 563A

It seems to work in a very simple manner with the functions, but at this point, I recognize that I must be doing something wrong. I'm looking for anyone who can tell me what's wrong. 

By the way: I tried all combinations of reverse byte input, reverse byte result and tried with and without sending the 16 0's. None of the combinations gave a result matching anything I can produce in the online tables. I used https://crccalc.com/ for checking results.

Thanks in advance.

  • Hello Martin,

    I have attached two example codes on CRC module for your reference.

    The projects are written for FR5976 you just need to change them to FR5869.

    crc_example.zip

    Thanks,

    Yiding

  • I looked at my CRC16 code and I had to use the reverse bit order input register and the normal order output register on the FR5969. I ended up with a file that depending on what I want will use the hardware CRC, a table driven version, or iterative. All delivering the same results. My comment says: "When tested with the usual test string of "123456789" all versions return  0x29B1."

  • Thank you. I see that you are using the CRC32 module, which my MCU does not have (which mean I can't simply steal your whole, fine-looking code :-) ) . Your code looks pretty similar to mine though. I'll make a comparison.
    Your hardware oriented code:
    "
    static const uint8_t myData[9] = {0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};

    volatile uint16_t hwCalculatedCRC;

    CRC32_setSeed(CRC16_INIT, CRC16_MODE); //Init the same way as I

    for(ii=0;ii<9;ii++)
    CRC32_set8BitDataReversed(myData[ii], CRC16_MODE); //Shifting data through register

    hwCalculatedCRC = CRC32_getResult(CRC16_MODE); //Storing CRC in variable
    "

    My test code (keep in mind I do not have a CRC32 module on my MCU, so I use the files "crc.c" and "crc.h" instead of "crc32.c" and "crc32.h" as you use):

    "
    uint16_t seed = 0xFFFF;
    uint16_t dataArray[9] = {0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39}; //ASCII '123456789'

    CRCINIRES = seed; //init

    for(i=0; i<9; i++)
    {
    CRCDIRB = dataArray[i]; //shifting in reversed uint16_t input
    }
    uint16_t result = CRCINIRES;
    "

    The above code gives result = 4D64 (hex)
    If I dont reverse the input the code gives result = 8350 (hex)

    Any suggestions to how the code differs from each other, or what I might be doing wrong?
  • Hello David. Thanks for the tip. I have already tried all combinations of reversed input/result, and it's killing me that nothing works. Is there any way you could share your file? Or maybe just the code block used for hardware generated CRC-16? I'd love to compare my code to yours, as the 0x23B1 is the result I'm looking for.
  • I have these in two files. crc16.h hold the defines while crc16.c holds the code. This is just the hardware version as the complete code has options for the two types of software CRC.

    #define crc16_init(crc) (CRCINIRES = 0xffff)
    #define crc16_next(crc, data)  (CRCDIRB_L = data)
    #define crc16_done(crc) (CRCINIRES)
    
    /*
      Compute and return the CRC16 on n bytes of the string.
    */
    uint16_t compute_crc(uint8_t *s, int n)
    {
      uint16_t crc, i;
    
      crc16_init(&crc);
      for(i = 0; i < n; i++)
          crc16_next(&crc, *s++);
    
      return crc16_done(&crc);
    }
    
    

**Attention** This is a public forum