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

nrf51822EK on kit button triggering

I have burnt ble-app-multilink peripheral code on my nrf51822ek. What happens currently is dat when i press button on kit, on kit led turns on . when i press it again, it turns off.

I require that when button is in pressed state it, the led should remain on and when it is released it should turn off.

How is this possible ? any sort of help will be appreciated.

  • Hi Mohib

    Since you are using the evaluation kit, my guess is that you are using SDK 6.1.0 or older, since that is still compatible with the nRF51 revision 2, which resides on the evaluation kit.

    For SDK 6.1.0, you can take a look at e.g. the pin_change_int_example, which I think does exactly what you are asking for. It uses GPIOTE directly. However, the example does not implement any de-bounce function, so when pressing the button on the ev-kit, you will occasionally not see the led turn on, because the signal possibly bounces and the led is both turned on and off by a single button press.

    The app_button library does however implement a de-bounce function. The debounce function of app_button is very simple

    • When a button is pressed, a timer is started
    • when the timer expires, button state is read and an event to the application is given with the state of the button
    • same is done when a button is released as when button is pressed

    You can see an example how app_button library is used by looking at the ble_app_bsp example which is set up with softdevice. The steps required to include a button function is:

    • include the app_button library in your project
    • The app_button library uses both app_timer and app_gpiote libraries, so you need to initialize those before initializing app_button library in a similar way as done in the ble_app_bps example with call to the APP_TIMER_INIT and APP_GPIOTE_INIT macros
    • Create app_button array, as done in button_init() function in the ble_app_bps example
    • Create button handler, as done with button_event_handler in the ble_app_bps example. The app_button_handler will fire both when you press the button and release the button. Read what button state triggered the handler by reading button_action
    • Initialize the button library with call to APP_BUTTON_INIT macro. There you define with BUTTON_DETECTION_DELAY how long time should elapse from the button press until reading the button state and give event to the application
    • Enable buttons with call to app_button_enable(), which is done in ble_app_bps when BLE connection has been established, but you could also do it right away after calling APP_BUTTON_INIT
    • You may need to increase the APP_TIMER_MAX_TIMERS constant since the button library uses one app_timer per button.

    For more advanced de-bounce function than app_button implements, you can look at the debouncer_example in nRF51 SDK 6.1.0. It implements so-called integrator debouncer. The method is fairly simple and its basics are explained on this link and the method is best explained with the following:

    real signal 0000111111110000000111111100000000011111111110000000000111111100000
    corrupted   0100111011011001000011011010001001011100101111000100010111011100010
    integrator  0100123233233212100012123232101001012321212333210100010123233321010
    output      0000001111111111100000001111100000000111111111110000000001111111000
    
  • YOu deserve noble prize for this Stefan. I had the same problem , and now it is solved. Thankyou so much.... :)

Related