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

Using GPIO as button

Hello,

I am trying to understand how to use an external button. In the first stage I am trying to replace the functionality of button0 on the DK with a GPIO.

I took the peripheral\BSP example and made the following changes:

1. pca10056.h:

       I replaced the line:

       #define BUTTON_1       11

       with the following line:

       #define BUTTON_1 NRF_GPIO_PIN_MAP(1, 3)

2. main.c:

      Added the lines:

     #define newPin NRF_GPIO_PIN_MAP(1, 3)

     nrf_gpio_cfg_input(newPin, NRF_GPIO_PIN_PULLUP);

I expected that whenever I connect the 5V on the board to pin 1.3, the button press event will fire. But it doesn't.

Any advice?

Parents Reply
  • Hi, 

    I tested with the changes he posted in DevZone, it is working fine. I get a BSP_EVENT_KEY_4 event when I connect P1.06 to GND (We tested in this way because we don't have an external button). I did not use nrf_gpio_cfg_input(newPin, NRF_GPIO_PIN_PULLUP); in main. I do not see what good that should do, but he BSP library will configure the buttons correctly. 

    -Amanda H

Children
No Data
Related