INT2 working but INT1 is not

Please find below my config for handling Interrupt calls.

I've tested on another sensor dev board that the sensor I use is properly set up and is sending INT1 and INT2. 

I also tried switching the outputs of the sensor and when I did so I got a response on INT2 (that should have been triggered on INT1) and vice versa. 

I also tried switching the INT pins in the device tree and that worked.

I cant seem to get INT1 to work while int@ works as desired. The configuration is the same, there are no conflicts in any error messages or device tree.

	buttons {
		compatible = "gpio-keys";
		button1: button_1 {
			gpios = <&gpio1 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
			label = "Push button 2";
		};
		int1: int_1 {
			status = "okay";
			gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
			label = "interrupt 1";
		};
		int2: int_2 {
			status = "okay";
			gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
			label = "interrupt 2";
		};
	};


#define INT1_NODE            DT_ALIAS(int1)
#define INT1_GPIO_CONTROLLER DEVICE_DT_GET(DT_GPIO_CTLR(INT1_NODE, gpios))
#define INT1_GPIO_PIN        DT_GPIO_PIN(INT1_NODE, gpios)
#define INT1_GPIO_FLAGS      (DT_GPIO_FLAGS(INT1_NODE, gpios) | GPIO_INPUT)

#define INT2_NODE            DT_ALIAS(int2)
#define INT2_GPIO_CONTROLLER DEVICE_DT_GET(DT_GPIO_CTLR(INT2_NODE, gpios))
#define INT2_GPIO_PIN        DT_GPIO_PIN(INT2_NODE, gpios)
#define INT2_GPIO_FLAGS      (DT_GPIO_FLAGS(INT2_NODE, gpios) | GPIO_INPUT)


struct k_work idleDetected_work;
struct k_work int1_work;

void idleDetected_work_handler(struct k_work* item) {
  printk("Idle detected\n");
}

void int1_work_handler(struct k_work* item) {
  printk("INT2\n");
}

void int1_callback(const struct device* dev, struct gpio_callback* cb, uint32_t pins) {
  k_work_submit(&idleDetected_work);
}

void int2_callback(const struct device* dev, struct gpio_callback* cb, uint32_t pins) {
  k_work_submit(&int1_work);
}

int configure_gpio(const struct device* gpio_dev, gpio_pin_t pin, gpio_flags_t flags) {
  int ret;

  /* Ensure the GPIO device is ready */
  if (!device_is_ready(gpio_dev)) {
    printk("Error: %s device not ready\n", gpio_dev->name);
    return -1;
  }

  /* Configure the GPIO pin */
  ret = gpio_pin_configure(gpio_dev, pin, flags);
  if (ret != 0) {
    printk("Failed to configure GPIO pin %d: %d\n", pin, ret);
    return ret;
  }

  /* Configure the GPIO pin interrupt */
  ret = gpio_pin_interrupt_configure(gpio_dev, pin, GPIO_INT_EDGE_TO_ACTIVE);
  if (ret != 0) {
    printk("Failed to configure GPIO pin interrupt %d: %d\n", pin, ret);
    return ret;
  }

  return 0;
}

int setup_gpio_callback(const struct device* gpio_dev, gpio_pin_t pin, struct gpio_callback* cb, gpio_callback_handler_t handler) {
  int ret;

  /* Initialize and add the GPIO callback */
  gpio_init_callback(cb, handler, BIT(pin));
  ret = gpio_add_callback(gpio_dev, cb);
  if (ret != 0) {
    printk("Failed to add GPIO callback for pin %d: %d\n", pin, ret);
    return ret;
  }

  return 0;
}

int setup_irq_init(const struct i2c_dt_spec* dev) {
  int status;

  status = configure_gpio(INT1_GPIO_CONTROLLER, INT1_GPIO_PIN, INT1_GPIO_FLAGS);
  check_error(status, "configure_gpio1");

  status = setup_gpio_callback(INT1_GPIO_CONTROLLER, INT1_GPIO_PIN, &int1_cb_data, int1_callback);
  check_error(status, "setup_gpio_callback1");

  status = configure_gpio(INT2_GPIO_CONTROLLER, INT2_GPIO_PIN, INT2_GPIO_FLAGS);
  check_error(status, "configure_gpio2");

  status = setup_gpio_callback(INT2_GPIO_CONTROLLER, INT2_GPIO_PIN, &int2_cb_data, int2_callback);
  check_error(status, "setup_gpio_callback2");

  k_work_init(&int1_work, int1_work_handler);
  k_work_init(&idleDetected_work, idleDetected_work_handler);

  return 0; // Success
}

What am I doing wrong?

Parents Reply Children
  • This is an excerpt from zephyr.dts where P0.11 is referenced. I can't see what's colliding.

    	buttons {
    		compatible = "gpio-keys";
    		button0: button_0 {
    			gpios = < &gpio0 0x17 0x11 >;
    			label = "Push button 1";
    			zephyr,code = < 0xb >;
    		};
    		button1: button_1 {
    			gpios = < &gpio1 0xd 0x11 >;
    			label = "Push button 2";
    			zephyr,code = < 0x2 >;
    		};
    		button2: button_2 {
    			gpios = < &gpio0 0x8 0x11 >;
    			label = "Push button 3";
    			zephyr,code = < 0x3 >;
    		};
    		button3: button_3 {
    			gpios = < &gpio0 0x9 0x11 >;
    			label = "Push button 4";
    			zephyr,code = < 0x4 >;
    			status = "disabled";
    		};
    		int1: int_1 {
    			status = "okay";
    			gpios = < &gpio0 0xb 0x0 >;
    			label = "interrupt 1";
    		};
    		int2: int_2 {
    			status = "okay";
    			gpios = < &gpio0 0x9 0x0 >;
    			label = "interrupt 2";
    		};
    	};
    	arduino_header: connector {
    		compatible = "arduino-header-r3";
    		#gpio-cells = < 0x2 >;
    		gpio-map-mask = < 0xffffffff 0xffffffc0 >;
    		gpio-map-pass-thru = < 0x0 0x3f >;
    		gpio-map = < 0x0 0x0 &gpio0 0x4 0x0 >, < 0x1 0x0 &gpio0 0x5 0x0 >, < 0x2 0x0 &gpio0 0x6 0x0 >, < 0x3 0x0 &gpio0 0x7 0x0 >, < 0x4 0x0 &gpio0 0x19 0x0 >, < 0x5 0x0 &gpio0 0x1a 0x0 >, < 0x6 0x0 &gpio1 0x0 0x0 >, < 0x7 0x0 &gpio1 0x1 0x0 >, < 0x8 0x0 &gpio1 0x4 0x0 >, < 0x9 0x0 &gpio1 0x5 0x0 >, < 0xa 0x0 &gpio1 0x6 0x0 >, < 0xb 0x0 &gpio1 0x7 0x0 >, < 0xc 0x0 &gpio1 0x8 0x0 >, < 0xd 0x0 &gpio1 0x9 0x0 >, < 0xe 0x0 &gpio1 0xa 0x0 >, < 0xf 0x0 &gpio1 0xb 0x0 >, < 0x10 0x0 &gpio1 0xc 0x0 >, < 0x11 0x0 &gpio1 0xd 0x0 >, < 0x12 0x0 &gpio1 0xe 0x0 >, < 0x13 0x0 &gpio1 0xf 0x0 >, < 0x14 0x0 &gpio1 0x2 0x0 >, < 0x15 0x0 &gpio1 0x3 0x0 >;
    		phandle = < 0x8 >;
    	};
    	arduino_adc: analog-connector {
    		compatible = "arduino,uno-adc";
    		#io-channel-cells = < 0x1 >;
    		io-channel-map = < 0x0 &adc 0x0 >, < 0x1 &adc 0x1 >, < 0x2 &adc 0x2 >, < 0x3 &adc 0x3 >, < 0x4 &adc 0x4 >, < 0x5 &adc 0x5 >;
    	};
    	gpio_fwd: nrf-gpio-forwarder {
    		compatible = "nordic,nrf-gpio-forwarder";
    		status = "okay";
    		uart {
    			status = "disabled";
    			gpios = < &gpio0 0xb 0x0 >, < &gpio0 0xa 0x0 >;
    		};
    	};
    				i2c2: i2c@b000 {
    				compatible = "nordic,nrf-twim";
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				clock-frequency = < 0x186a0 >;
    				interrupts = < 0xb 0x1 >;
    				easydma-maxcnt-bits = < 0x10 >;
    				status = "disabled";
    			};
    			spi2: spi@b000 {
    				compatible = "nordic,nrf-spim";
    				#address-cells = < 0x1 >;
    				#size-cells = < 0x0 >;
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				max-frequency = < 0x7a1200 >;
    				easydma-maxcnt-bits = < 0x10 >;
    				status = "disabled";
    			};
    			uart2: uart@b000 {
    				compatible = "nordic,nrf-uarte";
    				reg = < 0xb000 0x1000 >;
    				interrupts = < 0xb 0x1 >;
    				status = "disabled";
    			};
    
    		pwm0_default: pwm0_default {
    			phandle = < 0xb >;
    		};

  • Hi,

    Apologies for the long response time.

    Could you please check if you're able to reproduce this on a nRF5340DK?

    I've not been able to reproduce the behavior.

    Kind regards,
    Andreas

Related