I don't understand completely the description about CRC calculation in ADXL288 datasheet. How can I find an example code to understand this?
Where are you seeing the information about CRC calculations? Is it on the product page?
CRC calculations is on page 38 in ADXL288 Datasheet.
Are you looking for details beyond the pseudo code and LabView example on iterative CRC in the datasheet?
Yes, I followed the pseudo pseudo, but the result was not correct, so I need the example for comparing.
can you please post your code so that i can examine it?
This is my code. Thanks for your help.
unsigned char CRC_Calculation(unsigned short MISO, unsigned char CRC_Ini)
unsigned char CRC_Array;
unsigned char CRC_Cal;
unsigned char MISO_Array;
unsigned char CRC_temp=0;
unsigned short k;
for(i=0;i<8;i++) //put CRC Ini to array
if((CRC_Ini & 0x01)==1)
for(i=0;i<16;i++) // put MISO to array
if((MISO & 0x0001)==1)
for(i=0;i<16;i++) //CRC calculation
CRC_Array[i] = CRC_Cal[i];
for(i=0;i<8;i++) // put array in a char type value
I've given your code a look over, and there are a few things that don't quite add up for me.
First, this code is only written to execute on a single MISO value. do you call this function iteratively from your main program? Figures 47 through 49 of the ADXL288 datasheet show that all previous MISO responses are used in the calculation of the CRC value. so, if you have 5 previous MISO responses since the last time that you received the CRC value, then you need to call this function 5 times so that you can fully process the CRC.
Second, the MISO value needs to be run through the CRC calculation from MSB to LSB. this is made quite clear in the datasheet. Based on your code, it appears that you are processing through the MISO value in the reverse order (from LSB to MSB). Notice how the pseudo-code in the datasheet has a for loop that is written as:
for(i = 15; i>=0; i--)
this is done explicitly so that the MISO[i] array is processed from MSB (MISO) to LSB (MISO).
Third, the datasheet states that once you calculate the new CRC value, that this value must then be inverted in order to comply with the SAEJ1850 specification. i do not see an inversion step executed on the CRC_Cal[i] value in your code.
Fourth, i dont understand why you perform the following step in your code:
this follows the pseudo code written in the ADXL288 datasheet, but you aren't actually doing anything with the CRC_Array[i] value once you finish this for loop. Hence, this code has no purpose. the datasheet includes this step because it expects that you will iterate the previous for loop, and the CRC_Array[i] value needs to be updated in order initialize the next CRC calculation. because your code only processes a single MISO command, its not necessary to implement this particular for loop. you return "CRC_temp" at the end of your program, so you could use that value and pass it to this function the next time you call this routine.
Fifth, when converting the CRC_Cal[i] array back to a char value, i don't think your implementation is correct. The following code is flawed because it will right shift the CRC_temp value one more time than you need to.
You are going to have an issue with this architecture when you process the final CRC_Cal[i] value. When putting the final CRC_Cal[i] value into the CRC_temp variable, you should NOT perform any additional right shifting of the CRC_temp variable. because your code performs a right shift with *every* iteration of the loop, you end up shifting the CRC_temp variable one more time than you need to, which will corrupt the CRC value itself.
That should be enough to get you started. Let me know if you still have issues once you have worked out some of these bugs.
Retrieving data ...