Skip to content

Commit

Permalink
Issue #10: Add support for LSM6DSO.
Browse files Browse the repository at this point in the history
  • Loading branch information
quicksketch committed Jan 12, 2025
1 parent 65af2fd commit cee249a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 10 additions & 9 deletions src/F_LSM6DS3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@ int LSM6DS3::init(calData cal, uint8_t address)
//initialize address variable and calibration data.
IMUAddress = address;

if (cal.valid == false)
if (cal.valid == false)
{
calibration = { 0 };
}
else
{
calibration = cal;
}

uint8_t IMUWhoAmI = checkReady(IMUAddress, 500);
if (!(IMUWhoAmI == LSM6DS3_WHOAMI_DEFAULT_VALUE)) {
if (!(IMUWhoAmI == LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE)) {
return -1;
}

uint8_t IMUWhoAmI = checkReady(IMUAddress, 100);
if (IMUWhoAmI != LSM6DS3_WHOAMI_DEFAULT_VALUE &&
IMUWhoAmI != LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE &&
IMUWhoAmI != LSM6DSO_WHOAMI_DEFAULT_VALUE)
{
return -1;
}

// reset device
writeByteI2C(wire, IMUAddress, LSM6DS3_CTRL3_C, 0x01); // Toggle softreset
while (!checkReady(IMUAddress, 100)); // wait for reset

writeByteI2C(wire, IMUAddress, LSM6DS3_CTRL1_XL, 0x47); // Start up accelerometer, set range to +-16g, set output data rate to 104hz, BW_XL bits to 11.
writeByteI2C(wire, IMUAddress, LSM6DS3_CTRL2_G, 0x4C); // Start up gyroscope, set range to -+2000dps, output data rate to 104hz.
writeByteI2C(wire, IMUAddress, LSM6DS3_CTRL4_C, 0x80); // Set XL_BW_SCAL_ODR;
Expand Down Expand Up @@ -260,4 +261,4 @@ void LSM6DS3::calibrateAccelGyro(calData* cal)
cal->gyroBias[1] = (float)gyro_bias[1];
cal->gyroBias[2] = (float)gyro_bias[2];
cal->valid = true;
}
}
3 changes: 2 additions & 1 deletion src/F_LSM6DS3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@

#define LSM6DS3_WHOAMI_DEFAULT_VALUE 0x69
#define LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE 0x6A
#define LSM6DSO_WHOAMI_DEFAULT_VALUE 0x6C

#define LSM6DS3_DEFAULT_ADDRESS 0x6B

Expand Down Expand Up @@ -109,7 +110,7 @@ class LSM6DS3 : public IMUBase {
uint8_t IMUAddress;

TwoWire& wire;

uint8_t checkReady(uint8_t address, uint8_t timeout)
{
uint8_t IMUWhoAmI = 0;
Expand Down

0 comments on commit cee249a

Please sign in to comment.