Lis2mdl dont launch a trigger when i program with a threshold

Hello everyone,

I have tried several different approaches to solve this issue, but I have not been successful so far.

My goal is to generate an interrupt when the LIS2MDL magnetic field measurements (X, Y, and Z) go below a defined threshold. I created a small test application (shown below) to verify the interrupt functionality.

I have experimented with many different threshold values, including very low and very high settings, but the interrupt is never triggered.

Has anyone successfully used the LIS2MDL threshold interrupt feature with Zephyr or the nRF5340? Am I missing a required configuration step, such as interrupt routing, GPIO configuration, or sensor initialization?

Alsi "I'm having an doubt verifying if a trigger was successfully programmed on the sensor. When I configure it like this:

The function always returns success (ret == 0), even when I set a trigger type that the sensor theoretically doesn't support. I have no way to verify if the trigger was actually applied or just silently ignored by the driver."

 my code :: 
````

truct sensor_trigger trig = {
        .type = SENSOR_TRIG_THRESHOLD,  
        .chan = SENSOR_CHAN_MAGN_XYZ,
    };
    ret = sensor_trigger_set(sensor, &trig, trigger_handler);
    if (ret != 0) {
        LOG_ERR("Failed to set trigger: %d\n", ret);
        return ret;
    }
    LOG_INF("trigger set successfull\n");
    return 0;````

Driver code :: 

/* link external trigger to event data ready */
int lis2mdl_trigger_set(const struct device *dev,
              const struct sensor_trigger *trig,
              sensor_trigger_handler_t handler)
{
    const struct lis2mdl_config *cfg = dev->config;
    stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
    struct lis2mdl_data *lis2mdl = dev->data;
    int16_t raw[3];

    if (!cfg->trig_enabled) {
        LOG_ERR("trigger_set op not supported");
        return -ENOTSUP;
    }

    if (trig->chan == SENSOR_CHAN_MAGN_XYZ) {
        lis2mdl->handler_drdy = handler;
        lis2mdl->trig_drdy = trig;
        if (handler) {
            /* fetch raw data sample: re-trigger lost interrupt */
            LOG_ERR("trigger_set supported");
            lis2mdl_magnetic_raw_get(ctx, raw);

            //return lis2mdl_enable_int(dev, 1);
            return 0;
        } else {
            return lis2mdl_enable_int(dev, 0);
        }
    }

    return -ENOTSUP;
}````

Any suggestions would be greatly appreciated.

To configure a trigger mode i applied this configuration as say in the datasheet but no respone :: 

`````

Thank you.

Parents
  • ASMA,

    This thread is mostly about the LIS2MDL and very less about nRF solutions, but I will still try to give you some of my thoughts.

    The LIS2MDL Zephyr driver only implements the data-ready trigger. lis2mdl_trigger_set() never checks trig->type. Only trig->chan, so SENSOR_TRIG_THRESHOLD takes the data-ready path and returns 0 then arms DRDY. That is why you always seem to get success and the threshold interrupt is never firing.

    I do not think that the INT_CTRL / INT_THS are ever configured. Also, I think that the LIS2MDL threshold interrupt is "absolute value exceeds ±threshold" in hardware. There is no below-threshold mode, so you cannot get a hardware interrupt for the field dropping below a value even with a full driver. So I would recommend you to keep SENSOR_TRIG_DATA_READY, and in the handler do sensor_sample_fetch + sensor_channel_get and compare against your threshold there. Should work with the upstream driver.

Reply
  • ASMA,

    This thread is mostly about the LIS2MDL and very less about nRF solutions, but I will still try to give you some of my thoughts.

    The LIS2MDL Zephyr driver only implements the data-ready trigger. lis2mdl_trigger_set() never checks trig->type. Only trig->chan, so SENSOR_TRIG_THRESHOLD takes the data-ready path and returns 0 then arms DRDY. That is why you always seem to get success and the threshold interrupt is never firing.

    I do not think that the INT_CTRL / INT_THS are ever configured. Also, I think that the LIS2MDL threshold interrupt is "absolute value exceeds ±threshold" in hardware. There is no below-threshold mode, so you cannot get a hardware interrupt for the field dropping below a value even with a full driver. So I would recommend you to keep SENSOR_TRIG_DATA_READY, and in the handler do sensor_sample_fetch + sensor_channel_get and compare against your threshold there. Should work with the upstream driver.

Children
No Data
Related