Skip to content

Commit 4be6161

Browse files
committed
Improve robustness when bus error happens
1 parent 6004a94 commit 4be6161

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino ISM330DHCX
2-
version=2.1.0
2+
version=2.1.1
33
author=SRA
44
maintainer=stm32duino
55
sentence=High-Performance 3D digital accelerometer and 3D digital gyroscope.

src/ISM330DHCXSensor.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ ISM330DHCXSensor::ISM330DHCXSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed
3939
*/
4040
ISM330DHCXStatusTypeDef ISM330DHCXSensor::Init()
4141
{
42+
/* Check sensor ID: this checks that we can communicate with the sensor */
43+
uint8_t Id;
44+
45+
/* Get the Id; note this is not enough per se depending on the I2C implementation */
46+
if (ReadID(&Id) != ISM330DHCX_OK) {
47+
return ISM330DHCX_ERROR;
48+
}
49+
50+
/* Check that we actually got back the right ID; this should return an error even if
51+
the I2C implementation does not complain in case of no response. */
52+
if (Id != ISM330DHCX_ID) {
53+
return ISM330DHCX_ERROR;
54+
}
55+
4256
/* SW reset */
4357
if (ism330dhcx_reset_set(&(reg_ctx), PROPERTY_ENABLE) != ISM330DHCX_OK) {
4458
return ISM330DHCX_ERROR;

0 commit comments

Comments
 (0)