AnsweredAssumed Answered

How to Calculate CRC on a structure?

Question asked by Amit Kumar on Sep 18, 2014
Latest reply on Sep 19, 2014 by Amit Kumar

Hi

I am using built in CRC PE component to calculate CRC32 of an array which is coming fine but how do I do it for structure ?

 

char buffer[10] = "abcdefghij";

 

CRC1_GetBlockCRC(crc1, buffer, sizeof(buffer)-1, &crc_val);          //  This syntax gives the actual CRC value which I compared with the online CRC calculator

 

Why do we have to subtract 1 from sizeof ??

 

 

Secondly , I want to calculate the CRC as following.

 

typedef struct

{

      uint32_t name;

      float weight;

      int32_t marks;

      float average;

      int32_t value;

      uint32_t crc;

}LDD_Test;

 

LDD_Test TEST;


int main(void)

{

      TEST.name = 0x41424344;

      TEST.weight = 59.23;

      TEST.marks = 530;

      TEST.average = 46.58;

      TEST.value = 120;


      CRC1_GetBlockCRC(crc1, &TEST, sizeof(TEST)-5, &TEST.crc);// Get 32 bit CRC last 4 bytes of struct is CRC so excluding that. I have tested for ARRAY

 

      FAT1_write(&fp1, &TEST, sizeof(TEST), &bw);

}

 

The above code is just for illustration. The CRC calculated by this is incorrect. My Query is how do we do operations on structure as we do for any strings or array ? Kindly help

 

Kind Regards

Amit Kumar

Outcomes