Hey everyone,
I am having trouble setting up the lsm6dsv16x as a interrupt. I was able to successfully poll the data meaning I can talk and read imu data, but no interrupt mode.
I tried most of the configuration setup, but not sure what I am missing
Here is part of the code
I did port over the st driver code from here
github.com/.../5cbd8301660f10beee129327326beb92e8af17e9
&i2c0 {
compatible = "nordic,nrf-twim";
clock-frequency = <I2C_BITRATE_FAST>;
status = "okay";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
zephyr,concat-buf-size = <1024>;
lsm6dsv16x: lsm6dsv16x@6b {
status = "okay";
compatible = "zephyr,custom-lsm6dsv16x";
int0-gpios = <&gpio0 8 (GPIO_PULL_DOWN | GPIO_ACTIVE_LOW )>;
label="lsm6dsv16x";
reg = <0x6b>;
};
bmm350: bmm350@14 {
status = "okay";
compatible = "bosch,bmm350";
reg = <0x14>;
};
};
const struct gpio_dt_spec interrupt1 = GPIO_DT_SPEC_GET(DT_NODELABEL(lsm6dsv16x), int0_gpios);
static struct gpio_callback gpio_cb;
static lsm6dsv16x_interrupt_mode_t irq;
void IMU::lsm6dsv16x_read_data_irq(void)
{
uint8_t whoamI;
int16_t data_raw_acceleration[3];
double_t acceleration_mg[3];
lsm6dsv16x_filt_settling_mask_t filt_settling_mask;
uint8_t tx_buffer[100];
// Check device ID
lsm6dsv16x_device_id_get(&dev_ctx, &whoamI);
if (whoamI != LSM6DSV16X_ID) {
LOG_ERR("Wrong device ID");
return;
}
// Restore default configuration
lsm6dsv16x_reset_set(&dev_ctx, LSM6DSV16X_RESTORE_CTRL_REGS);
lsm6dsv16x_reset_t rst;
do {
lsm6dsv16x_reset_get(&dev_ctx, &rst);
} while (rst != LSM6DSV16X_READY);
lsm6dsv16x_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
// Enable interrupt on data ready
lsm6dsv16x_pin_int_route_t pin_int = {0};
pin_int.drdy_xl = PROPERTY_ENABLE;
lsm6dsv16x_pin_int1_route_set(&dev_ctx, &pin_int);
/* Configure GPIO interrupt */
if (!device_is_ready(interrupt1.port)) {
LOG_ERR("IMU interrupt pin not ready");
return;
}
int ret = gpio_pin_configure_dt(&interrupt1, GPIO_INPUT);
if (ret != 0) {
LOG_ERR("Failed to configure IMU interrupt pin: %d", ret);
return;
}
gpio_init_callback(&gpio_cb, imu_irq_callback, BIT(interrupt1.pin));
gpio_add_callback(interrupt1.port, &gpio_cb);
ret = gpio_pin_interrupt_configure_dt(&interrupt1, GPIO_INT_EDGE_TO_ACTIVE);
if (ret != 0) {
LOG_ERR("Failed to configure IMU interrupt: %d", ret);
return;
}
// Set ODR and FS
lsm6dsv16x_xl_data_rate_set(&dev_ctx, LSM6DSV16X_ODR_AT_120Hz);
lsm6dsv16x_xl_full_scale_set(&dev_ctx, LSM6DSV16X_2g);
filt_settling_mask.drdy = PROPERTY_ENABLE;
filt_settling_mask.irq_xl = PROPERTY_ENABLE;
filt_settling_mask.irq_g = PROPERTY_ENABLE;
lsm6dsv16x_filt_settling_mask_set(&dev_ctx, filt_settling_mask);
lsm6dsv16x_filt_xl_lp2_set(&dev_ctx, PROPERTY_ENABLE);
lsm6dsv16x_filt_xl_lp2_bandwidth_set(&dev_ctx, LSM6DSV16X_XL_STRONG);
}