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

Can't get app_button handler to fire

Hello,

I'm trying a very simple thing; to light a LED on button press. I'm using SDK 9.0.0, nRF51 and SoftDevice 110. However, button handler is not firing.

So, APP_BUTTON_INIT macro is now non-existent (documentation still refers to it though) and app_button_init() takes only 3 args, last one, whether scheduler should be used, is now omitted. This was discussed here too but did not help me in anyway. Also, I do not want to use a scheduler.

So what am I doing wrong that the handler is not firing?

Here is my code (main()):

int main(void) {
    nrf_gpio_cfg_output(11); // LED
    static app_button_cfg_t p_button[] = {{8, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}}; // Button
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    APP_GPIOTE_INIT(1);
    app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), BUTTON_DEBOUNCE_DELAY); // 50ms debounce
    app_button_enable();

    while(true) { /* do nothing */ }
}

And handler (very simplified):

static void button_handler(uint8_t pin_no, uint8_t button_action)
{
     nrf_gpio_pin_toggle(11);
}
Parents
  • Hello,

    I'm trying to do the same things, to light a LED on button press whiteout using SoftDevice. I'm using SDK v10.0.0 and nRF51.

    That is my main code :

    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
    
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    
    app_button_cfg_t app_buttons[NUM_OF_BUTTONS] = {
    	{ BUTTON_1, false, BUTTON_PULL, button_handler },
    	{ BUTTON_2, false, BUTTON_PULL, button_handler },
    };
    
    uint8_t err_code = app_button_init((app_button_cfg_t *)app_buttons,
        NUM_OF_BUTTONS,
        APP_TIMER_TICKS(50, APP_TIMER_PRESCALER));
    APP_ERROR_CHECK(err_code);
    
    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);
    
    while(true);
    

    Here is my handler function :

    static void button_handler(uint8_t pin_no, uint8_t button_action) {
    	if(button_action == APP_BUTTON_PUSH) {
    		switch(pin_no) {
    			case BUTTON_1:
    				LEDS_CONFIGURE(1<<LED_1);
    				break;
    			default:
    				break;
    		}
    	}
    }
    

    As you can see it's a very simple code, but he doesn't work. If anyone have an idea about what I'm doing wrong, please tell me.

Reply
  • Hello,

    I'm trying to do the same things, to light a LED on button press whiteout using SoftDevice. I'm using SDK v10.0.0 and nRF51.

    That is my main code :

    NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
    NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
    while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);
    	NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
    
    APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);
    
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
    
    app_button_cfg_t app_buttons[NUM_OF_BUTTONS] = {
    	{ BUTTON_1, false, BUTTON_PULL, button_handler },
    	{ BUTTON_2, false, BUTTON_PULL, button_handler },
    };
    
    uint8_t err_code = app_button_init((app_button_cfg_t *)app_buttons,
        NUM_OF_BUTTONS,
        APP_TIMER_TICKS(50, APP_TIMER_PRESCALER));
    APP_ERROR_CHECK(err_code);
    
    err_code = app_button_enable();
    APP_ERROR_CHECK(err_code);
    
    while(true);
    

    Here is my handler function :

    static void button_handler(uint8_t pin_no, uint8_t button_action) {
    	if(button_action == APP_BUTTON_PUSH) {
    		switch(pin_no) {
    			case BUTTON_1:
    				LEDS_CONFIGURE(1<<LED_1);
    				break;
    			default:
    				break;
    		}
    	}
    }
    

    As you can see it's a very simple code, but he doesn't work. If anyone have an idea about what I'm doing wrong, please tell me.

Children
No Data
Related