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

nrf51822 gpiote could not enter interrupt routine

Hello I am using SDK12.3 without softdevice on a custom board (with nrf51822 256k flash, 16kram without 32768 crystal).

I have written some code using GPIOTE to detect two buttons (with app_button library) when pressed and it worked no problem on nrf5 dev board.

However when i ported the code to the custom board i found that button press could only wake up the MCU but it won't enter the interrupt routine (button handler function).

Any idea could lead to this problem??

Thanks. MM

  • Thanks Amigo, tried to add this but it makes no difference (also the original code works in NFF51 DK board do not need it)

    Below are the code i initialize the buttons...

    static void buttons_leds_init(bool * p_erase_bonds)
    {    
    	uint32_t err_code;
    	static app_button_cfg_t p_button[] = {{BUTTON_1, APP_BUTTON_ACTIVE_HIGH, NRF_GPIO_PIN_NOPULL, button_handler},		
    											  {BUTTON_2, APP_BUTTON_ACTIVE_LOW, NRF_GPIO_PIN_PULLUP, button_handler}};	
    				
    	APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS);																					
    	// Initializing the buttons.
    	err_code = app_button_init(p_button, sizeof(p_button) / sizeof(p_button[0]), BUTTON_DEBOUNCE_DELAY);
    	
    	APP_ERROR_CHECK(err_code);																					
    	err_code = app_button_enable();	
    	APP_ERROR_CHECK(err_code); 
    }
    
    1. So the exact same code works on the nRF51, but not your custom board?
    2. I assume you have double checked that you use the correct pins?
    3. Is there a reason why you configure Button 1 without pullup resistor, and button 2 with pullup?
  • @ Martin

    1. Yes, except i have to change the pin definition correspondingly
    2. Yes.
    3. This is due to the hardware limitation.

    Just a thought...is it possible due to the absent of 32768 crystal and somehow i do not configure to use internal RC properly? I have set the CLOCK_CONFIG_LF_SRC to RC in Configuration Wizard. Do i need to change any code in the project files??

    Thanks

  • Here is my code for nrf5 sdk 12

    static void buttons_leds_init(bool * p_erase_bonds)
    {
     bsp_event_t startup_event;
     uint32_t err_code = bsp_init(BSP_INIT_LED | BSP_INIT_BUTTONS,
                                 APP_TIMER_TICKS(100, APP_TIMER_PRESCALER),
                                 bsp_event_handler);
     APP_ERROR_CHECK(err_code);
     err_code = bsp_btn_ble_init(NULL, &startup_event);
     APP_ERROR_CHECK(err_code);
     *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
    
     #if defined  (NRF52832)
    	// init LED
    	nrf_gpio_cfg_output(LED2);
    	// Set gas sensors manage output pins
    	nrf_gpio_cfg_output(CO_Pin);
    	nrf_gpio_cfg_output(CH4_Pin);
    
    	nrf_gpio_pin_set(CO_Pin);
    	nrf_gpio_pin_set(CH4_Pin);
    	// init BUTTON		
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);    
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_1, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_2, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);  
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_3, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW); 
    
    	NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
                NVIC_EnableIRQ(GPIOTE_IRQn);
     #elif defined  (NRF51822)
    	// init LED
    	nrf_gpio_cfg_output( LED1 );
                nrf_gpio_cfg_sense_input(BSP_BUTTON_0, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);    
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_1, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_2, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW);  
    	nrf_gpio_cfg_sense_input(BSP_BUTTON_3, GPIO_PIN_CNF_PULL_Pullup, NRF_GPIO_PIN_SENSE_LOW); 
                NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Msk;
                NVIC_EnableIRQ(GPIOTE_IRQn);
     #endif	
    }
    
    
    void GPIOTE_IRQHandler(void)
    {
      uint8_t bit;
      if(NRF_GPIOTE->EVENTS_PORT)
      {
    			if((~((NRF_GPIO->IN) >> BSP_BUTTON_0) & 0x01)) val=0x00;
    			if((~((NRF_GPIO->IN) >> BSP_BUTTON_1) & 0x01)) __nop();
    		#if defined  (NRF52832)
    			if((~((NRF_GPIO->IN) >> BSP_BUTTON_2) & 0x01)) __nop();
    			if((~((NRF_GPIO->IN) >> BSP_BUTTON_3) & 0x01)) __nop();
    		#endif
        NRF_GPIOTE->EVENTS_PORT = 0;
      }
    }
    
Related