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.

CRC in TMS37157

Other Parts Discussed in Thread: TMS37157

Hello

I tried to get acquainted with CRC used in TMS37157 using some web-based tools like http://www.zorc.breitbandkatze.de/crc.html

In this case I'm trying to read page 55 from the chip memory and verify the read using CRC.

Page 55 of the memory has bytes 0xAA, 0xAA, 0xAA, 0xAA, 0xAA.

If I understood the CRC usage correctly, calculating CRC over the reply message's 01AAAAAAAAAADC25AB should give zero but I'm not getting that.

I'm using eZ430-TMS37157 evaluation kit with its demo GUI and I extracted the message above from "data from reader" field's 010B007E01AAAAAAAAAADC25AB8C

Could someone tell me why the web-tool is not giving me correct results and/or give me correct parameters?

I'm assuming here that the tool is correct which is supported by the results are similar to those given by Java code which I copied from a respectable source.

The manual states that CRC-CCITT is used with initial value 0x3791.

  • Dear Petri,

    I am stuck just at the same point as you describe in your post, the exact calculation algorithm of the BCC for communication with the transponder.

    It should be pretty straightforward, i mean, it loks like an standard CCITT CRC with 0x1021 polynom, 0x3791 initial value and calculation over the 7 bytes of data, excluding the 0x7E prolog. But there must be some subtlety with the implementation (or in the documentation) because i am totally unable to replicate its calculation.

    Reading a more recent post of yours leads me to think that you might have done some progress with this. Could you provide any hint?

    Best regards,

     Victor

  • Ok, I'll respond to myself.....

    What you have to do is to implement __exactly__ the algorithm described in Figure52 of the datasheet, with initial value 0x3791.

    Maybe it's just equivalent to the usual calculation but shifting bytes LSB-first... i dont' have time now to figure out....

    Regards,

     Victor

  • Yes in my case the idea of standard CRC CCITT was abandoned and instead an exact implementation of the picture in the data sheet was done and it seems to work.

  • Hi,

       I'm stuck too. I tried web-tools, source code on internet on CCITT CRC, I even try to do my own program to calculate CRC (with information give by figure 51 of the datasheet). And I don't succeed to do anything right. And I don't really understand the figure 52 =(. Someone can help me, please ??

    Thanks for the answers.

    Matthias

  • Ok, I found  a solution =) :

    My code :

    "

    /* CRC for TMS37157 */

    #include<stdio.h>
    #include<reg517.h>
    #include<string.h>

    int j=0;
    int i=0;
    int z=0;
    char temp=2;
                   
    /*unsigned char tab[56]={'1', '1', '1', '1', '1', '1', '1', '1',         // (message = FF 01 0E 03 29 04 0E )
             '1', '0', '0', '0', '0', '0', '0', '0',                                                       // =>   CRC=A8 C0
             '0', '1', '1', '1', '0', '0', '0', '0',                         // bit to send FF 01 0E 03 29 04 0E C0 A8
             '1', '1', '0', '0', '0', '0', '0', '0',
             '1', '0', '0', '1', '0', '1', '0', '0',
             '0', '0', '1', '0', '0', '0', '0', '0',
             '0', '1', '1', '1', '0', '0', '0', '0'}; */

                     
    unsigned char tab[48]={    '1', '0', '0', '1', '0', '1', '0', '0',                  //  (message = 29 05 04 03 02 01)
                '1', '0', '1', '0', '0', '0', '0', '0',                                                                 // =>   CRC=9E C2
                '0', '0', '1', '0', '0', '0', '0', '0',                                      // bit to send 29 05 04 03 02 01 C2 9E
                '1', '1', '0', '0', '0', '0', '0', '0',
                '0', '1', '0', '0', '0', '0', '0', '0',                           
                '1', '0', '0', '0', '0', '0', '0', '0'};    

    /*unsigned char tab[56]={    '1', '0', '1', '1', '1', '1', '1', '0',                  // (message = 7D 04 00 00 00 00 00)              
                     '0', '0', '1', '0', '0', '0', '0', '0',                                                             // =>    CRC=AF 58
                     '0', '0', '0', '0', '0', '0', '0', '0',
                     '0', '0', '0', '0', '0', '0', '0', '0',                                              // bit to send 7D 04 00 00 00 00 00 58 AF
                     '0', '0', '0', '0', '0', '0', '0', '0',
                     '0', '0', '0', '0', '0', '0', '0', '0'};     */                         

    unsigned char crc[16]={'0', '0', '1', '1', '0', '1', '1', '1',       // CRC with initial value 0x3791 in MSBF
             '1', '0', '0', '1', '0', '0', '0', '1'};   


    unsigned char invert (unsigned char bit_invert)            // function to do invert a bit
    {
    if (bit_invert=='1')
        return('0');
    else
        return('1');
    }

    void calc_CRC (unsigned char bit_data){        // function to modify the value of the CRC bit by bit
        temp=crc[15];                                                             // (based only on fig 52 of the TMS37157 (p.40))
        for (i=15;i>0;i--)        // crc = (crc >> 1);
            crc[i]=crc[i-1];                     
        crc[0]='0';                    
        if (bit_data=='1')
            crc[0]='1';
        else
            crc[0]='0';
        if(temp=='1')
            {
            crc[0]=invert(crc[0]);
            }
        if(crc[0]=='1')
            {
            crc[12]=invert(crc[12]);
            crc[5]=invert(crc[5]);
            }
    }

    void affiche_CRC (unsigned char * crc){            // function to display the CRC
        printf("\n ****   MSB: ");
    for(j=0;j<4;j++)
        printf("%c",crc[j]);
    printf(" ");
    for(j=4;j<8;j++)
        printf("%c",crc[j]);
    printf("  /  LSB: ");
    for(j=8;j<12;j++)
        printf("%c",crc[j]);
    printf(" ");
    for(j=12;j<16;j++)
        printf("%c",crc[j]);
    printf("\n\n\n");   
    }

                              

    int main (void)
    {

    printf("\n\n\n");

    printf("  /// Valeur initial du CRC /// ");       
    affiche_CRC(crc);                                // display initial value 0x3791

    for(z=0;z<sizeof(tab);z++)
           calc_CRC(tab[z]);                        // modification of the CRC for all bit of the
                                                                          // message to send (for all the bit in "tab")
    printf("  /// Valeur final du CRC /// ");        // final value
    affiche_CRC(crc);                                // display the final value of the CRC

    printf("fin du programme \n");

    return (0);
    }

    "

    this function calc_CRC (the key of the program) is only based on the figure 52 of the datasheet of the TMS37157 (pages 40).

    Hope that it will help people ; ).

    Matthias

     

    fig 52 :