cancel
Showing results for 
Search instead for 
Did you mean: 

generate CRC for M24SR

Joerg Maertens
Associate
Posted on January 04, 2017 at 15:39

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

1 ACCEPTED SOLUTION

Accepted Solutions
Berenice BENVEGUDA
ST Employee
Posted on January 20, 2017 at 16:48

Dear Joerg,

You're right the correct CRC is 0x7940. There is a mistake in AN4433.

This will be corrected soon.

Thanks a lot for your help !

Best Regards,

NFC Product Support1

View solution in original post

1 REPLY 1
Berenice BENVEGUDA
ST Employee
Posted on January 20, 2017 at 16:48

Dear Joerg,

You're right the correct CRC is 0x7940. There is a mistake in AN4433.

This will be corrected soon.

Thanks a lot for your help !

Best Regards,

NFC Product Support1