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

GPIO Interrupt with BLE peripheral code

Hi, I am currently testing some BLE sample code (the proximity code and hrs code) with the nRF52840 PDK and I am trying to just simply interface the GPIO interrupt example (pin_change_int) with either of these. I found this post (https://devzone.nordicsemi.com/f/nordic-q-a/19804/gpio-interrupt-with-proximitty-example) where it looks like they were doing something similar.  All I did was copy the functions from the main.c of pin_change_int example to the main.c of the proximity example, added in the #defines for the LED and BUTTON, and put in the missing #includes. When I run this, it always stops execution in the app_error.weak.c at NRF_BREAKPOINT_COND;. From the other post I guess I am initializing GPIOTE a second time (the first being in buttons_leds_init() and the second being in the gpio_init() function that I added from the interrupt example), but I don't see how I should implement the suggested function  nrf_drv_gpiote_is_init() to fix my problem. What part of the code would I put this in? I apologize if this is a really simple question, I'm very new to this all. Thanks.

  • When trying to integrate the pin_change_int example with the ble_app_proximity example I got the same error as you (running both gpio_init() and buttons_leds_init(&erase_bonds)). However, in my case using sdk 15 and the ble_app_proximity example the function nrf_drv_gpiote_is_init() is already implemented inside buttons_leds_init(..) --> bsp_init(..) --> app_button_init(..).

    But the error still remains, and after debugging, it is due to calling nrf_drv_gpiote_in_init(..) two times:

    In the ble_app_proximity example:

    • It is called inside buttons_leds_init(..)bsp_init(..)app_button_init(..)nrf_drv_gpiote_in_init(..)
    • Button 1 to 4 is initialized using low accuracy and the sense feature

    In the pin_change_init example:

    • It is called inside gpio_init()nrf_drv_gpiote_in_init(..)
    • Here button 1 is initialized using high accuracy and IN_EVENT is enabled

    The problem is that button 1 is used by both of the examples.

    I solved it by defining PIN_IN and PIN_OUT to respectively button 3 and led 3, then the pin_change_int functionality be changed to control LED 4 with button 4.

    Then I changed the definition of BUTTONS_NUMBER from 4 to 3, inside pca10056.h (It might be smart to make a copy of the edited file, in case you will use this header file in other projects), then the buttons_leds_init() function will only initialize button 1 to 3. The ble app_proximity will still work as expected, since it only uses button 1 and 2 (according to function bsp_event_handler(..)).

    Remember to call gpio_init() first, if not you have to swap these lines (inside gpio_init):

    err_code = nrf_drv_gpiote_init();
    APP_ERROR_CHECK(err_code);

    with these lines:

    if (!nrf_drv_gpiote_is_init())
        {
            err_code = nrf_drv_gpiote_init();
            VERIFY_SUCCESS(err_code);
        }

    Best regards Simon

  • Thank you for thoroughly explaining this. 

Related