This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pin P0.00 as a button input not working as GPIO but P0.01 does. Already switched all LFCLKSRC to RC.

Board: NRF52840

SDK: 16

Soft Device: s113

So our board is custom and does not contain a crystal. We are treating P0.00 and P0.01 as GPIOs for button inputs. P0.01 works fine but P0.00 does not work and no events are produced despite both being programmed the exact same way.  

I understand that those pins are reserved as crystal pins and according to other posts in this forum you should switch all LFCLKSRC to RC when you want to use them as GPIO. This has been done and does not fix the issue. In addition there are no NULL values in the pin configuration. The EE tested the voltage and found that it is oscillating between hi and low when the button is not pressed. Below is how the pins are configured with BSP_BUTTON_0 being the button not working correctly: 

static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
{
    #ifdef BSP_BUTTON_0
    {BSP_BUTTON_0, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_0

    #ifdef BSP_BUTTON_1
    {BSP_BUTTON_1, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_1

    #ifdef BSP_BUTTON_2
    {BSP_BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, bsp_button_event_handler},
    #endif // BUTTON_2

    #ifdef BSP_BUTTON_3
    {BSP_BUTTON_3, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_3

    #ifdef BSP_BUTTON_4
    {BSP_BUTTON_4, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_4

    #ifdef BSP_BUTTON_5
    {BSP_BUTTON_5, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_5

    #ifdef BSP_BUTTON_6
    {BSP_BUTTON_6, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_6

    #ifdef BSP_BUTTON_7
    {BSP_BUTTON_7, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_7

    #ifdef BSP_BUTTON_8
    {BSP_BUTTON_8, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_8

    #ifdef BSP_BUTTON_9
    {BSP_BUTTON_9, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_NOPULL, bsp_button_event_handler},
    #endif // BUTTON_9
};

Given this information, any information that could solve this issue with the button not working?    

  • Hey so I ended up figuring out what was wrong and it is definitely something I didn't expect. Everything for buttons was actually coded correctly. There was a function in boards.c to configure the LEDs that was being used incorrectly. The code below shows the issue. 

    In custom_board.h:

    #define LEDS_LIST { }

    #define LEDS_NUMBER    8

    In boards.c:

    static const uint8_t m_board_led_list[LEDS_NUMBER] = LEDS_LIST;

     

    void bsp_board_init(uint32_t init_flags)
    {
        #if defined(BOARDS_WITH_USB_DFU_TRIGGER) && defined(BOARD_PCA10059)
        (void) nrf_dfu_trigger_usb_init();
        #endif
    
        #if LEDS_NUMBER > 0
        if (init_flags & BSP_INIT_LEDS)
        {
            bsp_board_leds_init();
        }
        #endif //LEDS_NUMBER > 0
    
        #if BUTTONS_NUMBER > 0
        if (init_flags & BSP_INIT_BUTTONS)
        {
            bsp_board_buttons_init();
        }
        #endif //BUTTONS_NUMBER > 0
    }

    static void bsp_board_leds_init(void)
    {
        #if defined(BOARD_PCA10059)
        // If nRF52 USB Dongle is powered from USB (high voltage mode),
        // GPIO output voltage is set to 1.8 V by default, which is not
        // enough to turn on green and blue LEDs. Therefore, GPIO voltage
        // needs to be increased to 3.0 V by configuring the UICR register.
        if (NRF_POWER->MAINREGSTATUS &
           (POWER_MAINREGSTATUS_MAINREGSTATUS_High << POWER_MAINREGSTATUS_MAINREGSTATUS_Pos))
        {
            gpio_output_voltage_setup();
        }
        #endif
    
        uint32_t i;
        for (i = 0; i < LEDS_NUMBER; ++i)
        {
            nrf_gpio_cfg_output(m_board_led_list[i]);
        }
        bsp_board_leds_off();
    }

    So function call goes bsp_board_init() -> bsp_board_leds_init(). Within that last function, the for loop is trying to loop through nothing as you can see in custom_board.h the #define LED_LIST {} is empty. Not sure why it affected the button but once I commented out the bsp_board_leds_init(); function, the button worked as intended. Thanks for all the help. 

Related