Hello all, I modified the bmi270 api accel examples to make it work in STM32F205 and successfully read the accel data, but with problems that: 1) The accelerometer data is out by factor of 4 x=0.02 m/ss y=2.37 m/ss (anticipate it close to 1G, 9.8m/ss) z=-0.4 m/ss 2) Changing the range made no difference to the data (double checked Register (0x41) ACC_RANGE and sure the change was wrote the register correctly) During my self debug, I narrow down the problem is getting BMI2_E_ACC_INVALID_CFG error in set_accel_config() But I got all BMI2_OK in other settings and BMI2_E_ACC_INVALID_CFG error doest not tell me more details except my ACCEL configuration should have problem. My code is mostly the accel example from BMI270-Sensor-API https://github.com/boschsensortec/BMI270-Sensor-API/tree/master/bmi270_examples/accel with following changes to make it work with stm32 1) redefine bmi2_interface_init() with struct bmi2_dev bmi270_dev; bmi270_dev.read = bm_spi_read; bmi270_dev.write = bm_spi_write; bmi270_dev.delay_us = delayUs; bmi270_dev.read_write_len = SPI_BUFF_SZ-1; (#define SPI_BUFF_SZ (1024+1)) bmi270_dev.intf = BMI2_SPI_INTF;//configure BMI270 SPI bmi270_dev.intf_ptr = &hspi2; bmi270_dev.config_file_ptr = NULL; 2)define bm_spi_read with stm32spi static int8_t bm_spi_read(uint8_t reg_addr, uint8_t* data, uint16_t len, uint8_t dev_addr) { UNUSED(dev_addr); if( len > SPI_BUFF_SZ ) { Error_Handler(); } uint8_t txarr[1] = { reg_addr };//not sure if the size always 1 but highly possible uint8_t rxarr[SPI_BUFF_SZ] = {}; HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_RESET); HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr,1,COMM_DELAY); HAL_SPI_Receive(&hspi2,rxarr,len,COMM_DELAY); HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_SET); memcpy(data, rxarr, len); return (status == HAL_OK ? BMI2_OK : BMI2_E_COM_FAIL); } 3)define bm_spi_write with stm32spi int8_t bm_spi_write(uint8_t reg_addr, uint8_t* data, uint16_t len, uint8_t dev_addr) { 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(GPIOB, IMU_CS_Pin, GPIO_PIN_RESET); HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr, len + 1,COMM_DELAY); HAL_GPIO_WritePin(GPIOB, IMU_CS_Pin, GPIO_PIN_SET); return (status == HAL_OK ? BMI2_OK : BMI2_E_COM_FAIL); } My problem should be exact with the post in below link https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI270-accel-data-anomily/td-p/15622 Unfortunately, this post does not give out the details how the problem was finally solved
... View more