GPIO conflict

I have a nRF9160DK board that is used for development of a custom nRF9160 board. The hardware designers have assigned GPIO P0.27 to be a general purpose output pin. This pin is also used as uart0_cts. when I try to toggle this pin with a simple test it does not work with the code shown below. If I use another pin such as P0.23 the pin toggles fine. I am assuming there is a pin conflict by assigning 2 things to the same pin. The boards are already manufactured with P0.27 as a general purpose output control pin. How can I get this to work? Is there something in the overlay file I need to add or remove?

    int test = 0;
    while(1)
    {
        printf("test GPIO BAT_MON_EN %d\r\n",test & 0x01);
        /* toggle test */

        /* set/clear test */
        if(test++ & 0x01)
        {
//          printf("set\r\n");
            gpio_pin_set(bat_mon_en_dev, BAT_MON_EN_DEV_PIN, 1);
        }
        else
        {
//          printf("clear\r\n");
            gpio_pin_set(bat_mon_en_dev, BAT_MON_EN_DEV_PIN, 0);
        }
        k_sleep(K_MSEC(1000));
    }
  • Hello,

    Is it possible to upload the entire project, or a strip-down project that can replicate the issue that you are seeing? Then I can poke around and see if I can figure out why this pin is not controllable by the application.

    Best regards,

    Edvin

  • Edvin

    thanks for the quick response. If I gave you the project it would only work on our custom board. am I disabling the pins from UART0 and reenabling P0.27 to be used for our custom board properly in the overlay file? all the other GPIO pins work properly.

  • Timothy said:
    all the other GPIO pins work properly

    All others?

    What about the other GPIOs originally used by the uart0? Have you tried to change the GPIOs of uart0 directly in the .dts file? Just for debugging purposes? This will tell you whether it is the uart that is still holding the gpio, or if it is being set somewhere else.

    Also, try to debug, and look at the GPIOs config register. What does it say? We can use this to determine whether the pin is set as an input or output. What does it say if you don't try to use it? Perhaps that can give a hint of what the pin is used for.

    BR,
    Edvin

  • Edvin

    this is my setup for output GPIOs. all others work just a problem with BAT_MON_EN. The overlay file was given earlier.

    /* outputs */
    #define SW2CTRL_DEV_NODE            DT_GPIO_CTLR(DT_ALIAS(sw2ctrl), gpios)
    #define SW2CTRL_DEV_PIN             DT_GPIO_PIN(DT_ALIAS(sw2ctrl), gpios)
    #define SW2CTRL_DEV_PIN_DTS_FLAGS   DT_GPIO_FLAGS(DT_ALIAS(sw2ctrl), gpios)

    #define CS2N_DEV_NODE            DT_GPIO_CTLR(DT_ALIAS(spi_cs2n), gpios)
    #define CS2N_DEV_PIN             DT_GPIO_PIN(DT_ALIAS(spi_cs2n), gpios)
    #define CS2N_DEV_PIN_DTS_FLAGS   DT_GPIO_FLAGS(DT_ALIAS(spi_cs2n), gpios)

    #define CS3N_DEV_NODE            DT_GPIO_CTLR(DT_ALIAS(spi_cs3n), gpios)
    #define CS3N_DEV_PIN             DT_GPIO_PIN(DT_ALIAS(spi_cs3n), gpios)
    #define CS3N_DEV_PIN_DTS_FLAGS   DT_GPIO_FLAGS(DT_ALIAS(spi_cs3n), gpios)

    #define BAT_MON_EN_DEV_NODE            DT_GPIO_CTLR(DT_ALIAS(batmonen), gpios)
    #define BAT_MON_EN_DEV_PIN             DT_GPIO_PIN(DT_ALIAS(batmonen), gpios)
    #define BAT_MON_EN_DEV_PIN_DTS_FLAGS   DT_GPIO_FLAGS(DT_ALIAS(batmonen), gpios)

    const struct device *sw2ctrl_dev = DEVICE_DT_GET(SW2CTRL_DEV_NODE);
    const struct device *spi2_csn_dev = DEVICE_DT_GET(CS2N_DEV_NODE);
    const struct device *spi3_csn_dev = DEVICE_DT_GET(CS3N_DEV_NODE);
    const struct device *bat_mon_en_dev = DEVICE_DT_GET(BAT_MON_EN_DEV_NODE);

        /* set up BAT_MON_EN as output/pullup */
        if (!device_is_ready(bat_mon_en_dev))
        {
            myPrintfW("BAT MON EN device is not ready\r\n");
        }
        else
            myPrintfS("BAT MON EN device is ready\r\n");
        gpio_pin_configure(bat_mon_en_dev, BAT_MON_EN_DEV_PIN, GPIO_OUTPUT | GPIO_PULL_UP);
        gpio_pin_set(bat_mon_en_dev, BAT_MON_EN_DEV_PIN, 1);
  • Edvin

    I have it working as shown below. I changed Pin 27 to Pin 23 (an unused pin on custom board) in the file C:\Nordic1\v2.5.0\zephyr\boards\arm\nrf9160dk_nrf9160\nrf9160dk_nrf9160_common-pinctrl.dtsi.

    so it definitely is uart0 messing up pin 27. any idea what is going on?

    I should have taken care of this in my overlay file. It does remove uart0 and redefine it without Pin 26/27. 

    I can live with this change if I have to but I really did not want to alter any V2.5.0 files at all.

    > batmon 0
    batmon 0
    Battery Monitor: 0 Disabled
    > adc
    adc
    BAT: 0.12 V ADC: 2.85 V
    > batmon 1
    batmon 1
    Battery Monitor: 1 Enabled
    > adc
    adc
    BAT: 3.31 V ADC: 2.84 V
Related