Interrupt setup in devicetree overlay for I2C device - nrf5340

Hi,

I'm developing a library (in the "src" folder of the project) for a I2C sensor. The device is a temperature sensor that has a specific pin for alert (interrupt). I'm trying to understand how to write properly a DTS overlay file to implement such functionalities. I already read the last devicetree specifications (0.4rc) and looked in nrf connect sdk documentation, but specific info on syntax and requirements are missing (or i have not been able to find them!). 

I would like to connect the interrupt pin on P1.10, but i don't understand what are the required fields and their parameters. This is my overlay at the moment

&i2c1 {
    compatible = "nordic,nrf-twim";
    status="okay";
    pinctrl-0=<&i2c1_default>;
    pinctrl-1=<&i2c1_sleep>;
    
    temp-sensor-test: temp_sens@18{
        compatible = "i2c-device";
        reg = <0x18>;
        label = "temp_sens";
        interrupt-parent = < &nvic >;
        interrupts = <1 NRF_DEFAULT_IRQ_PRIORITY>;
    };
    
};

Even if i know that there are different ways i can make an interrupt work, i'm trying to understand better how to use devicetree more efficiently. Any guide or suggestion you can provide me is really appreciated!

Thanks,

Frax

Parents Reply Children
  • I'm developing a library (in the "src" folder of the project) for a I2C sensor.

    So since your library just use the I2C driver, you do not need to do a fancy out of tree module thing, as you pointed out.

    frax84 said:
    1) use gpio bindings (like in the sample for button interrupt) and use them in code with gpio apis. In this case everything is already available out of the box, but i have to map separately the i2c device and its interrupt pin.

    This for sure sounds like the easiest solution to implement.

    frax84 said:
    2) write a custom yaml file for the i2c device i'm working on add a field for interrupt parameters on it, use the "compatible" property in the DTS overlay and use these in code with gpio apis. In this case i need to write an additional file (the custom yaml) but the result is more compact and maintanable.

    Yes, this would make sense to me. Requires more work, but is more elegant than 1).

    See this unofficial sample on how you can add a this yaml file.

    Regards,
    Sigurd Hellesvik

  • Hi Sigurd,

    Thank you for your feedback and the useful link. I'll post my solution when is done for the community, but it will take a bit. In the meantime I'll mark the post as solved.

    Thx

    Frax

Related