When entering a key, multiple events occur at once.

hi.

I am testing by making a custum board with nRF52832.

In the process of debugging, when a key is entered, a number of key events occur, so I have a question.

The GPIO modification was done as follows.

#define BUTTONS_NUMBER        5

#define BUTTON_START          27
#define BUTTON_1              27
#define BUTTON_2              28
#define BUTTON_3              29
#define BUTTON_4              30
#define BUTTON_5              31
#define BUTTON_STOP           31

//#define BUTTON_PULL         NRF_GPIO_PIN_PULLUP
#define BUTTON_PULL         NRF_GPIO_PIN_PULLDOWN

//#define BUTTONS_ACTIVE_STATE 0
#define BUTTONS_ACTIVE_STATE 1

#define BUTTONS_LIST     { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5 }

#define BSP_BUTTON_0   BUTTON_1
#define BSP_BUTTON_1   BUTTON_2
#define BSP_BUTTON_2   BUTTON_3
#define BSP_BUTTON_3   BUTTON_4
#define BSP_BUTTON_4   BUTTON_5

The key envet through GPIO is configured to be confirmed with printf as follows.

/**@brief Function for handling events from the BSP module.
 *
 * @param[in]   event   Event generated by button press.
 */
void bsp_event_handler(bsp_event_t event)
{
    uint32_t err_code;
    uint8_t reason;
    switch (event)
    {
        case BSP_EVENT_SLEEP:

            printf("> BSP_EVENT_SLEEP\r\n");
            sleep_mode_enter();
            break;
        
      
        case BSP_EVENT_DISCONNECT:

            reason = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
            printf("> BSP_EVENT_DISCON : %x Reconn..\r\n", reason);
            err_code = sd_ble_gap_disconnect(m_conn_handle, reason);
           
            if (err_code != NRF_ERROR_INVALID_STATE)
            {
                APP_ERROR_CHECK(err_code);
            }
            

            break;


        case BSP_EVENT_WHITELIST_OFF:

             printf("> BSP_EVENT_WHITELIST_OFF\r\n");
            if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
            {
                err_code = ble_advertising_restart_without_whitelist(&m_advertising);
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
            }
            break;

        case BSP_EVENT_KEY_0 :
             printf("BSP_EVENT_KEY_0\r\n");
             break;

        case BSP_EVENT_KEY_1 :
             printf("BSP_EVENT_KEY_1\r\n");
             break;

        case BSP_EVENT_KEY_2 :
             printf("BSP_EVENT_KEY_2\r\n");
             break;

        case BSP_EVENT_KEY_3 :
             printf("BSP_EVENT_KEY_3\r\n");
             break;

        case BSP_EVENT_KEY_4 :
             printf("BSP_EVENT_KEY_4\r\n");
             break;
       
        default:
            
            printf("> BSP_no_data\r\n");

            break;
    }
}

When you actually press the key, a strange phenomenon occurs.

Phenomenon 1) When key is pressed, BSP_EVNT_KEY_0 is generated All evnets in the above switch statement are generated sequentially.

                          However, it occurs only once according to evnt when keys of BSP_EVNT_KEY_1 ~ 4, excluding BSP_EVNT_KEY_0, are input.

   <-  Capture printf output when BSP_EVNT_KEY_0 key is pressed

Phenomenon 2)  When advertising is no longer done due to Pheripheral's connection time-out, another problem arises.

At this time, pressing the key resets and all events occur sequentially at once.

    <-  Capture printf output when BSP_EVNT_KEY_1 key is pressed

I can't find the cause, so I'm asking for help.

Parents
  • Hi David, 

    Could you please try testing the buttons without BLE ? 
    Note that BSP_EVENT_SLEEP, BSP_EVENT_DISCONNECT , BSP_EVENT_WHITELIST_OFF may use the same buttons as yours. 
    Please test and make sure you don't have any issue on the hardware board that causing the pins to connect together. Do you see the same issue if you test on a DK ?

    My suggestion is to try testing with only 2 buttons at a time and try debugging to see why other button event is also triggered. 

  • hello,

    Thank you very much for your answer.

    1) Commenting out "err_code = bsp_btn_ble_init(NULL, &startup_event);" and testing it.

        As mentioned, Note that BSP_EVENT_SLEEP, BSP_EVENT_DISCONNECT ,

        BSP_EVENT_WHITELIST_OFF is defined in " err_code = bsp_btn_ble_init(NULL, &startup_event); ".

    static void buttons_leds_init(bool * p_erase_bonds)
    {
        bsp_event_t startup_event;
    
        uint32_t err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);
        APP_ERROR_CHECK(err_code);
    
      // FIXME
      //  err_code = bsp_btn_ble_init(NULL, &startup_event);
      //  APP_ERROR_CHECK(err_code);
    
        *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
    }
    

    2) I tested the port assigned to the key in the working source by turning it back to the DK version.

        [ result ]

       - BSP_EVENT_KEY_0 : When an event occurs, it is reset and enters the event routine

       - The remaining BSP_EVENT_KEY_0 ~ 3 operate normally

    3) In the DK version test of " 2) " err_code = bsp_btn_ble_init(NULL, &startup_event);

         Commenting out the function Even if " BSP_EVENT_KEY_0 " occurs, rest is no longer possible.

    4) Strange...

        On the PCB board I made, err_code = bsp_btn_ble_init(NULL, &startup_event);

       The function is definitely commented out I checked again to see if it was processed and tested it.

       symptoms are the same

    5) In the code below, " switch (event) " broke and looked at the value of the event variable.

    The value of event is sequentially BSP_EVENT_KEY_0 -> BSP_EVENT_KEY_1 -> BSP_EVENT_KEY_2 occurs in this way. I just pressed the key assigned to BSP_EVENT_KEY_0...

    I just pressed the key assigned to BSP_EVENT_KEY_0...

     

    /**@brief Function for handling events from the BSP module.
     *
     * @param[in]   event   Event generated by button press.
     */
    void bsp_event_handler(bsp_event_t event)
    {
        uint32_t err_code;
        uint8_t reason;
        switch (event)
        {
            case BSP_EVENT_SLEEP:
    
                printf("> BSP_EVENT_SLEEP\r\n");
                sleep_mode_enter();
                break;
            
          
            case BSP_EVENT_DISCONNECT:
    
                reason = BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION;
                printf("> BSP_EVENT_DISCON : %x Reconn..\r\n", reason);
                err_code = sd_ble_gap_disconnect(m_conn_handle, reason);
               
                if (err_code != NRF_ERROR_INVALID_STATE)
                {
                    APP_ERROR_CHECK(err_code);
                }
                
    
                break;
    
    
            case BSP_EVENT_WHITELIST_OFF:
    
                 printf("> BSP_EVENT_WHITELIST_OFF\r\n");
                if (m_conn_handle == BLE_CONN_HANDLE_INVALID)
                {
                    err_code = ble_advertising_restart_without_whitelist(&m_advertising);
                    if (err_code != NRF_ERROR_INVALID_STATE)
                    {
                        APP_ERROR_CHECK(err_code);
                    }
                }
                break;
    
            case BSP_EVENT_KEY_0 :
                 printf("BSP_EVENT_KEY_0\r\n");
                 break;
    
            case BSP_EVENT_KEY_1 :
                 printf("BSP_EVENT_KEY_1\r\n");
                 break;
    
            case BSP_EVENT_KEY_2 :
                 printf("BSP_EVENT_KEY_2\r\n");
                 break;
    
            case BSP_EVENT_KEY_3 :
                 printf("BSP_EVENT_KEY_3\r\n");
                 break;
    
            case BSP_EVENT_KEY_4 :
                 printf("BSP_EVENT_KEY_4\r\n");
                 break;
           
            default:
                
                printf("> BSP_no_data\r\n");
    
                break;
        }
    }

    5) Short  test was performed on the 5 keys of the PCB board I made, but there is no abnormality.

    Advice please.

  • Hi David, 
    I think I know what could be wrong here. 

    It was because of the active state has changed from BUTTONS_ACTIVE_STATE 0 to BUTTONS_ACTIVE_STATE 1. But our bsp initializing bsp array doesn't have that active state reflected. They are all "false" (0)

    It looks like this: 

    static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
    {
        #ifdef BSP_BUTTON_0
        {BSP_BUTTON_0, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_0
    
        #ifdef BSP_BUTTON_1
        {BSP_BUTTON_1, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_1
    
        #ifdef BSP_BUTTON_2
        {BSP_BUTTON_2, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_2
    
        #ifdef BSP_BUTTON_3
        {BSP_BUTTON_3, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_3
    
        #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_4
    
        #ifdef BSP_BUTTON_5
        {BSP_BUTTON_5, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_5
    
        #ifdef BSP_BUTTON_6
        {BSP_BUTTON_6, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_6
    
        #ifdef BSP_BUTTON_7
        {BSP_BUTTON_7, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_7
    
    };


    If you change it to this: 

    static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
    {
        #ifdef BSP_BUTTON_0
        {BSP_BUTTON_0, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_0
    
        #ifdef BSP_BUTTON_1
        {BSP_BUTTON_1, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_1
    
        #ifdef BSP_BUTTON_2
        {BSP_BUTTON_2, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_2
    
        #ifdef BSP_BUTTON_3
        {BSP_BUTTON_3, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_3
    
        #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_4
    
        #ifdef BSP_BUTTON_5
        {BSP_BUTTON_5, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_5
    
        #ifdef BSP_BUTTON_6
        {BSP_BUTTON_6, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_6
    
        #ifdef BSP_BUTTON_7
        {BSP_BUTTON_7, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_7
    
    };

    It should work

Reply
  • Hi David, 
    I think I know what could be wrong here. 

    It was because of the active state has changed from BUTTONS_ACTIVE_STATE 0 to BUTTONS_ACTIVE_STATE 1. But our bsp initializing bsp array doesn't have that active state reflected. They are all "false" (0)

    It looks like this: 

    static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
    {
        #ifdef BSP_BUTTON_0
        {BSP_BUTTON_0, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_0
    
        #ifdef BSP_BUTTON_1
        {BSP_BUTTON_1, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_1
    
        #ifdef BSP_BUTTON_2
        {BSP_BUTTON_2, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_2
    
        #ifdef BSP_BUTTON_3
        {BSP_BUTTON_3, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_3
    
        #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_4
    
        #ifdef BSP_BUTTON_5
        {BSP_BUTTON_5, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_5
    
        #ifdef BSP_BUTTON_6
        {BSP_BUTTON_6, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_6
    
        #ifdef BSP_BUTTON_7
        {BSP_BUTTON_7, false, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_7
    
    };


    If you change it to this: 

    static const app_button_cfg_t app_buttons[BUTTONS_NUMBER] =
    {
        #ifdef BSP_BUTTON_0
        {BSP_BUTTON_0, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_0
    
        #ifdef BSP_BUTTON_1
        {BSP_BUTTON_1, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_1
    
        #ifdef BSP_BUTTON_2
        {BSP_BUTTON_2, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_2
    
        #ifdef BSP_BUTTON_3
        {BSP_BUTTON_3, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_3
    
        #ifdef BSP_BUTTON_4
        {BSP_BUTTON_4, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_4
    
        #ifdef BSP_BUTTON_5
        {BSP_BUTTON_5, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_5
    
        #ifdef BSP_BUTTON_6
        {BSP_BUTTON_6, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_6
    
        #ifdef BSP_BUTTON_7
        {BSP_BUTTON_7, BUTTONS_ACTIVE_STATE, BUTTON_PULL, bsp_button_event_handler},
        #endif // BUTTON_7
    
    };

    It should work

Children
No Data
Related