I have an L3GD20, which is an accelerometer with a temperature sensor built in, and I want to make sure my math isn't funky regarding the temperature. I'm not exactly experienced with embedded hardware.
I've been playing around with the temperature sensor on the L3GD20. According to the datasheet, the temperature is represented in 8 bit 2's complement, so it goes from -128 to 127. However, the datasheet includes this little snipp:
So, if I'm understanding the datasheet, the temperature sensor will deliver a temperature range of -40c to +85c in 8 bit 2's complement. So, a raw value of 127 (0x7F) from the sensor would correspond to +85c, and a raw value of -128 (0x80) would correspond to -40c. Therefore, the spacing between consecutive readings (for example, 0x00 and 0x01) is approximately 0.5c. I came to this conclusion by taking the temperature range and dividing it by the output range of the sensor: (85 - (-40)) / (127 - (-128)).
But then here's the part where my math gets fuzzy. If the temperature range remained the same (125c from smallest to largest), but was centered on 0, it would go from -62.5 to +62.5). But it doesn't. It goes from -40 to 85c. Therefore, the temperature range has a positive offset of 22.5c. But since there's approximately 2 codes from the temperature sensor for every degree Celsius, a raw value of 0x00 from the sensor would correspond to 11.25c, correct?
TL;DR version: I have a temperature sensor that ranges from -40c to +85c, and gives the reading back in 8 bit 2's complement. In order to get the actual temperature in degrees Celsius, I believe I need to add 11.25 (or just 11 to keep things simple) to the sensor output. Is this correct?