AnsweredAssumed Answered

generate CRC for M24SR

Question asked by j.maerten on Jan 4, 2017
Latest reply on Jan 20, 2017 by Berenice Benveguda

Hi everyone,

in our application I have to communicate with a M24SR02-Y over IIC.

I have tried 2 versions to generate the CRC:

Version 2

#define PRESET_VALUE 0x6363
#define MASK 0x8408
#define NUMBER_OF_BYTES 6
unsigned char array_of_databytes[6] = { 0x03, 0x00, 0xB0, 0x00, 0x00, 0x02 };

void CRC() {
    current_crc_value = PRESET_VALUE;
    for (i = 0; i < NUMBER_OF_BYTES; i++)    {
        DATA = array_of_databytes[i];
        current_crc_value ^= (uint)DATA;
        for (j = 0; j < 8; j++)  {
            if ((current_crc_value & 0x0001) > 0)  {
                current_crc_value >>= 1;
                current_crc_value ^= MASK;
            }
            else            {
                current_crc_value >>= 1;
            }
        }
}

Version 2

#define PRESET_VALUE 0x6363
#define NUMBER_OF_BYTES 6
unsigned char array_of_databytes[6] = { 0x03, 0x00, 0xB0, 0x00, 0x00, 0x02 };

void CRC() {
    current_crc_value = PRESET_VALUE;
    for (i = 0; i < NUMBER_OF_BYTES; i++)    {

        DATA = array_of_databytes[i];
        DATA ^= (uchar)(current_crc_value & 0x00FF);
        DATA ^= (DATA<<4);
        current_crc_value >>= 8;
        current_crc_value ^= (uint)DATA << 8;
        current_crc_value ^= (uint)DATA << 3;
        current_crc_value ^= (uint)DATA >> 4;
    }
}

Version 2 based on AN4420 page 20.

Both version generate a CRC 0x7940.

But according to AN4433 'Storing data into the NDEF memory of M24SR' on page 20 the CRC has to be 0x7D6B.

The databyte array { 0x03, 0x00, 0xB0, 0x00, 0x00, 0x02 } contains PCB and command of the 'Read NDEF message length' command.

 

What could have gone wrong?

 

Thanks,

Jörg

Outcomes