cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, Not quite sure on how to extract data from LIS2DH12 in 12 bit mode.

PBalz.1
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions
raptorhal2
Lead

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

View solution in original post

2 REPLIES 2
raptorhal2
Lead

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

PBalz.1
Associate

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