01-27-2020 10:15 AM - edited 01-27-2020 04:46 PM
Hi,
I would like to use the BMX160 with my STM32 MCU. Unfortunately, I am getting always zero for the gyro data. The chip id is changed to #define BMI160_CHIP_ID UINT8_C(0xD8) and the return value for the bmi160_init and bmi160_set_sens_conf is BMI160_OK.
I have no clue where the mistake could be.
acc.x =-1413, acc.y=236, acc.z=16734, sensortime=5340
gyro.x=0, gyro.y=0;gyro.z=0, sensortime=5340
// Edit: I am able to get the gyro data with the FIFO example https://github.com/BoschSensortec/BMI160_driver/wiki/How-to-use-an-auxiliary-sensor-or-magnetometer-....
main()
{
...
// Initialization
bmi.id = 0;
bmi.interface = BMI160_SPI_INTF;
bmi.read = bm_spi_read;
bmi.write = bm_spi_write;
bmi.delay_ms = HAL_Delay;
rslt=bmi160_init(&bmi);
/* Select the Output data rate, range of accelerometer sensor */
bmi.accel_cfg.odr = BMI160_ACCEL_ODR_50HZ;
bmi.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
bmi.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
bmi.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
/* Select the Output data rate, range of Gyroscope sensor */
bmi.gyro_cfg.odr = BMI160_GYRO_ODR_50HZ;
bmi.gyro_cfg.range = BMI160_GYRO_RANGE_500_DPS;
bmi.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE;
bmi.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
/* Set the sensor configuration */
rslt = bmi160_set_sens_conf(&bmi);
struct bmi160_sensor_data acc;
struct bmi160_sensor_data gyro;
/* To read only Gyro data */
bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL | BMI160_TIME_SEL), &acc, &gyro, &bmi);
....
}
#define SPI_BUFF_SZ (1024+1)
#define COMM_DELAY 10
int8_t bm_spi_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t* data, uint16_t len) {
UNUSED(dev_addr);
if (len > (SPI_BUFF_SZ - 1)) {
Error_Handler();
}
uint8_t rxarr[SPI_BUFF_SZ] = { reg_addr };
HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET);
HAL_StatusTypeDef status = HAL_SPI_TransmitReceive(&hspi2, rxarr, rxarr, len + 1, COMM_DELAY);
HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET);
memcpy(data, rxarr + 1, len);
return (status == HAL_OK ? BMI160_OK : BMI160_E_COM_FAIL);
}
int8_t bm_spi_write(uint8_t dev_addr, uint8_t reg_addr, const uint8_t *data, uint16_t len) {
UNUSED(dev_addr);
if (len > (SPI_BUFF_SZ - 1)) {
Error_Handler();
}
uint8_t txarr[SPI_BUFF_SZ] = { reg_addr };
memcpy(txarr + 1, data, len);
HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET);
HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr, len + 1, COMM_DELAY);
HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET);
return (status == HAL_OK ? BMI160_OK : BMI160_E_COM_FAIL);
}
Regards,
01-29-2020 11:10 AM
06-08-2020 11:01 AM
Dear sidjur
Can I ask you how you use STM32 to read the CHIPID of BMX160
Can you share your CODE