2025-07-06 6:07 AM
Hi There,
I've designed a board which uses a LSM6DSO32 sensor over i2c for accelerometer, gyro and it's embedded pedometer function.
I've been able to reliably get data from the sensors accelerometer and gyro registers however I've not been able to get it to return pedometer data. I'm aware of AN5473 and have followed this in my own application and have also implemented the public C driver for this IC found on github.
I'm initialising the pedometer as follows
```
int lsm6dso32_init(void)
{
int32_t ret;
uint8_t rst;
if (!lsm6dso32_is_available()) {
LOG_ERR("I2C device not ready");
return -ENODEV;
}
/* Initialize STM driver interface */
dev_ctx.write_reg = platform_write;
dev_ctx.read_reg = platform_read;
dev_ctx.mdelay = platform_delay;
dev_ctx.handle = (void *)&dev_i2c;
/* Wait sensor boot time */
platform_delay(10);
/* Check device ID */
ret = lsm6dso32_device_id_get(&dev_ctx, &whoami_value);
// if (ret != 0 || whoami_value != LSM6DSO32_ID) {
// LOG_ERR("WHO_AM_I check failed. Read: 0x%02X, ret: %d", whoami_value, ret);
// return -EINVAL;
// }
LOG_INF("LSM6DSO32 WHO_AM_I: 0x%02X", whoami_value);
/* Restore default configuration */
ret = lsm6dso32_reset_set(&dev_ctx, PROPERTY_ENABLE);
if (ret != 0) {
LOG_ERR("Reset failed: %d", ret);
return ret;
}
do {
lsm6dso32_reset_get(&dev_ctx, &rst);
} while (rst);
/* Disable I3C interface */
ret = lsm6dso32_i3c_disable_set(&dev_ctx, LSM6DSO32_I3C_DISABLE);
if (ret != 0) {
LOG_ERR("I3C disable failed: %d", ret);
return ret;
}
/* Enable Block Data Update */
ret = lsm6dso32_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
if (ret != 0) {
LOG_ERR("BDU enable failed: %d", ret);
return ret;
}
/* Set full scale */
ret = lsm6dso32_xl_full_scale_set(&dev_ctx, LSM6DSO32_8g);
if (ret != 0) {
LOG_ERR("Accel full scale failed: %d", ret);
return ret;
}
ret = lsm6dso32_gy_full_scale_set(&dev_ctx, LSM6DSO32_2000dps);
if (ret != 0) {
LOG_ERR("Gyro full scale failed: %d", ret);
return ret;
}
/* Set ODR for pedometer - needs at least 26Hz */
ret = lsm6dso32_xl_data_rate_set(&dev_ctx, LSM6DSO32_XL_ODR_26Hz_HIGH_PERF);
if (ret != 0) {
LOG_ERR("Accel ODR failed: %d", ret);
return ret;
}
ret = lsm6dso32_gy_data_rate_set(&dev_ctx, LSM6DSO32_GY_ODR_26Hz_HIGH_PERF);
if (ret != 0) {
LOG_ERR("Gyro ODR failed: %d", ret);
return ret;
}
/* Configure and enable pedometer */
LOG_INF("Configuring pedometer...");
/* Enable pedometer using correct API */
ret = lsm6dso32_pedo_sens_set(&dev_ctx, LSM6DSO32_PEDO_BASE_MODE);
if (ret != 0) {
LOG_ERR("Failed to enable pedometer: %d", ret);
return ret;
}
/* Reset step counter */
ret = lsm6dso32_steps_reset(&dev_ctx);
if (ret != 0) {
LOG_ERR("Failed to reset step counter: %d", ret);
return ret;
}
/* Configure pedometer debounce steps (optional) */
uint8_t debounce_steps = 3;
ret = lsm6dso32_pedo_debounce_steps_set(&dev_ctx, &debounce_steps);
if (ret != 0) {
LOG_WRN("Failed to set pedometer debounce: %d", ret);
// Continue - this is optional
}
/* Wait a bit for initialization */
platform_delay(100);
LOG_INF("LSM6DSO32 initialized with pedometer successfully.");
return 0;
}
I have written a debug function to print the contents of these registers to the RTT of this device, here is what it's returning
[00:04:47.283,796] <inf> lsm6dso32_nrf_shim: Device ID: 0x6C (should be 0x6C)
[00:04:47.284,334] <inf> lsm6dso32_nrf_shim: Status Register: XLDA=1, GDA=1, TDA=1
[00:04:47.287,461] <inf> lsm6dso32_nrf_shim: Accel [raw]: X=-761, Y=-110, Z=-4021
[00:04:47.287,467] <inf> lsm6dso32_nrf_shim: Gyro [raw]: X=3, Y=-12, Z=5
[00:04:47.287,472] <inf> lsm6dso32_nrf_shim: Temperature [raw]: -579
[00:04:47.287,485] <inf> lsm6dso32_nrf_shim: Accel [mg]: X=-185.7, Y=-26.8, Z=-981.1
[00:04:47.296,261] <inf> lsm6dso32_nrf_shim: Pedometer mode: 0x01
[00:04:47.296,279] <inf> lsm6dso32_nrf_shim: Pedometer enabled: YES
[00:04:47.298,649] <inf> lsm6dso32_nrf_shim: Step detection flag: 0
[00:04:47.301,036] <inf> lsm6dso32_nrf_shim: Step Count: 0
[00:04:47.301,053] <inf> lsm6dso32_nrf_shim: Activity: STATIONARY
and here is the debug print function
int lsm6dso32_pedometer_diagnostics(void)
{
int32_t ret;
lsm6dso32_data_t sensor_data;
lsm6dso32_diag_data_t diag_data;
lsm6dso32_reg_t reg;
uint8_t device_id;
uint8_t step_det_flag;
lsm6dso32_pedo_md_t pedo_mode;
LOG_INF("=== LSM6DSO32 Pedometer Diagnostics ===");
/* Check device ID */
ret = lsm6dso32_device_id_get(&dev_ctx, &device_id);
LOG_INF("Device ID: 0x%02X (should be 0x6C)", device_id);
/* Check status register */
ret = lsm6dso32_status_reg_get(&dev_ctx, ®.status_reg);
if (ret == 0) {
LOG_INF("Status Register: XLDA=%d, GDA=%d, TDA=%d",
reg.status_reg.xlda, reg.status_reg.gda, reg.status_reg.tda);
}
/* Read sensor data */
ret = lsm6dso32_read_data(&sensor_data);
if (ret == 0) {
LOG_INF("Accel [raw]: X=%d, Y=%d, Z=%d",
sensor_data.accel_x, sensor_data.accel_y, sensor_data.accel_z);
LOG_INF("Gyro [raw]: X=%d, Y=%d, Z=%d",
sensor_data.gyro_x, sensor_data.gyro_y, sensor_data.gyro_z);
LOG_INF("Temperature [raw]: %d", sensor_data.temperature);
/* Convert accelerometer to mg (for 8g scale: LSB = 0.244 mg) */
float accel_mg_x = lsm6dso32_from_fs8_to_mg(sensor_data.accel_x);
float accel_mg_y = lsm6dso32_from_fs8_to_mg(sensor_data.accel_y);
float accel_mg_z = lsm6dso32_from_fs8_to_mg(sensor_data.accel_z);
LOG_INF("Accel [mg]: X=%.1f, Y=%.1f, Z=%.1f",
(double)accel_mg_x, (double)accel_mg_y, (double)accel_mg_z);
}
/* Check pedometer configuration */
ret = lsm6dso32_pedo_sens_get(&dev_ctx, &pedo_mode);
if (ret == 0) {
LOG_INF("Pedometer mode: 0x%02X", pedo_mode);
LOG_INF("Pedometer enabled: %s", (pedo_mode != LSM6DSO32_PEDO_DISABLE) ? "YES" : "NO");
}
/* Check step detection flag */
ret = lsm6dso32_pedo_step_detect_get(&dev_ctx, &step_det_flag);
if (ret == 0) {
LOG_INF("Step detection flag: %d", step_det_flag);
}
/* Read step counter */
ret = lsm6dso32_get_diag_data(&diag_data);
if (ret == 0) {
LOG_INF("Step Count: %u", diag_data.step_count);
LOG_INF("Activity: %s", (diag_data.activity == LSM6DSO32_ACTIVITY_MOVING) ? "MOVING" : "STATIONARY");
}
LOG_INF("=====================================");
return 0;
}
Despite this I'm yet to see the module return 0x00, 0x00 for the step count registers despite the module clearly 'stepping' for 30 seconds or so with each test. It seems as if something is missing here in it's initialisation or otherwise - can you please shed some light on this, it would be much appreciated and hopefully helps the next person with this issue.