PIN_CNF Sense change state

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.

Parents
  • Hi,

     

    the nrfx_gpiote port event is setup to simulate edge triggering with a level triggered hardware signal.

    It therefore uses the cpu to invert the .SENSE field to be able to provide an event when input signal occurs and when it goes back to idle state.

     

    In the SYSTEMOFF scenario, we have to differentiate between a wake-up scenario and a interrupt scenario.

    All pins with SENSE configured with either HIGH or LOW can generate a wake-up scenario from SYSTEMOFF, regardless of if the GPIOTE PORT event is enabled or not.

     

    If you fear that you're getting interrupted while executing code in sleep_mode_enter, I would recommend that you wrap around the sensitive code and disable the GPIOTE IRQ before configuring and entering SystemOFF.

     

    My system either goes to sleep like everything's fine or it ends up in an infinite reset loop hell.

    This is more concerning. Is this due to an assert upon wakeup?

    Have you tried to add the preprocessor symbol "DEBUG" to see where you assert?

     

    Kind regards,

    Håkon

  • Hello Hakon, after 2 months, I am back on this issue. 

    I am working in the debug mode, but I dont get any assert.. It is my understanding that debugger doesn't let me go into the SYSTEMOFF, so I cant really see what is actually going on in SYSTEMOFF, can I?

    But, for the sake of investigation, I have commented out the line  sd_power_system_off(); and observed the above described isue, that .SENSE gets inverted. 

  • Hi,

     

    If you are entering system off mode while the debug session is active, you're in "emulated system off", where it is strongly recommended that you add a loop after the systemoff call, as explained here:

    https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/power.html?cp=4_2_0_17_1_0#unique_1150026639

     

    Have you tried setting a pull-resistor before flipping the sense orientation?

     

    Kind regards,

    Håkon

Reply Children
No Data
Related