03-25-2022 01:12 PM
Hello.
I've followed the data synchronization guide from GitHub and I've used the example as a reference to work with this sensor.
I've configured the interrupts as indicated in the example, with the difference that I'm working with the STM32, so I'm not using the COINES library.
while (1)
{
previous_time = sensor_time * BMI08X_SENSORTIME_RESOLUTION;
rslt = bmi08a_get_synchronized_data(&bmi08x_accel, &bmi08x_gyro, &bmi08xdev);
rslt = bmi08a_get_sensor_time(&bmi08xdev, &sensor_time);
elapsed_time = sensor_time * BMI08X_SENSORTIME_RESOLUTION;
duration = (elapsed_time - previous_time) * 1000;
}
The problem I have is that when I run the function to obtain the data from the sensors, the accelerometer is always reading the same data. The gyroscope appears to work correctly. When I read the data separately, I mean without using synchronization, I have no problem reading the data of both sensors.
/* Read accel x,y sensor data */
reg_addr = BMI08X_REG_ACCEL_GP_0;
rslt = bmi08a_get_regs(reg_addr, &data[0], 4, dev);
...
/* Read accel sensor data */
reg_addr = BMI08X_REG_ACCEL_GP_4;
rslt = bmi08a_get_regs(reg_addr, &data[4], 2, dev);
I've noticed that the bmi08a_get_synchronized_data function reads different registers than the bmi08a_get_data function does. It does the reading of two general purpose registers, so I see first of length 4 and then of length 2. I assume to read x and y first, and then z. The problem here is that I've observed that even though it's performing the SPI reading correctly, it always reads the same values in the data array.
/* Read accel sensor data */
rslt = bmi08a_get_regs(BMI08X_REG_ACCEL_X_LSB, data, 6, dev);
So, I tried to modify the bmi08a_get_synchronized_data function in order to make the SPI reading in the same register as the bmi08a_get_data function, as shown above. This way, it's reading the accelerometer data correctly. The problem with doing something like this is that I'm not supposed to modify the library, so I don't know if that means there is no longer synchronization in reading the data from both sensors, since it's reading it in a different register.
I attach the file with the initialization functions. I've followed the examples, so it shouldn't make any difference how I did it.
Solved! Go to Solution.
03-25-2022 02:25 PM
03-28-2022 05:41 PM
I've tried to follow the example attatched in your reply. As you can see in the gifs the problem persists, I get the same data all the time in the accelerometer. It makes the register reading, but it seems that it's always the same exact data.
I'll attach the project, the main files are the common and the main, where I've done the same as in the example. I definitely don't understand where the problem is, because I've tried different boards and the same problem occurs on all of them.
04-11-2022 11:01 AM
Hi jorgazam,
You could modify SPI clock frequency and test it again.
If your CPU frequency was set to 64 MHz, then the following SPI clock frequency will be too high.
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
SPI clock frequency should be configured bellow 10 MHz.
04-11-2022 11:23 AM - edited 04-11-2022 11:28 AM
Hello,
Thanks for answering, it's useful to know what you have said, but this is not the case, since if you check the project that I attached in the previous answer, the clock is set to 4 MHz.
The solution I used to obtain the simultaneous reading has been to create my own function that combines the reading functions of the accelerometer and gyroscope from the Bosch library, in addition to the sensor time. This seems to work the way I wanted, so I'll end this post. Thanks for the answers.
Edit: I'm going to add the function, it has nothing new, it's just a combination of those from the library.
BMI08X_INTF_RET_TYPE bmi08x_get_data(struct bmi08x_sensor_data *accel, struct bmi08x_sensor_data *gyro, uint32_t *sensor_time, struct bmi08x_dev *dev)
{
int8_t rslt;
uint8_t data[9] = { 0 };
uint8_t lsb, msb;
uint16_t msblsb;
uint32_t byte2, byte1, byte0;
/* Proceed if null check is fine */
if ((accel != NULL) && (sensor_time != NULL))
{
/* Read accel sensor data & sensor time */
rslt = bmi08a_get_regs(BMI08X_REG_ACCEL_X_LSB, data, 9, dev);
if (rslt == BMI08X_OK)
{
lsb = data[0];
msb = data[1];
msblsb = (msb << 8 ) | lsb;
accel->x = ((int16_t) msblsb); /* Data in X axis */
lsb = data[2];
msb = data[3];
msblsb = (msb << 8 ) | lsb;
accel->y = ((int16_t) msblsb); /* Data in Y axis */
lsb = data[4];
msb = data[5];
msblsb = (msb << 8 ) | lsb;
accel->z = ((int16_t) msblsb); /* Data in Z axis */
byte0 = data[6]; /* Lower byte */
byte1 = (data[7] << 8); /* Middle byte */
byte2 = (data[8] << 16); /* Higher byte */
/* Sensor time */
*sensor_time = (byte2 | byte1 | byte0);
/* Read gyro sensor data */
rslt = bmi08g_get_data(gyro, dev);
}
}
else
{
rslt = BMI08X_E_NULL_PTR;
}
return rslt;
}