Skip to main content
Visitor II
April 25, 2018
Solved

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

  • April 25, 2018
  • 1 reply
  • 1100 views
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.
    Best answer by Miroslav BATEK
    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.

    1 reply

    ST Employee
    April 25, 2018
    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.

    Visitor II
    April 25, 2018
    Posted on April 25, 2018 at 11:24

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