cancel
Showing results for 
Search instead for 
Did you mean: 

LSM303D temperature sensor ''12 bit two's complement right aligned''

Alistair Buxton
Associate II
Posted on April 25, 2018 at 03:31

Quote the datasheet:

'Temperature data is stored inside TEMP_OUT_L (05h), TEMP_OUT_H (06h) as two’s complement data in 12-bit format, right-justified.'

So if the sensor value is reading 0 and the temperature drops by 1/8th of a degree, I would expect the value to be 0xffff or 0x0fff - that is 0bxxxx111111111111. Since 111111111111 is 12 bit two's complement for -1, and the x bits are ignored.

However this is not the case. The value I actually read is 0xefff / 0b1111111011111111 / -257. The value continues to count down by 1 per 1/8 degree from here.

Can anyone explain what is going on here please?

1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee
Posted on April 25, 2018 at 11:16

Didn't you swat the High and Low byte?

Morevover 0b1111111011111111 is not 0xEFFF so I don't know which value do you read.

View solution in original post

2 REPLIES 2
Miroslav BATEK
ST Employee
Posted on April 25, 2018 at 11:16

Didn't you swat the High and Low byte?

Morevover 0b1111111011111111 is not 0xEFFF so I don't know which value do you read.

Posted on April 25, 2018 at 11:24

Yes you are right. It is 0b1110111111111111 which is 12 1s, so it makes sense.