Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix readTemperature function #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/SparkFunLSM9DS1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,13 +607,26 @@ int16_t LSM9DS1::readMag(lsm9ds1_axis axis)
return 0;
}

typedef union
{
struct
{
int16_t data :12;
int16_t Reserved :4;
};
int16_t word;
} int12_t;

void LSM9DS1::readTemp()
{
uint8_t temp[2]; // We'll read two bytes from the temperature sensor into temp
if ( xgReadBytes(OUT_TEMP_L, temp, 2) == 2 ) // Read 2 bytes, beginning at OUT_TEMP_L
{
int12_t degree;
degree.word = ( ( int16_t )temp[ 1 ] << 8 ) | ( int16_t ) temp[ 0 ];

int16_t offset = 25; // Per datasheet sensor outputs 0 typically @ 25 degrees centigrade
temperature = offset + ((((int16_t)temp[1] << 8) | temp[0]) >> 8) ;
temperature = offset + degree.data / 16;
}
}

Expand Down