12-15-2020 11:31 AM - edited 12-15-2020 01:24 PM
Hello,
I'm working with a BMI270 and its GitHub library. I noticed a important change with the release v.2.46.1. (File bmi2_defs.h)
The old typedef function pointer for the bus interfacing was:
typedef int8_t (*bmi2_read_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);
this instruction has been modified to:
typedef BMI2_INTF_RETURN_TYPE (*bmi2_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr);
I don't fully understand the interest of such a change... Because now the device address must be passed through the pointer *intf_ptr ... I find it much less clear. There's probably a good reason for this change but I don't understand it.
If someone can help me...
Thanks
Solved! Go to Solution.
12-15-2020 06:40 PM
Hello rey-a,
If you are using i2c, you should put dev id in interface as below.
i2c_bus = BMI2_I2C_PRIM_ADDR;
bmi2.intf_ptr = &i2c_bus;
bmi2.intf = BMI2_I2C_INTF;
bmi2.read = bmi2xy_hal_i2c_bus_read;
bmi2.write = bmi2xy_hal_i2c_bus_write;
/*! This API is used to perform I2C read operation with sensor */
int8_t bmi2xy_hal_i2c_bus_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
int8_t rslt = 0;
//uint8_t dev_id = 0x68;
uint8_t* dev_id = (uint8_t *)intf_ptr;
rslt = BMI270_read_i2c(*dev_id, reg_addr, reg_data, length);
return rslt;
}
/*! This API is used to perform I2C write operations with sensor */
int8_t bmi2xy_hal_i2c_bus_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
{
int8_t rslt = 0;
// uint8_t dev_id = 0x68;
uint8_t* dev_id = (uint8_t *)intf_ptr;
rslt = BMI270_write_i2c(*dev_id, reg_addr, (uint8_t *)reg_data, length);
return rslt;
}
If you are using spi and doesn't use several slave, but only bmi270, you don't need to use it. ( It's for chip selection )
But, anyway you need to put it as below.
#define BMI260_CS 10
spi_bus = BMI260_CS;
bmi2.intf_ptr = &spi_bus;
bmi2.intf = BMI2_SPI_INTF;
bmi2.read = BMI270_read_spi;
bmi2.write = BMI270_write_spi;
Thanks,
12-16-2020 12:44 PM
My question wasn't about the way to use it but on the reason of this changement. So if I understand it correctly, it has been changement to use the same variable (a void pointer) to use it as I2C or SPI parameter depending on the bus used.
I found the parameter badly adapted to transmit the i2c address, but now it's make sense.
Thanks for your response.
12-16-2020 06:52 PM
Hello rey-a,
Its intention could be flexibility. Using void paramater, it can get any type of value as parameter.
Yap, but it could be confusing for old user, and some people.
Thanks 🙂