diff --git a/README.md b/README.md index 1e0d825..a6b06e2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Supported IMUS: * BMI055 * BMX055 (Magnetometer currently untested) * BMI160 -* LSM6DS3 +* LSM6DS3 (And some of it's variants) * LSM6DSL (currently untested) * QMI8658 diff --git a/datasheets/LSM6DS3TR-C-Datasheet.pdf b/datasheets/LSM6DS3TR-C-Datasheet.pdf new file mode 100644 index 0000000..e072ada Binary files /dev/null and b/datasheets/LSM6DS3TR-C-Datasheet.pdf differ diff --git a/examples/IMUIdentifier/IMUIdentifier.ino b/examples/IMUIdentifier/IMUIdentifier.ino index b86e2da..81158ac 100644 --- a/examples/IMUIdentifier/IMUIdentifier.ino +++ b/examples/IMUIdentifier/IMUIdentifier.ino @@ -33,7 +33,7 @@ const IMU IMUList[NUM_IMUS] = {0x68, 0x69, 0x75, 0x19, "MPU6886", "3A,3G", true}, {0x69, 0x68, 0x00, 0xD1, "BMI160", "3A,3G", true}, {0x6B, 0x6A, 0x0F, 0x69, "LSM6DS3", "3A,3G", true}, - {0x6B, 0x6A, 0x0F, 0x6A, "LSM6DSL", "3A,3G", true}, + {0x6B, 0x6A, 0x0F, 0x6A, "LSM6DSL or LSM6DS3TR-C", "3A,3G", true}, {0x68, 0x69, 0x75, 0x98, "ICM20689", "3A,3G", true}, {0x68, 0x69, 0x75, 0x20, "ICM20690", "3A,3G", true}, {0x6B, 0x6A, 0x00, 0x05, "QMI8658", "3A,3G", true}, diff --git a/src/F_LSM6DS3.cpp b/src/F_LSM6DS3.cpp index 4e16946..54638d1 100644 --- a/src/F_LSM6DS3.cpp +++ b/src/F_LSM6DS3.cpp @@ -15,14 +15,17 @@ int LSM6DS3::init(calData cal, uint8_t address) { calibration = cal; } - - if (!(readByte(IMUAddress, LSM6DS3_WHO_AM_I) == LSM6DS3_WHOAMI_DEFAULT_VALUE)) { - return -1; + + uint8_t IMUWhoAmI = checkReady(IMUAddress, 500); + if (!(IMUWhoAmI == LSM6DS3_WHOAMI_DEFAULT_VALUE)) { + if (!(IMUWhoAmI == LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE)) { + return -1; + } } // reset device writeByte(IMUAddress, LSM6DS3_CTRL3_C, 0x01); // Toggle softreset - delay(100); // wait for reset + while (!checkReady(IMUAddress, 100)); // wait for reset writeByte(IMUAddress, LSM6DS3_CTRL1_XL, 0x47); // Start up accelerometer, set range to +-16g, set output data rate to 104hz, BW_XL bits to 11. writeByte(IMUAddress, LSM6DS3_CTRL2_G, 0x4C); // Start up gyroscope, set range to -+2000dps, output data rate to 104hz. diff --git a/src/F_LSM6DS3.hpp b/src/F_LSM6DS3.hpp index ae0a59d..bcf92e3 100644 --- a/src/F_LSM6DS3.hpp +++ b/src/F_LSM6DS3.hpp @@ -51,6 +51,7 @@ #define LSM6DS3_OUTZ_H_XL 0x2D #define LSM6DS3_WHOAMI_DEFAULT_VALUE 0x69 +#define LSM6DS3TR_C_WHOAMI_DEFAULT_VALUE 0x6A class LSM6DS3 : public IMUBase { public: @@ -135,5 +136,17 @@ class LSM6DS3 : public IMUBase { dest[i++] = Wire.read(); } // Put read results in the Rx buffer } + + uint8_t checkReady(uint8_t address, uint8_t timeout) + { + uint8_t IMUWhoAmI = 0; + // Wait until a valid byte is returned, up until timeout value. + for (uint8_t checkCount = timeout; checkCount > 0; checkCount--) { + IMUWhoAmI = readByte(address, LSM6DS3_WHO_AM_I); + if (IMUWhoAmI == 0xFF) { delay(1); } else { break; } + } + // Return IMU identifier if found. + return IMUWhoAmI; + } }; #endif /* _F_LSM6DS3_H_ */