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
  • Hello,

    I didn't find any errors in the code you've posted. I also confirmed that it works correctly on my 5340 DK without the need for any additional overlay files.

    Project

    pin_read.zip

    Compiled .hex

    8130.zephyr.hex

    Result

    Could you please try to program the device with the zephyr.hex file above to see if that works? You can use nrfjprog to program it:

    $ nrfjprog --program zephyr.hex --chiperase --verify -r
    

    Note: P0.10 will be assigned to the network core by default if you build for the the 'nrf5340dk_nrf5340_cpuapp' board with a project that enables the network core (nordic,nrf-gpio-forwarder). 

    Best regards,

    Vidar

Reply
  • Hello,

    I didn't find any errors in the code you've posted. I also confirmed that it works correctly on my 5340 DK without the need for any additional overlay files.

    Project

    pin_read.zip

    Compiled .hex

    8130.zephyr.hex

    Result

    Could you please try to program the device with the zephyr.hex file above to see if that works? You can use nrfjprog to program it:

    $ nrfjprog --program zephyr.hex --chiperase --verify -r
    

    Note: P0.10 will be assigned to the network core by default if you build for the the 'nrf5340dk_nrf5340_cpuapp' board with a project that enables the network core (nordic,nrf-gpio-forwarder). 

    Best regards,

    Vidar

Children
Related