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

button event handler not firing

Hello EveryOne

My button event handler is not being called. following is my code what can be the problem.

uint32_t err_code;


    ble_stack_init();

    timers_init();

    APP_GPIOTE_INIT(1);	

    buttons_init();

    device_manager_init();

    gap_params_init();

    advertising_init();

    services_init();

    conn_params_init();

    Therapy_Init();

    Diagnosis_Init();
    ADC_Init();	

    Pstorage_Initialization();

    // Start detecting button presses.
	err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);

my buttons_init code

static app_button_cfg_t buttons[] =
    {
      17, false, NRF_GPIO_PIN_PULLUP, button_events_handler};

  APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false);}

i have also enabled app_button_enable but then also handler is not getting called.

Regards Asma

  • This is a modified version of Nordics example ble_app_uart and the button presses are working for me.

    Maybe it is will give you a hint why your code is not working.main.c

    I basically just added

    err_code = bsp_buttons_enable(0x0F);
    

    and

    static void bspEvent(bsp_event_t event) {
        //debug_printf("bspEvent: %d\n", event);
        switch(event) {
        case BSP_EVENT_NOTHING:
              debug_printf("BSP_EVENT_NOTHING\n");
              break;
        case BSP_EVENT_CLEAR_BONDING_DATA:
              debug_printf("BSP_EVENT_CLEAR_BONDING_DATA\n");
              break;
        case BSP_EVENT_CLEAR_ALERT:
              debug_printf("BSP_EVENT_CLEAR_ALERT\n");
              break;
        case BSP_EVENT_DISCONNECT:
              debug_printf("BSP_EVENT_DISCONNECT\n");
              break;
        case BSP_EVENT_ADVERTISING_START:
              debug_printf("BSP_EVENT_ADVERTISING_START\n");
              break;
        case BSP_EVENT_ADVERTISING_STOP:
              debug_printf("BSP_EVENT_ADVERTISING_STOP\n");
              break;
        case BSP_EVENT_BOND:
              debug_printf("BSP_EVENT_BOND\n");
              break;
        case BSP_EVENT_RESET:
              debug_printf("BSP_EVENT_RESET\n");
              break;
        case BSP_EVENT_SLEEP:
              debug_printf("BSP_EVENT_SLEEP\n");
              break;
        case BSP_EVENT_WAKEUP:
              debug_printf("BSP_EVENT_WAKEUP\n");
              break;
        case BSP_EVENT_DFU:
              debug_printf("BSP_EVENT_DFU\n");
              break;
        case BSP_EVENT_KEY_0:
              debug_printf("BSP_EVENT_KEY_0\n");
              break;
        case BSP_EVENT_KEY_1:
              debug_printf("BSP_EVENT_KEY_1\n");
              break;
        case BSP_EVENT_KEY_2:
              debug_printf("BSP_EVENT_KEY_2\n");
              break;
        case BSP_EVENT_KEY_3:
              debug_printf("BSP_EVENT_KEY_3\n");
              break;
        case BSP_EVENT_KEY_4:
              debug_printf("BSP_EVENT_KEY_4\n");
              break;
        case BSP_EVENT_KEY_5:
              debug_printf("BSP_EVENT_KEY_5\n");
              break;
        case BSP_EVENT_KEY_6:
              debug_printf("BSP_EVENT_KEY_6\n");
              break;
        case BSP_EVENT_KEY_7:
              debug_printf("BSP_EVENT_KEY_7\n");
              break;
     //   case BSP_EVENT_KEY_LAST:
     //         debug_printf("\n");
     //         break;
        
        default:
            debug_printf("Unknown BSP Event: %d\n", event);
        }
    
    
    }
    
  • thank you chris for a reply... but i didnt got any hint.can u plz let me know. if u have understood.

    Thanks asma

  • my code is working now... in one of my initialization i was using bsp_configurations i.e bsp_buttons_enable after commenting now its working properly Now there is some other problem after i add app_buttons my pstorage is not working . initially i used to sore data in pstorage and at the time of boot up i read the data whatever is stored . now its coming to be all 0xFF. Is there any problem using both together , no other thing is added to the code other than buttons_init and enable.

    Thanks Asma

  • Hi Asma

    I am not sure why your pstorage is not working together with app_button library. Does the app_button operation by any chance block the operation of the flash operation? What do you do in your app_button handler?

    You could find out if your pstorage operation is actually writing something to flash, see this thread.

    There is an example code here for pstorage. Perhaps you can compare your code with that code.

    What SDK and SD are you using?

  • I am using SDK 7.1.0 and S110 . my example is pretty much like the one you shared.

Related