Skip to main content
Visitor II
February 28, 2019
Question

Communication with BNO055 using STM32F4 Discovery Board

  • February 28, 2019
  • 2 replies
  • 1330 views

I am trying to use BNO055 with STM32F407VG discovery board. I got the API from here. In the API example file, it says just adjust the read and write functions.

Here is the main code I work on. But I cannot read the acceleration data. What should I be missing? Thanks in advance.`

/* \Brief: The API is used as SPI bus write
 * \Return : Status of the SPI write
 * \param dev_addr : The device address of the sensor
 * \param reg_addr : Address of the first register,
 * will data is going to be written
 * \param reg_data : It is a value hold in the array,
 * will be used for write the value into the register
 * \param cnt : The no of byte of data to be write
 */
 
s8 BNO055_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
 s32 BNO055_iERROR = BNO055_INIT_VALUE;
 u8 array[I2C_BUFFER_LEN];
 u8 stringpos = BNO055_INIT_VALUE;
 
 array[BNO055_INIT_VALUE] = reg_addr;
 for (stringpos = BNO055_INIT_VALUE; stringpos < cnt; stringpos++)
 array[stringpos + BNO055_I2C_BUS_WRITE_ARRAY_INDEX] =
 *(reg_data + stringpos);
 
 /*
 * Please take the below APIs as your reference for
 * write the data using I2C communication
 * "BNO055_iERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+1)"
 * add your I2C write APIs here
 * BNO055_iERROR is an return value of I2C read API
 * Please select your valid return value
 * In the driver BNO055_SUCCESS defined as 0
 * and FAILURE defined as -1
 * Note :
 * This is a full duplex operation,
 * The first read data is discarded, for that extra write operation
 * have to be initiated. For that cnt+1 operation done
 * in the I2C write string function
 * For more information please refer data sheet SPI communication:
 */
 
 HAL_I2C_Mem_Write(&hi2c1, dev_addr, reg_addr, I2C_MEMADD_SIZE_8BIT, array, cnt, 100);
// HAL_I2C_Mem_Write(&hi2c1, dev_addr, reg_addr, I2C_MEMADD_SIZE_8BIT, &array, cnt+1, 100);
// HAL_I2C_Master_Transmit(&hi2c1, dev_addr, &array, I2C_MEMADD_SIZE_8BIT, 100);
 
 
 return (s8)BNO055_iERROR;
}
 
 /* \Brief: The API is used as I2C bus read
 * \Return : Status of the I2C read
 * \param dev_addr : The device address of the sensor
 * \param reg_addr : Address of the first register,
 * will data is going to be read
 * \param reg_data : This data read from the sensor,
 * which is hold in an array
 * \param cnt : The no of byte of data to be read
 */
 
s8 BNO055_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
 s32 BNO055_iERROR = BNO055_INIT_VALUE;
 u8 array[I2C_BUFFER_LEN] = {BNO055_INIT_VALUE};
 u8 stringpos = BNO055_INIT_VALUE;
 
 array[BNO055_INIT_VALUE] = reg_addr;
 
 /* Please take the below API as your reference
 * for read the data using I2C communication
 * add your I2C read API here.
 * "BNO055_iERROR = I2C_WRITE_READ_STRING(DEV_ADDR,
 * ARRAY, ARRAY, 1, CNT)"
 * BNO055_iERROR is an return value of SPI write API
 * Please select your valid return value
 * In the driver BNO055_SUCCESS defined as 0
 * and FAILURE defined as -1
 */
 
 HAL_I2C_Mem_Read(&hi2c1, dev_addr, reg_addr, I2C_MEMADD_SIZE_8BIT, reg_data, cnt, 100);
// HAL_I2C_Mem_Read(&hi2c1, dev_addr, reg_addr, I2C_MEMADD_SIZE_8BIT, &array, cnt, 100);
// HAL_I2C_Master_Receive(&hi2c1, dev_addr, &array, I2C_MEMADD_SIZE_8BIT, 100);
 
 
 for (stringpos = BNO055_INIT_VALUE; stringpos < cnt; stringpos++)
 *(reg_data + stringpos) = array[stringpos];
 return (s8)BNO055_iERROR;
}

    This topic has been closed for replies.

    2 replies

    Visitor II
    April 13, 2019

    hello; i am also trying to comminicate these 2 parts.Did you come up with a solition yet? If so please can you explain your finding?

    ST Employee
    April 16, 2019

    Hi, this is a Bosh part number :D If you are supposing the issue is related to the communication from the master side (STM32), you should post your question in this community (https://community.st.com/s/group/0F90X000000AXsASAW/stm32-mcus). If on the other side you think the issue is related to the sensor, you can try our 9-axis iNemo sensor LSM9DS1 and the related adapter :D Regards