Hi,
We have a custom device that has 15 buttons. Presently we use the following code to initialize and use the button interrupts. I am using a __WFE(); to wait for the next event (i.e. a button press) however when I press two specific buttons (by design) together it brings the device partially into sleep_mode. This method works sufficient for detecting the button presses, but in attempting to put the device into a lower power mode it seems that some sort of interrupt is triggering the device to come right out of the low power mode or not completely go into low power mode. The device does come out of the "low power (5mA)" mode but completes a reset in the process. The current draw drops from about 9 mA (with I2C device) down to 5 mA (likely, just without I2C device), but never drops to uA levels. My thought is that another interrupt triggers the device to come right out while keeping the I2C device off, but I'm not sure which one would do that.
/* * * The following contain the interrupt handlers for all button presses * */ void in_pin_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { buttons_pressed = true; chirp_led(BLUE_LED); ret_code_t err_code; if(power_off_mode) { //Disable power-down button to prevent System-off wakeup for(int i = 0; i < NUM_BUTTONS; i++) { nrf_drv_gpiote_in_uninit(buttons[i]); nrf_drv_gpiote_in_event_disable(buttons[i]); } //Configure wake-up button for(int i = 0; i < NUM_BUTTONS; i++) { nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(false); //Configure to generate interrupt and wakeup on pin signal high. in_config.pull = NRF_GPIO_PIN_PULLDOWN; //Configure pulldown for input pin to prevent it from floating. err_code = nrf_drv_gpiote_in_init(buttons[i], &in_config, in_pin_handler); //Initialize the wake-up pin APP_ERROR_CHECK(err_code); //Check error code returned nrf_drv_gpiote_in_event_enable(buttons[i], true); //Enable event and interrupt for the wakeup pin } //Enter System-off NRF_POWER->SYSTEMOFF = 1; } } // //@brief Function for configuring: PIN_IN pin for input, PIN_OUT pin for output, // and configures GPIOTE to give an interrupt on pin change. // static void gpio_init(void) { ret_code_t err_code; nrf_gpio_cfg_output(BLUE_LED); nrf_gpio_cfg_output(RED_LED); if(nrf_drv_gpiote_is_init() == false) { err_code = nrf_drv_gpiote_init(); APP_ERROR_CHECK(err_code); } for(int i = 0; i < NUM_BUTTONS; i++) { nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_LOTOHI(false); in_config.pull = NRF_GPIO_PIN_PULLDOWN; err_code = nrf_drv_gpiote_in_init(buttons[i], &in_config, in_pin_handler); APP_ERROR_CHECK(err_code); nrf_drv_gpiote_in_event_enable(buttons[i], true); } }
Searching around I found a handful of explanations of using the BSP module along with a sleep_mode_enter() based on a button press. However, all of the documentation only shows 8 buttons available in the BSP module. Is there the ability to handle more buttons than that, 15 or more? If so what steps would need to be taken to modify the included files to allow for this? Do I need to modify the pca10040.h, bsp.h/c, boards.h/c, others? How so?
Thanks for the help!