2022-04-19 07:17 AM
I initialize the sensor like this:
uint8_t rst;
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.handle = &SENSOR_BUS;
static uint8_t whoamI;
/* Wait sensor boot time */
platform_delay(1000);
/* Check device ID */
lsm6dsr_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LSM6DSR_ID)
while (1);
/* Restore default configuration */
lsm6dsr_reset_set(&dev_ctx, PROPERTY_ENABLE);
do {
lsm6dsr_reset_get(&dev_ctx, &rst);
} while (rst);
/* Disable I3C interface */
lsm6dsr_i3c_disable_set(&dev_ctx, LSM6DSR_I3C_DISABLE);
/* Enable Block Data Update */
lsm6dsr_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
/* Set Output Data Rate */
lsm6dsr_xl_data_rate_set(&dev_ctx, LSM6DSR_XL_ODR_12Hz5);
lsm6dsr_gy_data_rate_set(&dev_ctx, LSM6DSR_GY_ODR_12Hz5);
/* Set full scale */
lsm6dsr_xl_full_scale_set(&dev_ctx, LSM6DSR_2g);
lsm6dsr_gy_full_scale_set(&dev_ctx, LSM6DSR_2000dps);
/* Configure filtering chain(No aux interface)
* Accelerometer - LPF1 + LPF2 path
*/
lsm6dsr_xl_hp_path_on_out_set(&dev_ctx, LSM6DSR_LP_ODR_DIV_100);
lsm6dsr_xl_filter_lp2_set(&dev_ctx, PROPERTY_ENABLE);
Then i periodicly try to read the sensors data:
uint8_t reg;
/* Read output only if new xl value is available */
lsm6dsr_xl_flag_data_ready_get(&dev_ctx, ®);
if (reg) {
/* Read acceleration field data */
memset(data_raw_acceleration, 0x00, 3 * sizeof(int16_t));
lsm6dsr_acceleration_raw_get(&dev_ctx, data_raw_acceleration);
acceleration_mg[0] =
lsm6dsr_from_fs2g_to_mg(data_raw_acceleration[0]);
acceleration_mg[1] =
lsm6dsr_from_fs2g_to_mg(data_raw_acceleration[1]);
acceleration_mg[2] =
lsm6dsr_from_fs2g_to_mg(data_raw_acceleration[2]);
sprintf(tx_buffer,
"(IMU) Acceleration [mg]: %4.2f\t%4.2f\t%4.2f\r\n",
acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
PRINTF("%s", tx_buffer);
}
lsm6dsr_gy_flag_data_ready_get(&dev_ctx, ®);
if (reg) {
/* Read angular rate field data */
memset(data_raw_angular_rate, 0x00, 3 * sizeof(int16_t));
lsm6dsr_angular_rate_raw_get(&dev_ctx, data_raw_angular_rate);
angular_rate_mdps[0] =
lsm6dsr_from_fs2000dps_to_mdps(data_raw_angular_rate[0]);
angular_rate_mdps[1] =
lsm6dsr_from_fs2000dps_to_mdps(data_raw_angular_rate[1]);
angular_rate_mdps[2] =
lsm6dsr_from_fs2000dps_to_mdps(data_raw_angular_rate[2]);
sprintf(tx_buffer,
"(IMU) Angular rate [mdps]: %4.2f\t%4.2f\t%4.2f\r\n",
angular_rate_mdps[0], angular_rate_mdps[1], angular_rate_mdps[2]);
PRINTF("%s", tx_buffer);
}
lsm6dsr_temp_flag_data_ready_get(&dev_ctx, ®);
if (reg) {
/* Read temperature data */
memset(&data_raw_temperature, 0x00, sizeof(int16_t));
lsm6dsr_temperature_raw_get(&dev_ctx, &data_raw_temperature);
temperature_degC = lsm6dsr_from_lsb_to_celsius(
data_raw_temperature);
sprintf(tx_buffer, "(IMU) Temperature [degC]: %6.2f\r\n",
temperature_degC );
PRINTF("%s", tx_buffer);
}
"reg" is always zero, thats why it never enters the if-statement to get the data. But even when i force the code to enter the if-statement it just returns 0.00 0.00 0.00.
I also tried to get activitydata with the same behaviour.
Does anyone of you see what's missing in my code?
Solved! Go to Solution.
2022-04-25 03:17 AM
Hi Eleon
I found out that only the readfunction was working properly. Now the writefunction is also working and lets me read data from the sensor
2022-04-22 06:59 AM
Hi @Hannes Wäckerlig ,
which hardware platform are you using in you application?
Are you using I2C or SPI? And did you check the goodness of the signal with an oscilloscope?
-Eleon
2022-04-25 03:17 AM
Hi Eleon
I found out that only the readfunction was working properly. Now the writefunction is also working and lets me read data from the sensor
2022-04-26 01:13 AM
Hi @Hannes Wäckerlig
glad you found and shared the solution to the issue!
Best,
-Eleon
2022-12-04 05:05 AM
Hi @Hannes Wäckerlig ,
I am having the same issue. The write won't work. What did you do to get it to work
thanks,
Don
2022-12-06 08:53 AM
Hi @HWäck.1,
I am having the same issue. I don't see the solution posted here. Could you share the solution?
Much Thanks,
Don