This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

What codes should we change in the sdk example if we send a logic 1 instead of logic 0 to the processor pin when the button is pressed?

I am developing a project on the ble_app_template example. In the sdk(15.3.0) example, when the button is pressed, some cases are executed by going to bsp_event_handler. if the button design is changed on the pcb, for example when the button is pressed, the pin is changed from low to high instead of from high to low, what should I change in the software?

  • Hello,

    I assume you are using the bsp module, since you mention the bsp_event_handler.

    Actually, I suggest that you look into the ble_app_blinky example for inspiration, and it's implementation in buttons_init() in main.c.

    Note that it uses the app_button module instead of the bsp. Bsp actually uses the app_button, but it takes away some functionality, and adds some events from the BLE stack in addition to the buttons and LEDs.

    app_button_init takes an array of buttons. In the blinky example, this is only one button, but you can easily expand it:

        static app_button_cfg_t buttons[] =
        {
            {LEDBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler},
            {ANOTHER_BUTTON, false, BUTTON_PULL, button_event_handler}
        };

    (you can use the same event handler for all the buttons.)

    The second parameter in this button configuration, which is false here, is the active state. False = active low, and high would be active high. 

    By default, BUTTON_PULL is set to NRF_GPIO_PIN_PULLUP in pca10040.h, but you can use whatever pull configuration you want here. If the button is active high, you may want to have pulldown? It depens on the hardware you are using.

    If you still want to use the bsp for this, please see how bsp_init() uses the app_button_init() in bsp.c, and a similar array of the buttons. These buttons are typically defined in pca10040.h, so perhaps you can just modify your custom board file to match your buttons.

Related