02-06-2022 01:45 PM
02-07-2022 03:42 AM
Hello Lmuh,
You can refer to the code logic of the sensor API, activate the SPI interface first, and then read the chip ID via SPI.
/*!
* @brief This API is the entry point for sensor.It performs
* the selection of I2C/SPI read mechanism according to the
* selected interface and reads the chip-id of bmi160 sensor.
*/
int8_t bmi160_init(struct bmi160_dev *dev)
{
int8_t rslt;
uint8_t data;
uint8_t try = 3;
/* Null-pointer check */
rslt = null_ptr_check(dev);
/* Dummy read of 0x7F register to enable SPI Interface
* if SPI is used */
if ((rslt == BMI160_OK) && (dev->intf == BMI160_SPI_INTF))
{
rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev);
}
if (rslt == BMI160_OK)
{
/* Assign chip id as zero */
dev->chip_id = 0;
while ((try--) && (dev->chip_id != BMI160_CHIP_ID))
{
/* Read chip_id */
rslt = bmi160_get_regs(BMI160_CHIP_ID_ADDR, &dev->chip_id, 1, dev);
}
if ((rslt == BMI160_OK) && (dev->chip_id == BMI160_CHIP_ID))
{
dev->any_sig_sel = BMI160_BOTH_ANY_SIG_MOTION_DISABLED;
/* Soft reset */
rslt = bmi160_soft_reset(dev);
}
else
{
rslt = BMI160_E_DEV_NOT_FOUND;
}
}
return rslt;
}