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

long-push button not work when nrf52832 is advertising

Hi:

I'm using SDK V17 & encounter a problem.

in my project, the nRF52832 doesn't broadcast at all.

Once the button1(EVK btn1) is pressed and lasting 5 seconds, 

nRF52832 starts broadcasting.

----------------------------------

The issue is

Once press the button1 with 5 seconds,   the "void bsp_event_handler(bsp_event_t event)" is not invoked.

And check function "bsp_button_event_handler" bsp.c in  SDK_Files\components\libraries\bsp\,

the cases, "APP_BUTTON_PUSH" & "BSP_BUTTON_ACTION_LONG_PUSH" of button_action" are executed in turn,

and even checked the statement " m_registered_callback(event);" is executed,

but  "void bsp_event_handler(bsp_event_t event)" is not executed at this case.

Can somebody help? 

Parents
  • Hi 

    If I understand you correctly the long push on button 1 is working fine the first time, but after you start advertising it will never work again?

    Can you show me the code you use to initialize the BSP library, and the handler where you start the advertising?

    Also, did you use one of the existing SDK examples as a starting point?

    Best regards
    Torbjørn

  • I tried some more,

    Actually, the broadcast starts, then the "void bsp_event_handler(bsp_event_t event)"  won't be invoked.

    My project starts from the "ble_app_uart" example.

    The following  are partial of my code,

    Let me what the more you want if necessary

    And thanks

    =====================================================================

    static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        bsp_event_t event = BSP_EVENT_NOTHING;
        uint32_t button = 0;
        uint32_t err_code;
        static uint8_t current_long_push_pin_no; /**< Pin number of a currently pushed button, that could become a long push if held long enough. */
        static bsp_event_t release_event_at_push[BUTTONS_NUMBER]; /**< Array of what the release event of each button was last time it was pushed, so that no release event is sent if the event was bound after the push of the button. */

        button = bsp_board_pin_to_button_idx(pin_no);

        if (button < BUTTONS_NUMBER)
        {
            switch (button_action)
            {
                case APP_BUTTON_PUSH:
                         printf("%s[%d]::APP_BUTTON_PUSH\r\n",__FUNCTION__,__LINE__);
                        event = m_events_list[button].push_event;
                       if (m_events_list[button].long_push_event != BSP_EVENT_NOTHING)
                       {
                               err_code = app_timer_start(m_bsp_button_tmr, APP_TIMER_TICKS(BSP_LONG_PUSH_TIMEOUT_MS), (void*)&current_long_push_pin_no);
                             if (err_code == NRF_SUCCESS)
                              {
                                      current_long_push_pin_no = pin_no;
                              }
                         }
                         release_event_at_push[button] = m_events_list[button].release_event;
                        break;
                        case APP_BUTTON_RELEASE:
                                     (void)app_timer_stop(m_bsp_button_tmr);
                                   if (release_event_at_push[button] == m_events_list[button].release_event)
                                   {
                                          event = m_events_list[button].release_event;
                                   }
                            break;
                           case BSP_BUTTON_ACTION_LONG_PUSH:
                                 printf("%s[%d]::BSP_BUTTON_ACTION_LONG_PUSH\r\n",__FUNCTION__,__LINE__);
                                event = m_events_list[button].long_push_event;
                                   }
                       }

             if ((event != BSP_EVENT_NOTHING) && (m_registered_callback != NULL))
             {
                    printf("%s[%d]::CallBack\r\n",__FUNCTION__,__LINE__);
                         m_registered_callback(event);
               }
    }

    ==========================================================

    void bsp_event_handler(bsp_event_t event)
    {
        U32 err_code;
        switch (event)
        {

            case BSP_EVENT_KEY_RELEASE:
            break;

            case BSP_EVENT_KEY_LONG_PUSH:
                 printf("BSP_EVENT_KEY_LONG_PUSH\r\n");
                 printf("\r\n\r\n");
    break;
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Reply
  • I tried some more,

    Actually, the broadcast starts, then the "void bsp_event_handler(bsp_event_t event)"  won't be invoked.

    My project starts from the "ble_app_uart" example.

    The following  are partial of my code,

    Let me what the more you want if necessary

    And thanks

    =====================================================================

    static void bsp_button_event_handler(uint8_t pin_no, uint8_t button_action)
    {
        bsp_event_t event = BSP_EVENT_NOTHING;
        uint32_t button = 0;
        uint32_t err_code;
        static uint8_t current_long_push_pin_no; /**< Pin number of a currently pushed button, that could become a long push if held long enough. */
        static bsp_event_t release_event_at_push[BUTTONS_NUMBER]; /**< Array of what the release event of each button was last time it was pushed, so that no release event is sent if the event was bound after the push of the button. */

        button = bsp_board_pin_to_button_idx(pin_no);

        if (button < BUTTONS_NUMBER)
        {
            switch (button_action)
            {
                case APP_BUTTON_PUSH:
                         printf("%s[%d]::APP_BUTTON_PUSH\r\n",__FUNCTION__,__LINE__);
                        event = m_events_list[button].push_event;
                       if (m_events_list[button].long_push_event != BSP_EVENT_NOTHING)
                       {
                               err_code = app_timer_start(m_bsp_button_tmr, APP_TIMER_TICKS(BSP_LONG_PUSH_TIMEOUT_MS), (void*)&current_long_push_pin_no);
                             if (err_code == NRF_SUCCESS)
                              {
                                      current_long_push_pin_no = pin_no;
                              }
                         }
                         release_event_at_push[button] = m_events_list[button].release_event;
                        break;
                        case APP_BUTTON_RELEASE:
                                     (void)app_timer_stop(m_bsp_button_tmr);
                                   if (release_event_at_push[button] == m_events_list[button].release_event)
                                   {
                                          event = m_events_list[button].release_event;
                                   }
                            break;
                           case BSP_BUTTON_ACTION_LONG_PUSH:
                                 printf("%s[%d]::BSP_BUTTON_ACTION_LONG_PUSH\r\n",__FUNCTION__,__LINE__);
                                event = m_events_list[button].long_push_event;
                                   }
                       }

             if ((event != BSP_EVENT_NOTHING) && (m_registered_callback != NULL))
             {
                    printf("%s[%d]::CallBack\r\n",__FUNCTION__,__LINE__);
                         m_registered_callback(event);
               }
    }

    ==========================================================

    void bsp_event_handler(bsp_event_t event)
    {
        U32 err_code;
        switch (event)
        {

            case BSP_EVENT_KEY_RELEASE:
            break;

            case BSP_EVENT_KEY_LONG_PUSH:
                 printf("BSP_EVENT_KEY_LONG_PUSH\r\n");
                 printf("\r\n\r\n");
    break;
    // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Children
No Data
Related