Skip to content

Day23 - I2C Sensor Interrupt

Objective

Enable interrupt-driven update for I2C sensor driver.


Step 1 - Modify Device Tree Overlay

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2712";

    fragment@0 {
        target = <&rp1_gpio>;
        __overlay__ {
            my_sensor_pins: my_sensor_pins {
                brcm,pins = <23>;
                brcm,function = <0>;
                brcm,pull = <2>;
            };
        };
    };

    fragment@1 {
        target = <&i2c1>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;

            myi2c_sensor@48 {
                compatible = "myvendor,myi2c-sensor";
                reg = <0x48>;

                interrupt-parent = <&rp1_gpio>;
                interrupts = <23 IRQ_TYPE_EDGE_FALLING>;

                pinctrl-names = "default";
                pinctrl-0 = <&my_sensor_pins>;
            };
        };
    };
};

Step 2 - Rebuild and Load

make
sudo insmod myi2c_sensor.ko
sudo dtoverlay myi2c_snr

Step 3 - Verify Driver Probe

dmesg | grep myi2c

Expected:

  • probe success
  • IRQ registered

Step 4 - Check Interrupt Entry

grep myi2c_sensor_irq /proc/interrupts

Step 5 - Trigger Interrupt

Press STM32 button.

Expected:

  • interrupt counter increases

Step 6 - Test Script

chmod +x test_irq.sh
./test_irq.sh

Optional - Live Monitor

watch -n 0.5 "grep myi2c_sensor_irq /proc/interrupts"

Result

  • IRQ successfully triggered
  • Driver reacts to hardware interrupt