Skip to main content
Alistair Buxton
Associate
Apr 25, 2018 1:31 AM UTC
Solved

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

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?

This topic has been closed for replies.
Miroslav BATEKBest answer
ST Employee
Apr 25, 2018 9:16 AM UTC
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.

2 replies

Miroslav BATEKBest answer
ST Employee
Apr 25, 2018 9:16 AM UTC
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.

Alistair Buxton
Associate
Apr 25, 2018 11:24 AM UTC
Posted on April 25, 2018 at 11:24

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