2021-05-06 08:45 AM
It appears to be a 2's complement left justified value.
But making it simple, how do I convert this data... say for a start:
au8_l_Data[0] is the low byte returned from the MEMS (OUT_X_L)
au8_l_Data[1] is the high byte returned from the MEMS (OUT_X_H)
Then in my code:
u16_l_Temp = (uint16_t)au8_l_Data[0];
u16_l_Temp += ((uint16_t)au8_l_Data[1] << 8);
Until here all is ok... but now how do I simply convert this unsigned 16 bit value (u16_l_Temp) into a 16 bit signed value? Simply casting this value to a int16 shouldn't do it if it is a 2's complement... or am I misunderstanding something?
Thanks
Phil
Solved! Go to Solution.
2021-05-06 04:33 PM
Since the data is specified as 2's complement, I suspect it is already signed, so code it as int16_t.
A good check is to simply examine the data with the sensor at rest. If signed, the readings should be 2 axes close to zero, and a third axis close to 1g. If unsigned, there will have to be a half of full scale bias to provide for negative g's.
Cheers, Hal
2021-05-06 04:33 PM
Since the data is specified as 2's complement, I suspect it is already signed, so code it as int16_t.
A good check is to simply examine the data with the sensor at rest. If signed, the readings should be 2 axes close to zero, and a third axis close to 1g. If unsigned, there will have to be a half of full scale bias to provide for negative g's.
Cheers, Hal
2021-05-07 12:55 AM
Perfect Hal,
I tested it out just a minute ago.
No problem casting it directly to a signed value and I get the +1g and the -1g.
Thanks
Phil