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

Struggeling combining ble_app_gatts and gpiote

I’m in the process of learning the nRF52, and tries to combine the ble_app_gatts and the  pin_change_int examples (using nRF52 DK, SDK 15.3 SES projects on a Win7 machine).
In the SDK 15.3 ble_app_gatts project I have included the "nrf_drv_gpiote.h" and the following code for the init and the pin_handler:

#define PIN_OUT   LED_4
#define PIN_IN    BUTTON_4

void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
{
    nrf_drv_gpiote_out_toggle(PIN_OUT);
    NRF_LOG_INFO("IRQ received.");
}
/**
 * @brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output,
 * and configures GPIOTE to give an interrupt on pin change.
 */
static void gpio_init(void)
{
    ret_code_t err_code;
    if(!nrf_drv_gpiote_is_init())
    {
      err_code = nrf_drv_gpiote_init();
      APP_ERROR_CHECK(err_code);
    }

    nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(false);

    err_code = nrf_drv_gpiote_out_init(PIN_OUT, &out_config);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    in_config.pull = NRF_GPIO_PIN_PULLUP;

    err_code = nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);
    APP_ERROR_CHECK(err_code);

    nrf_drv_gpiote_in_event_enable(PIN_IN, true);
}

The gpio_init() is called at the end of the modules_init():

static void modules_init(void)
{
    log_init();
    leds_init();
    timers_init();
    buttons_leds_init(&m_erase_bonds);
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    db_discovery_init();
    services_init();
    advertising_init();
    peer_manager_init();
    gpio_init();
}

However, when running the program, it terminates in the nrf_drv_gpiote_in_init(PIN_IN, &in_config, in_pin_handler);, telling that the pin is in use by gpiote.

I have also tried using pin 43, with the same result.

What am I missing/doing wrong?

Thanks.

Parents
  • Hi,

    You get the error because you are trying to configure the same pin twice.

    The Board Support Package (BSP) is a higher level library that configures GPIO pins for buttons and LED'S. It also handle things like debouncing buttons an mapping them to events, and signalling various states with LED's blinking etc. Since this use GPIO pins it will conflict if you try to use the same pin for another purpose. If you want to test GPIO interrupts from the pin_change_int example within an example that use BSP, the simplest is to use a pin which is not associated with a button or LED, as this will then not conflict with BSP.

    Regarding the BSP_INIT_LEDS and BSP_INIT_BUTTONS, you can see that these are bit wise OR'ed as flags when you call bsp_init(). So if you for instance only want to configure LEDs but not buttons, then you modify the call to be like this (and vise versa if you only want buttons):

    err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);

  •  "... the simplest is to use a pin which is not associated with a button or LED, as this will then not conflict with BSP."  As I stated in the OP, I tried this using "pin 43" with the same result. However, "pin 43" is the physical pin number. Changing to  gpio pin 31 (which is the physical pin 43), it worked like you described. Thanks. 

Reply Children
Related