With reading some more forum entries like https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI160-How-do-you-properly-use-quot-softreset-quot/m-p/7322 I figured out the softreset timeout should be 200ms. I could create an *empirical* python test code sequence which works in my setup on the first attempt: import spidev
import time
spi = spidev.SpiDev()
spi.open(0,1)
spi.max_speed_hz = 1000000
# init SPI mode
ret = spi.xfer([0xff, 0x00])
# soft reset
ret = spi.xfer([0x7e, 0xb6])
time.sleep(.2)
# init SPI mode again
ret = spi.xfer([0xff, 0x00])
time.sleep(.02)
attempts = 0
while attempts < 10:
# read id
ret = spi.xfer([0x80, 0x00])
if ret[1] == 0xd1:
break
attempts += 1
print(f'attempt {attempts+1}, chip id: {hex(ret[1])}') With this logic I changed the Linux bmi160 iio driver setup code which now initializes the BMI160 device successfully 😅: diff --git a/drivers/iio/imu/bmi160/bmi160_core.c b/drivers/iio/imu/bmi160/bmi160_core.c
index a77f1a834..263ba8a22 100644
--- a/drivers/iio/imu/bmi160/bmi160_core.c
+++ b/drivers/iio/imu/bmi160/bmi160_core.c
@@ -93,7 +93,8 @@
#define BMI160_ACCEL_PMU_MIN_USLEEP 3800
#define BMI160_GYRO_PMU_MIN_USLEEP 80000
-#define BMI160_SOFTRESET_USLEEP 1000
+#define BMI160_SOFTRESET_USLEEP 200000
+#define BMI160_SPI_MODE_CHANGE_USLEEP 20000
#define BMI160_CHANNEL(_type, _axis, _index) { \
.type = _type, \
@@ -716,20 +717,29 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
return ret;
}
+ /*
+ * CS rising edge is needed before starting SPI, so do a dummy read
+ * See Section 3.2.1, page 86 of the datasheet
+ */
+ if (use_spi) {
+ ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
+ if (ret)
+ goto disable_regulator;
+ usleep_range(BMI160_SPI_MODE_CHANGE_USLEEP, BMI160_SPI_MODE_CHANGE_USLEEP + 1);
+ }
+
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
if (ret)
goto disable_regulator;
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
- /*
- * CS rising edge is needed before starting SPI, so do a dummy read
- * See Section 3.2.1, page 86 of the datasheet
- */
+ /* After soft reset switch to SPI mode is required again */
if (use_spi) {
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
if (ret)
goto disable_regulator;
+ usleep_range(BMI160_SPI_MODE_CHANGE_USLEEP, BMI160_SPI_MODE_CHANGE_USLEEP + 1);
}
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val); I did not find the timeout values in the BMI160 data sheet. Are those written down somewhere or are these always empirical values?
... View more