Richard,
Out of curiosity, have you tried the PBP code you posted with negative temperature values?
The reason I ask is that my temperature compensation code was pretty much exactly like yours but it went belly up as soon as the temperature went below 0°C.
Reason mainly being the shift operations where potentially negative values (T2, T3 and therfor t_fine) are involved.
I see you're handling the compensation values quite differently, simply pushing them into the lower 16bits of a LONG no matter if they're positive or negative. With that said, both T2 and T3 are positive in my case, like in yours, but they could potentially BE negative and then I don't think simplt stuffing the "signed short" into the lower 16bits of our LONG will work properly.
I had to replace the affected shift operations with * and / at quite some cost for the execution time and for any compensation values specified as signed I'm doing this sort of thing:
Code:
' dig_T2, signed, read to temporary variable and cast to LONG to preserve sign of value
SHIFTIN BME280_MISO, BME280_CLK, 6, [tmp_W.BYTE0, tmp_W.BYTE1]
IF tmp_W.15 = 1 THEN
dig_T2 = -ABS(tmp_W)
ELSE
dig_T2 = tmp_W
ENDIF
/Henrik.
/Henrik.
Bookmarks