I have enable 4 Low power events for 4 button in NRF52832 board. when i press a button board is waking up due to low power event
but when it is waiting in low power mode using sequence __sev(); __wfe(); __wfe(); events are not coming.
if i enable GPIOTE IRQ interrupt, i am getting the interrupts in low power mode but I don't want use interrupts.
#define BTN_PRESSED 0 /**< Value of a pressed button. */
#define BTN_RELEASED 1 /**< Value of a released button. */
static uint32_t button_state_1;
static uint32_t button_state_2;
static uint32_t button_state_3;
static uint32_t button_state_4;
NRF_GPIOTE->EVENTS_PORT = 0;
button_state_1 = nrf_gpio_pin_read(BUTTON_1);
button_state_2 = nrf_gpio_pin_read(BUTTON_2);
button_state_3 = nrf_gpio_pin_read(BUTTON_3);
button_state_4 = nrf_gpio_pin_read(BUTTON_4);
if (button_state_1 == BTN_PRESSED)
if (button_state_2 == BTN_PRESSED)
if (button_state_3 == BTN_PRESSED)
if (button_state_4 == BTN_PRESSED)
#define MY_BUTTON BUTTON_1
#define MY_LED LED_2
void gpio_init( void )
nrf_gpio_cfg_sense_input(BUTTON_1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
nrf_gpio_cfg_sense_input(BUTTON_2, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
nrf_gpio_cfg_sense_input(BUTTON_3, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
nrf_gpio_cfg_sense_input(BUTTON_4, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
// Workaround for PAN_028 rev1.1 anomaly 22 - System: Issues with disable System OFF mechanism
NRF_GPIOTE->EVENTS_PORT |= (1 << BUTTON_1);
// Enable interrupt:
//NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
/**@brief Function for initializing the nrf log module.
static void log_init(void)
ret_code_t err_code = NRF_LOG_INIT(NULL);
// Check state of all buttons with the button press, and toggle LED
err_code = gpio_check();
/*lint -restore */
I have attached simple test file main.c
What do you mean? How does this differ from what you want to achieve? I'm not sure I understand the issue.
thanks for your reply.
I have provided a simple code. in that, I enabled 4 GPIOTE events.
if i am going to systemoff instead of waiting in low power mode NRF52832 is waking up.
Q1.can GPIOTE events cant make NRF52832 come out of low power mode?
Q2. GPIOTE events won't come when system_on condition?
Yes, PORT interrupt should be enabled in NRF_GPIOTE->INTENSET to wake up on that event. If you don't want to use an interrupt, just don't enable it in NVIC.
i added below lin of code
NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
to gpio_init() but still event is not coming.
__SEV(); __WFE(); __WFE();
it seems should be different order: __WFE(); __SEV(); __WFE();
the same sequence is being used in all examples. anyway I checked with the order you mentioned but it is not waiting for an event, immediately going to gpio_check() again.
Surya said:the same sequence is being used in all examples.
The sev/wfe/wfe sequence saves some power when waiting for interrupt, but in case of waiting-for-event loop, you will lose an event if it comes while CPU is active.
I forgot to mention that SEVONPEND flag should be enabled to wake up on any events, including ones disabled in NVIC:
SCB->SCR |= SCB_SCR_SEVONPEND_Msk;
I played with such method for bit-banging protocol some time ago and found it unreliable (sometimes device didn't wake up when it should). For button handling, I don't see any advantage over traditional interrupt-based method.
I added the above mention line of code in gpio_init(), but no use. I am not getting any events when I press a button in the system on mode.
Maybe this topic will be helpful.
no, my case is different. anybody tried my code in nrf52832 board?