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

GPIOTE Port event triggered by the state of the pin, not an edge change.

Hi,

I put my NRF52 to sleep (POWER OFF mode) and configure it to wake on GPIO port event like so: 

    //set up reed switch to wake up from System Off
      nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
      in_config.pull = NRF_GPIO_PIN_NOPULL; //hardware pull up resistor.
      err_code = nrf_drv_gpiote_in_init(REED_SWITCH_PIN, &in_config, wake_handler);
      APP_ERROR_CHECK(err_code);
      nrf_drv_gpiote_in_event_enable(REED_SWITCH_PIN, true);
      
      SEGGER_RTT_printf(0, "Powering Down!\r\n");
      
      sd_power_system_off();

This GPIO is set up on a reed switch. Occasionally, the NRF52 will try to sleep whilst the magnet is resting next to the reed switch. I.e REED_SWITCH_PIN is at a steady state low. 

Problem:

  • When REED_SWITCH_PIN is a steady state low, the interrupt fires straight away and wakes up my sensor unexpectedly.
  • From reading the documentation I would expect that the PORT event can detect an edge change? Is this true, or am I seeing something weird?

I do have a work around which involves using a GPIOTE in event, and sending the device into System-on sleep mode, however power consumption is obviously higher - so not ideal.

  • I think may have misunderstood the requirement for this. I assumed the REED input would always be kept low in system OFF. Could it also be kept high? In that case you must change the sense configuration based on pin state before entering system off. E.g., if pin is low, sense should be configured to sense for high level. The sense mechanism can detect transition from high to low, or low to high, but not both (toggling).     

  • Yes, it could be kept both low and high whilst sleeping, but wanted to wake up only when transitioning from high to low.

    I.e if the reed switch was already low when entering sleep, I was expecting it to stay asleep until the reed switch has gone high (still asleep at this stage) and then gone low (high->low transition waking the device up). 

    However, your final suggestion does provide an acceptable solution (embarrassed I missed such a nice and simple fix!). Thank you for the help.

     

Related