Unable to read any GPIO input with nRF Connect SDK, but all GPIO output works

Hi all,

i am really desperate. since more than 1 week i am trying to work with the digital inputs in my custom pcb.

I can set all digital outputs, but from the inputs I always get the same level (low level). It doesn't matter if I try to read a single pin with gpio_pin_get_raw() or if I read the whole port at once with gpio_port_get_raw() instead.

I already found several other requests here in devzone for similiar problems, but none of them helped me.

This is my .dts file of my board:

ol0119v4.dts

And this is the .dts file what finally comes out after building:

0675.zephyr.dts

When i initialize the GPIO, i do the following:

/*  Definition of pin numbers for the GPIO  */
#define OL0119G3_LEDEN_PIN      3
#define OL0119G3_ENACO2_PIN     4
#define OL0119G3_CO2RDY_PIN     10
    /*  Configure and start the GPIO                    */
    pstrGPIO = device_get_binding("GPIO_0");
    if (pstrGPIO == NULL) {
        printk("Failed to find the port GPIO_0\n");
        err++;
    }
    else if (!device_is_ready(pstrGPIO))
    {
        printk("GPIO_0 device is not ready\n");
        err++;
    }    
    else
    {
        /*  The GPIO must also be configured individually for each pin  */
        if( (iDummy=gpio_pin_configure(pstrGPIO, OL0119G3_LEDEN_PIN, GPIO_OUTPUT_LOW)) != 0)
        {
            printk("gpio_pin_configure failed (err %d)\n", iDummy);
            err++;
        }

        if( (iDummy=gpio_pin_configure(pstrGPIO, OL0119G3_ENACO2_PIN, GPIO_OUTPUT_LOW)) != 0)
        {
            printk("gpio_pin_configure failed (err %d)\n", iDummy);
            err++;
        }

        if( (iDummy=gpio_pin_configure(pstrGPIO, OL0119G3_CO2RDY_PIN, GPIO_INPUT)) != 0)
        {
            printk("gpio_pin_configure failed (err %d)\n", iDummy);
            err++;
        }
    }

When i try to read the input pin OL0119G3_CO2RDY_PIN i do the following:

if( (iDummy = gpio_pin_get_raw(pstrGPIO, OL0119G3_CO2RDY_PIN)) < 0)

and expect iDummy to show the actual state....but it is always low

If i use

if( (iDummy = gpio_port_get_raw(pstrGPIO, &uiPortState)) < 0)

then i expect that current state of all pins within the port. And in fact - the digital output pins are correct, however all digital inputs are still low.

I have no more idea and even more important - i have a customer on my back who can no longer wait

Ah - my prj.conf is like following:

CONFIG_BT=y
CONFIG_BT_DEBUG_LOG=n
CONFIG_BT_DEVICE_NAME="OL0119G3_V1"

# Config logger, von Ünal hinzugefügt
CONFIG_LOG=n
CONFIG_CONSOLE=y
CONFIG_USE_SEGGER_RTT=y
CONFIG_RTT_CONSOLE=y
CONFIG_UART_CONSOLE=n

# The BLE settings (and others) should be initialized from flash
CONFIG_SETTINGS=y
CONFIG_BT_SETTINGS=n

# Params related to UART
CONFIG_UART_INTERRUPT_DRIVEN=y

# Params related to I2C
CONFIG_I2C=y

# Some system settings
CONFIG_MPU_ALLOW_FLASH_WRITE=y
CONFIG_FPU=y
CONFIG_FPU_SHARING=y
CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
CONFIG_NEWLIB_LIBC_FLOAT_SCANF=y
CONFIG_MAIN_STACK_SIZE=1024
CONFIG_MPSL_SIGNAL_STACK_SIZE=1024
CONFIG_PRIVILEGED_STACK_SIZE=1024
CONFIG_IDLE_STACK_SIZE=512

# Some settings regarding the buil
CONFIG_NO_OPTIMIZATIONS=y



any help is welcome, i have no idea anymore

Best regards

Parents
  • Hi,

    Are the input pins used for something else? You mention using a custom pcb, but I see in the devicetree file that it is compatible with nRF52 DK. As you can see in Connector interface in the specification for nRF52 DK, P0.10 is by default used for NFC2, so it might be unavailable to your application.

    Are any of the the input pins active low? You should be aware that the raw GPIO functions ignores the GPIO_ACTIVE_LOW flag, so gpio_pin_get_raw() will return 1 if the physical level is high, regardless of whether the pin is active high or active low. The function gpio_pin_get() on the other hand, will return 1 if the pin is active.

    Best regards,

    Marte

  • Dear Marte,

    sorry, i forgot another question: how do i get P0.10 free for my application? I do not need the NFC interface.

    Best regards,

    Ünal

  • Hi Ünal,

    uenal said:
    how do i get P0.10 free for my application?

    You can disable NFC as GPIO with the configuration CONFIG_NFCT_PINS_AS_GPIOS. For the nRF52 DK you will have to place resistors mounted on R25/R26 to R27/R28, as explained here: nRF52 DK > NFC antenna interface.

    uenal said:

    The following port pins in our design are digital input and none of them is visible, at least not by reading the hole port with  gpio_port_get_raw().

    P0.25, P0.27, P0.31, P0.10

    Is this only when you read the entire port, or also when you read a single pin with gpio_pin_get_raw()? How are you checking the value of the pins after reading them with this function? As stated in the documentation:

    Value of a pin with index n will be represented by bit n in the returned port value.

    uenal said:
    If some pin is used for something else, then it can not be read, even from the hole port?

    If a pin is used for something else, then it is unavailable as a GPIO. 

    uenal said:
    I already had the idea to use the origiinal devicetree of the nRF52dk and adopt it by an overlay file. However, i'm not sure how and what to do there especially regarding the gpio. That seems to be dfferent from standard peripherals. Do you have some good reading for that?

    You can find information and guides regarding devicetree overlays in the Zephyr documetnation, such as in Introduction to devicetree and Devicetree HOWTOs. You can also read about it in nRF Connect SDK Tutorial - Part 3. This tutorial has not been updated since nRF Connect SDK v1.5.0, so some of the information might be out of date, but you will find explanations of overlay files, device binding, and board files there.

    I tested the GPIO part of your devicetree file, but I did so using nRF52 DK as board and created an overlay file with only gpio_keys:

    / {
        gpio_keys {
            compatible = "gpio-keys";
            dio2: dio_2{
                label = "Switch Position";
                gpios = <&gpio0 25 0>;
            };
            dio4: dio_4{
                label = "Wall Power";
                gpios = <&gpio0 27 GPIO_PULL_UP>;
            };
            dio7: dio_7{
                label = "AIN Switched GND";
                gpios = <&gpio0 30 (GPIO_OPEN_DRAIN | GPIO_PULL_DOWN)>;
            };
            dio8: dio_8{
                label = "Charge";
                gpios = <&gpio0 31 GPIO_PULL_UP>;
            };
            dio16: dio_16{
                label = "LEDEN";
                gpios = <&gpio0 3 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio17: dio_17{
                label = "EnaCO2";
                gpios = <&gpio0 4 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio23: dio_23{
                label = "CO2RDY";
                gpios = <&gpio0 10 0>;
            };
            dio29: dio_29{
                label = "DEBUG P2";
                gpios = <&gpio0 15 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio30: dio_30{
                label = "DEBUG P1";
                gpios = <&gpio0 16 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio32: dio_32{
                label = "SWO";
                gpios = <&gpio0 18 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
        };
    };

    Here I directly copied gpio_keys from your file, but it shows an example of how you can use an overlay file for GPIOs. If you plan to use pins that are already used by something else in the board's devicetree file, you can disable it in your overlay file by setting the status to "disabled". For example if you want to use pins that are already used by spi1 you can disable spi1 by adding the following to the overlay file:

    &spi1 {
        status = "disabled";
    };

    There are multiple ways to set your devicetree overlay file, see Set devicetree overlays. I sat it in CMakeLists.txt like this:

    set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_LIST_DIR}/boards/nrf52dk_nrf52832.overlay")

    Best regards,

    Marte

Reply
  • Hi Ünal,

    uenal said:
    how do i get P0.10 free for my application?

    You can disable NFC as GPIO with the configuration CONFIG_NFCT_PINS_AS_GPIOS. For the nRF52 DK you will have to place resistors mounted on R25/R26 to R27/R28, as explained here: nRF52 DK > NFC antenna interface.

    uenal said:

    The following port pins in our design are digital input and none of them is visible, at least not by reading the hole port with  gpio_port_get_raw().

    P0.25, P0.27, P0.31, P0.10

    Is this only when you read the entire port, or also when you read a single pin with gpio_pin_get_raw()? How are you checking the value of the pins after reading them with this function? As stated in the documentation:

    Value of a pin with index n will be represented by bit n in the returned port value.

    uenal said:
    If some pin is used for something else, then it can not be read, even from the hole port?

    If a pin is used for something else, then it is unavailable as a GPIO. 

    uenal said:
    I already had the idea to use the origiinal devicetree of the nRF52dk and adopt it by an overlay file. However, i'm not sure how and what to do there especially regarding the gpio. That seems to be dfferent from standard peripherals. Do you have some good reading for that?

    You can find information and guides regarding devicetree overlays in the Zephyr documetnation, such as in Introduction to devicetree and Devicetree HOWTOs. You can also read about it in nRF Connect SDK Tutorial - Part 3. This tutorial has not been updated since nRF Connect SDK v1.5.0, so some of the information might be out of date, but you will find explanations of overlay files, device binding, and board files there.

    I tested the GPIO part of your devicetree file, but I did so using nRF52 DK as board and created an overlay file with only gpio_keys:

    / {
        gpio_keys {
            compatible = "gpio-keys";
            dio2: dio_2{
                label = "Switch Position";
                gpios = <&gpio0 25 0>;
            };
            dio4: dio_4{
                label = "Wall Power";
                gpios = <&gpio0 27 GPIO_PULL_UP>;
            };
            dio7: dio_7{
                label = "AIN Switched GND";
                gpios = <&gpio0 30 (GPIO_OPEN_DRAIN | GPIO_PULL_DOWN)>;
            };
            dio8: dio_8{
                label = "Charge";
                gpios = <&gpio0 31 GPIO_PULL_UP>;
            };
            dio16: dio_16{
                label = "LEDEN";
                gpios = <&gpio0 3 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio17: dio_17{
                label = "EnaCO2";
                gpios = <&gpio0 4 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio23: dio_23{
                label = "CO2RDY";
                gpios = <&gpio0 10 0>;
            };
            dio29: dio_29{
                label = "DEBUG P2";
                gpios = <&gpio0 15 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio30: dio_30{
                label = "DEBUG P1";
                gpios = <&gpio0 16 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
            dio32: dio_32{
                label = "SWO";
                gpios = <&gpio0 18 (GPIO_PUSH_PULL | GPIO_ACTIVE_LOW)>;
            };
        };
    };

    Here I directly copied gpio_keys from your file, but it shows an example of how you can use an overlay file for GPIOs. If you plan to use pins that are already used by something else in the board's devicetree file, you can disable it in your overlay file by setting the status to "disabled". For example if you want to use pins that are already used by spi1 you can disable spi1 by adding the following to the overlay file:

    &spi1 {
        status = "disabled";
    };

    There are multiple ways to set your devicetree overlay file, see Set devicetree overlays. I sat it in CMakeLists.txt like this:

    set(DTC_OVERLAY_FILE "${CMAKE_CURRENT_LIST_DIR}/boards/nrf52dk_nrf52832.overlay")

    Best regards,

    Marte

Children
No Data
Related