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

Button interrupt , gpiote

HEllo;
I'm working with nrf52832 and sdk15 , and for interrupt button i chose to work with the example "/nRF5_SDK_15.0.0_a53641a/examples/peripheral/pin_change_int/"
, so my question is how we can know its pushed button(push the button two time)  and long press.
and how we can add : three configuration nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(true);/and LOTOHI and toggle , all together. thank you for your help .
and what about consume of the energy is it better to work wirh nrf_gpio_pin_read(30) or this methode of interupt.

  • I would like to ask why you don't use the solution already provided in this thread?

    I think its not simple as i did, and its based on DK other wise Im using a custom borad. I'll use timer in my application (based on ble_hrs example)

  • I am sorry for the delay, I have been quite busy lately. I am currently looking into your problem and will provide you with an answer asap.

    Best regards,

    Simon

  • Hello SImon I just want to remember you of answering me if you d like of course

  • achraf said:
    I think its not simple as i did

     I think it should be quite straightforward:

    • First you call call timers_init() and buttons_init() in main()
      • timers_init() will simply initialize application timer (read more about it here)
      • buttons_init() will initialize the buttons and start the timer.
        • It will implement a button callback that starts when button 1 is pressed
        • It will implement a timeout handler, that will trigger rapid and continuously after the button is pressed, that checks whether a long or short button press occurred (based on value of cnt)
    • You can ignore most of the other code present (except for power management, some includes and defines)

     If anything is unclear, or if you would like me to explain anything in detail, please ask.

    achraf said:
    its based on DK other wise Im using a custom borad

     I think the solution should work with a custom board as well. Why do you think that matters?


    Some other comments about your solution:

    • Since you are putting the code in a loop, it is hard to know the duration of respectively a long and a short button press. In the timer-based method, you will.
    • The solution will consume a lot of power since you are constantly polling and the CPU will always run, even when calling nrf_delay_ms() a lot of current will be drawn.
      • In the timer-based method, you can put the CPU in sleep, between the increments of the counter variable cnt

    Best regards,

    Simon

Related