Hi Samfirex, the read and write functions require function pointers to function of yours that are able to read/write multiple bytes from/to the SPI. In the file bmi160_defs.h lines 714, 715 you can see how these functions must be defined typedef int8_t (*bmi160_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len);
typedef void (*bmi160_delay_fptr_t)(uint32_t period); You mentioned yourself the arguments the function must implement. These functions are then called in "bmi160_get_regs" or "bmi160_get_regs", e.g.: rslt = dev->read(dev->id, reg_addr, data, len); The dev_addr is a pointer to the "struct bmi160_dev yourSensor" you have to initialize before. You do not really need that (well I didn't ;-)) you could get for example the chip select pin of your SPI device, if you wrote it in the struct before. The reg_addr will be something out of the "bmi160_defs.h" file, whatever you want to read, write. data and len: for write it will be a pointer to the data which has to be written to the bmi, for read it will be a pointer where the data read from the bmi can be stored, i.e. a buffer (don't worry about that, it is handled by the API, specifically the functions that call bmi160_get_regs). Len is the number of Bytes that are to be read/written. The function for SPI read and write you have to provide can look like this (for an Arduino environment) int8_t bmi_spiWriteBytes(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
SPISettings imuSpiSettings(8000000, MSBFIRST, SPI_MODE0);
SPI1.beginTransaction(imuSpiSettings);
//csPin = dev_addr -> chip_id
digitalWrite(SS_IMU_BMI, LOW); // Initiate communication
SPI1.transfer(reg_addr); // Send Address
for (int i = 0; i < len; i++)
{
SPI1.transfer(*(data + i)); // Transfer the data
}
digitalWrite(SS_IMU_BMI, HIGH); // Close communication
SPI1.endTransaction();
return 0;
} int8_t bmi_spiReadBytes(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
SPISettings imuSpiSettings(8000000, MSBFIRST, SPI_MODE0);
SPI1.beginTransaction(imuSpiSettings);
digitalWrite(SS_IMU_BMI, LOW); // Initiate communication
SPI1.transfer(reg_addr); // Send Address
for (int i = 0; i < len; i++)
{
*(data + i) = SPI1.transfer(0x00); // request, read the data
}
digitalWrite(SS_IMU_BMI, HIGH); // Close communication
SPI1.endTransaction();
return 0;
} You have to adapt these functions to match your controllers environment. These functions you have to provide to the struct as pointers: struct bmi160_dev sensor;
sensor.id = 0;
sensor.interface = BMI160_SPI_INTF;
sensor.chip_id = SS_IMU_BMI;
sensor.read = &bmi_spiReadBytes; // Function pointer to SPI read
sensor.write = &bmi_spiWriteBytes; // Function pointer to SPI write
sensor.delay_ms = &delay; // Function pointer to delay(ms) function
rslt = bmi160_init(&sensor); Then you should be all set and you can start using the functions from the API like "bmi160_get_sensor_data(...)". Hope it works for you. Greetings Julian
... View more