Unable to read from GPIO P0.10 on nRF5340

I am trying to read from a GPIO configured as input and the value returned from gpio_pin_get_raw() is always 0. I have verified the voltage into the pin is 3.3v. Here is the code

#include <zephyr/kernel.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/gpio.h>

#define GPIO0_NODE DT_NODELABEL(gpio0)
#define ROGUE_IRQ_PIN 10

const struct device *gpio0_dev;

void main(void)
{
    gpio0_dev = DEVICE_DT_GET(GPIO0_NODE);
    gpio_pin_configure(gpio0_dev, ROGUE_IRQ_PIN, GPIO_INPUT);
    printk("irq=%d\n", gpio_pin_get_raw(gpio0_dev, ROGUE_IRQ_PIN));
}
I'm using ncs v2.4.2
This seems very simple. Am I missing something in my configuration? I have CONFIG_GPIO=y in my prt.conf. Do I need something in my device tree overlay?


Parents
  • I also tried the following. First, I added the following to my overlay file

    	buttons {
    		compatible = "gpio-keys";
    		button5: button_5 {
    			gpios = <&gpio0 10 (GPIO_ACTIVE_HIGH)>;
    			label = "IRQ_BT40";
    		};
    	};
    
    	aliases {
    		ircr0 = &button5;
    	};
    

    Then I rewrote the code as follows:

    #define IRQ0 DT_NODELABEL(button5)
    const struct gpio_dt_spec irqr = GPIO_DT_SPEC_GET(IRQ0, gpios);
    
    void main(void)
    {
      if (!device_is_ready(irqr.port)) printk("IRQ not ready\n");
      gpio_pin_configure_dt(&irqr, GPIO_INPUT);
      printk("IRQ=%d\n", gpio_pin_get_dt(&irqr));
      }
      

    But this behaves the same as before.

    I looked through build/zephyr/zephyr.dts but don't see any other device that uses P0.10.

Reply
  • I also tried the following. First, I added the following to my overlay file

    	buttons {
    		compatible = "gpio-keys";
    		button5: button_5 {
    			gpios = <&gpio0 10 (GPIO_ACTIVE_HIGH)>;
    			label = "IRQ_BT40";
    		};
    	};
    
    	aliases {
    		ircr0 = &button5;
    	};
    

    Then I rewrote the code as follows:

    #define IRQ0 DT_NODELABEL(button5)
    const struct gpio_dt_spec irqr = GPIO_DT_SPEC_GET(IRQ0, gpios);
    
    void main(void)
    {
      if (!device_is_ready(irqr.port)) printk("IRQ not ready\n");
      gpio_pin_configure_dt(&irqr, GPIO_INPUT);
      printk("IRQ=%d\n", gpio_pin_get_dt(&irqr));
      }
      

    But this behaves the same as before.

    I looked through build/zephyr/zephyr.dts but don't see any other device that uses P0.10.

Children
No Data
Related