Skip to content

Commit dba68ca

Browse files
committed
Merge @galch fixes
Fixes issue mentioned here: sparkfun#31
1 parent cbabb4e commit dba68ca

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/SparkFunLSM9DS1.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,26 @@ int16_t LSM9DS1::readMag(lsm9ds1_axis axis)
604604
return 0;
605605
}
606606

607+
typedef union
608+
{
609+
struct
610+
{
611+
int16_t data :12;
612+
int16_t Reserved :4;
613+
};
614+
int16_t word;
615+
} int12_t;
616+
607617
void LSM9DS1::readTemp()
608618
{
609619
uint8_t temp[2]; // We'll read two bytes from the temperature sensor into temp
610620
if ( xgReadBytes(OUT_TEMP_L, temp, 2) == 2 ) // Read 2 bytes, beginning at OUT_TEMP_L
611621
{
622+
int12_t degree;
623+
degree.word = ( ( int16_t )temp[ 1 ] << 8 ) | ( int16_t ) temp[ 0 ];
624+
612625
int16_t offset = 25; // Per datasheet sensor outputs 0 typically @ 25 degrees centigrade
613-
temperature = offset + ((((int16_t)temp[1] << 8) | temp[0]) >> 8) ;
626+
temperature = offset + degree.data / 16;
614627
}
615628
}
616629

0 commit comments

Comments
 (0)