This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

BMI160 I2C

I am developing a program with BMI160 with this libraries, but I do not know to which it refers the following code at line 5 and 6: sensor.read and sensor.write.

struct bmi160_dev sensor;

sensor.id = BMI160_I2C_ADDR;
sensor.interface = BMI160_I2C_INTF;
sensor.read = user_i2c_read;
sensor.write = user_i2c_write;
sensor.delay_ms = user_delay_ms;

int8_t rslt = BMI160_OK;
rslt = bmi160_init(&sensor);
 

It is an example of Bosch Sesonrtec for I2C conetion.

  • In bmi160_defs.h you'll find the structure declaration with what you need to know...

    /*! Read function pointer */
    bmi160_com_fptr_t read;
    /*! Write function pointer */
    bmi160_com_fptr_t write;

    You need to implement the two functions for writing/reading bytes, and pass a pointer to these functions to the library.

    Check bmi160_com_fptr_t to see what the functions prototypes should look like. 

    typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr,
    		uint8_t *data, uint16_t len)

Related