@@ -226,6 +226,8 @@ def __init__( # pylint: disable=too-many-arguments
226
226
self ._osr = oversampling
227
227
self ._gain_current = gain
228
228
self ._temperature_compensation = temperature_compensation
229
+ # Typical value according the application note
230
+ self ._tref = 0xB668
229
231
self ._off_x = self ._off_y = self ._off_z = offset
230
232
231
233
# Put the device in a known state to start
@@ -519,6 +521,12 @@ def reset(self) -> None:
519
521
print ("Resetting sensor" )
520
522
time .sleep (0.002 )
521
523
self ._transceive (bytes ([_CMD_RT ]))
524
+
525
+ # Read the temperature reference from register 0x24
526
+ self ._tref = self .read_reg (0x24 )
527
+ if self ._debug :
528
+ print ("Tref = {}" .format (hex (self ._tref )))
529
+
522
530
# burn a read post reset
523
531
try :
524
532
self .magnetic
@@ -614,9 +622,6 @@ def temperature(self) -> float:
614
622
Reads a single temperature sample from the magnetometer.
615
623
Temperature value in Celsius
616
624
"""
617
- # Read the temperature reference from register 0x24
618
- treference = self .read_reg (0x24 )
619
-
620
625
# Value taken from maximum time of temperature conversion on the datasheet section 12.
621
626
# maximum time for temperature conversion = 1603 us
622
627
delay = 0.1
@@ -637,4 +642,4 @@ def temperature(self) -> float:
637
642
tvalue = struct .unpack (">H" , data [1 :3 ])[0 ]
638
643
# See previous link for conversion formula
639
644
640
- return 35 + ((tvalue - treference ) / 45.2 )
645
+ return 35 + ((tvalue - self . _tref ) / 45.2 )
0 commit comments