Hello, I am developing a custom board based on nRF52832 that should spend most of it's time in SystemOFF mode. Eventually, it will wake up on an GPIO event caused by the external magnetic switch (LF11115TMR). Now, the switch behaves funny - it retains its state until a magnet is brought close to it. When I move the magnet close to it, it switches to low and stays until the magnet is moved back close to it. Then it switches high and stays there.
The problem is how to configure the nRF52832: if I set PIN_CNF to sense either low or high, it will keep on waking up constantly, since the switch doesn't change its state until the magnet is brought nearby. The solution I found is to check the state of the switch before going SystemOFF and changing the PIN_CNF accordingly. So the code looks like this:
void sleep_mode_enter(void){
printf("\n\rEntering SystemOFF sleep mode...");
nrf_delay_ms(500);
uint32_t tmr_state = nrf_gpio_pin_read(TMR_SWITCH);
// Prepare wakeup buttons.
if (tmr_state)
nrf_gpio_cfg_sense_set(TMR_SWITCH, NRF_GPIO_PIN_SENSE_LOW);
else
nrf_gpio_cfg_sense_set(TMR_SWITCH, NRF_GPIO_PIN_SENSE_HIGH);
// Go to system-off mode (this function will not return; wakeup will cause a reset).
sd_power_system_off();
}
And this turned out to be working fine...but only half the time. My system either goes to sleep like everything's fine or it ends up in an infinite reset loop hell. When I look into the debugger I see that PIN_CNF has been modified outside of my above function. Digging deeper in the stack, found that function port_event_handle() in nrfx_gpiote.c has some funny reconfiguration:
/* Reconfigure sense to the opposite level, so the internal PINx.DETECT signal
* can be deasserted. Therefore PORT event generated again,
* unless some other PINx.DETECT signal is still active. */
nrf_gpio_pin_sense_t next_sense =
(sense == NRF_GPIO_PIN_SENSE_HIGH) ? NRF_GPIO_PIN_SENSE_LOW :
NRF_GPIO_PIN_SENSE_HIGH;
that changes my sense inputs. Now, what to make of it? How to circumvent this without modifying nrfx_gpiote.c and is there a better approach in configuring wake-up pin for my application?
Best,
W.