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.

using MSP430f5438a's crc module

I am trying to calculate crc, but I always get what seems to be the wrong result.

I wrote this code to find see whats happens:

    CRCINIRES = 0xFFFF;
    CRCDIRB = '1';
    CRCDIRB = '2';
    CRCDIRB = '3';
    CRCDIRB = '4';
    CRCDIRB = '5';
    CRCDIRB = '6';
    CRCDIRB = '7';
    CRCDIRB = '8';
    CRCDIRB = '9';

    crc = CRCINIRES;

the result suppose to be 0x29B1 according to the user guide assembly code, but I get 0x26B2 on CRCINIRES and 0x4D64 on CRCINIRES.

Am I doing something wrong?

  • Check out this document: http://www.ti.com/lit/ug/slau398c/slau398c.pdf

    Regards,
    Maciej

  • I have already read it, and from there I got the assembly code that I wrote my c code according to.

    from what I understood from this chapter I need to initialized the crc generator by writing to the CRCINIRES register the wprd 0xFFFF, and then inserting data to CRCDIRB (for the reverse order) and after I will finish inserting all the data the result will be available on CRCRESR.

    This is what I have done in the c code, but this doesn't seem to work as it should...

  • I do not have MCU to check the code but this is what I would do. 

    Using following assembly code

    mov   #0FFFFh,&CRCINIRES ; initialize CRC
    mov.b #00031h,&CRCDIRB_L ; "1"
    mov.b #00032h,&CRCDIRB_L ; "2"
    mov.b #00033h,&CRCDIRB_L ; "3"
    mov.b #00034h,&CRCDIRB_L ; "4"
    mov.b #00035h,&CRCDIRB_L ; "5"
    mov.b #00036h,&CRCDIRB_L ; "6"
    mov.b #00037h,&CRCDIRB_L ; "7"
    mov.b #00038h,&CRCDIRB_L ; "8"
    mov.b #00039h,&CRCDIRB_L ; "9"
    cmp #029B1h,&CRCINIRES ; compare result
                           ; CRCRESR contains 08D94h
    jeq &Success           ; no error
    br  &Error             ; to error handler

    I would write the following C code:

    CRCINIRES = 0xFFFF;
    CRCDIRB_L = '1';
    CRCDIRB_L = '2';
    CRCDIRB_L = '3';
    CRCDIRB_L = '4';
    CRCDIRB_L = '5';
    CRCDIRB_L = '6';
    CRCDIRB_L = '7';
    CRCDIRB_L = '8';
    CRCDIRB_L = '9';
    if (CRCINIRES == 0x29B1)
    { print("It works"); }
    else
    { print("Something is wrong"); }

    Regards,
    Maciej

**Attention** This is a public forum