trying to get interrupt from lis2dw12 sensor, using nrf 52840dk board

i'm trying to get an interrupt using sensor lis2dw12 , i have connected my int1 pin of sensor to my gpio 0.10. whenever data is ready it should give me an interrupt 

static void trigger_handler(const struct device *dev,
                            const struct sensor_trigger *trig)
{
        printk("signal\n");
        struct sensor_value accel[3];
        if (sensor_sample_fetch(dev) < 0)
        {
                printk("Sample fetch error\n");
                return;
        }

        if (sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, accel) < 0)
        {
                printk("Channel get error\n");
                return;
        }

        printk("Acceleration (m/s^2): x: %f, y: %f, z: %f\n",
               sensor_value_to_double(&accel[0]),
               sensor_value_to_double(&accel[1]),
               sensor_value_to_double(&accel[2]));
}

void main(void)
{
        const struct device *dev = DEVICE_DT_GET(DT_INST(0, st_lis2dw12));

        if (dev == NULL)
        {
                printk("Could not get LIS2DW12 device\n");
                return;
        }

        struct sensor_trigger trig = {
            .type = SENSOR_TRIG_DATA_READY,
            .chan = SENSOR_CHAN_ACCEL_XYZ,
        };

        if (sensor_trigger_set(dev, &trig, trigger_handler) < 0)
        {
                printk("Unable to set trigger\n");
                return;
        }

        while (1)
        {
        }
        return;
}

this is my code 
and 
&i2c0 {
    status = "okay";

    lis2dw12: lis2dw12@19 {
        compatible = "st,lis2dw12";
        reg = <0x19>;
        label = "LIS2DW12";
        int-pin = <1>;
        irq-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>;
        wakeup-duration = <3>;
    };
};

this is my dts file

Parents
  • Hi!

    i'm trying to get an interrupt using sensor lis2dw12 , i have connected my int1 pin of sensor to my gpio 0.10. whenever data is ready it should give me an interrupt 

    But it does not work? Could you explain your issue some more?


  • lis2dw12 is my sensor i want to config in such a way that whenever my acceleration value crosses certain threshold value it should give me interrupt.  

    but currently what i have tried is i have put certain threshold value, as you can it in my main code .
    in terminal whenever i short my gpio 0.28 pin to GND. it reset my board.
    this is my main code 

    &i2c0 {
        status = "okay";
    
        lis2dw12: lis2dw12@19 {
            compatible = "st,lis2dw12";
            reg = <0x19>;
            label = "LIS2DW12";
    
            irq-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>,<&gpio0 9 GPIO_ACTIVE_HIGH>;
    
    
        };
    };


    this is my overlay file .
    &i2c0 {
        status = "okay";
    
        lis2dw12: lis2dw12@19 {
            compatible = "st,lis2dw12";
            reg = <0x19>;
            label = "LIS2DW12";
    
            irq-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>,<&gpio0 9 GPIO_ACTIVE_HIGH>;
    
    
        };
    };
Reply

  • lis2dw12 is my sensor i want to config in such a way that whenever my acceleration value crosses certain threshold value it should give me interrupt.  

    but currently what i have tried is i have put certain threshold value, as you can it in my main code .
    in terminal whenever i short my gpio 0.28 pin to GND. it reset my board.
    this is my main code 

    &i2c0 {
        status = "okay";
    
        lis2dw12: lis2dw12@19 {
            compatible = "st,lis2dw12";
            reg = <0x19>;
            label = "LIS2DW12";
    
            irq-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>,<&gpio0 9 GPIO_ACTIVE_HIGH>;
    
    
        };
    };


    this is my overlay file .
    &i2c0 {
        status = "okay";
    
        lis2dw12: lis2dw12@19 {
            compatible = "st,lis2dw12";
            reg = <0x19>;
            label = "LIS2DW12";
    
            irq-gpios = <&gpio0 28 GPIO_ACTIVE_HIGH>,<&gpio0 9 GPIO_ACTIVE_HIGH>;
    
    
        };
    };
Children
Related