04-05-2022 04:38 PM - edited 04-05-2022 04:41 PM
I would like to know where in the driver library of BMI160 (version 3.9.1/version 3.9.2) the "bmi160_com_fptr_t" is declared.
I have errors initializing the BMI160 due to the lines with "bmi160_com_fptr", and I could not find the declaration of "bmi160_com_fptr_t" in any of the files contained in the driver library; bmi160.c/bmi160.h/bmi160_defs.h from https://github.com/BoschSensortec/BMI160_driver.
I have tried initializing with version 3.9.1 and version 3.9.2. I am using the built-in BMI160 sensor on Cypress (Infenion) PSoC 6 BLE Pioneer kit.
Thank you.
/* ========================================
*
* Copyright YOUR COMPANY, THE YEAR
* All Rights Reserved
* UNPUBLISHED, LICENSED SOFTWARE.
*
* CONFIDENTIAL AND PROPRIETARY INFORMATION
* WHICH IS THE PROPERTY OF your company.
*
* ========================================
*/
#include "project.h"
// Added
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>
#include "bmi160.h"
#include "bmi160_defs.h"
static struct bmi160_dev bmi160Dev; // Added
static int8_t BMI160BurstWrite(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, & I2C_1_context);
for(int i = 0; i < len; i++)
{
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, data[i], 0, &I2C_1_context);
}
Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);
return 0;
}
// This function supports the BMP?180 library and read I2C Registers
static int8_t BMI160BurstRead(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len)
{
Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
Cy_SCB_I2C_MasterWriteByte(I2C_1_HW, reg_addr, 0, & I2C_1_context);
Cy_SCB_I2C_MasterSendReStart(I2C_1_HW, dev_addr, CY_SCB_I2C_WRITE_XFER, 0, &I2C_1_context);
for(int i = 0; i < len -1; i++)
{
Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_ACK, &data[i], 0, &I2C_1_context);
}
Cy_SCB_I2C_MasterReadByte(I2C_1_HW, CY_SCB_I2C_NAK, &data[len-1], 0, &I2C_1_context);
Cy_SCB_I2C_MasterSendStop(I2C_1_HW, 0, &I2C_1_context);
return 0;
}
static void bmi160Init(void)
{
vTaskDelay(100); // Guess
/* BMI160 */
bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
bmi160Dev.delay_ms = (bmi160_delay_fptr_t)vTaskDelay;
bmi160Dev.id = BMI160_I2C_ADDR; // I2C device address
bmi160_init(&bmi160Dev); // Initialize the device
bmi160Dev.gyro_cfg.odr = BMI160_GYRO_ODR_800HZ;
bmi160Dev.gyro_cfg.range = BMI160_GYRO_RANGE_125_DPS;
bmi160Dev.gyro_cfg.bw = BMI160_GYRO_BW_OSR4_MODE;
/* Select the power mode of Gyroscope sensor */
bmi160Dev.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
bmi160Dev.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
bmi160Dev.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
bmi160Dev.accel_cfg.bw = BMI160_ACCEL_BW_OSR4_AVG1;
bmi160Dev.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
/* Set the sensor configuration */
bmi160_set_sens_conf(&bmi160Dev);
bmi160Dev.delay_ms(50);
}
// 32768 = 2g
#define MAXACCEL (32768/2)
void motionTask(void *arg)
{
(void)arg;
I2C_1_Start();
bmi160Init();
struct bmi160_sensor_data acc;
float gx, gy, gz;
while(1)
{
bmi160_get_sensor_data(BMI160_ACCEL_ONLY, &acc, NULL, &bmi160Dev);
gx = (float)acc.x/MAXACCEL;
gy = (float)acc.y/MAXACCEL;
gz = (float)acc.z/MAXACCEL;
printf ("x=%1.2f y=%1.2f z=%1.2f\r\n", gx, gy, gz);
vTaskDelay(200);
}
}
int main(void)
{
__enable_irq(); /* Enable global interrupts. */
UART_1_Start();
xTaskCreate(motionTask, "Motion Task", 400, 0, 1, 0);
vTaskStartScheduler();
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
for(;;)
{
/* Place your application code here. */
}
}
/* [] END OF FILE */
Solved! Go to Solution.
04-06-2022 03:13 AM
Hi showns,
You could see the declaration of the write() read() function from this structure.
struct bmi160_dev
{
...
/*! Read function pointer */
bmi160_read_fptr_t read;
/*! Write function pointer */
bmi160_write_fptr_t write;
...
}
So for your code,
bmi160Dev.read = (bmi160_com_fptr_t)BMI160BurstRead;
bmi160Dev.write = (bmi160_com_fptr_t)BMI160BurstWrite;
should be:
bmi160Dev.read = (bmi160_read_fptr_t)BMI160BurstRead;
bmi160Dev.write = (bmi160_write_fptr_t)BMI160BurstWrite;