Use the same pin to wake up and other uses

Hi to all!

I'm trying to use the same GPIO to wake up the nrf52810 from system off and also use it to execute some functions. I have this code that is based on the example from this link: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/zephyr/samples/boards/nrf/system_off/README.html

// function to power off
static void power_off_system() {
	/* Configure to generate PORT event (wakeup) on button 1 press. */
	nrf_gpio_cfg_input(btn.pin, NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(btn.pin, NRF_GPIO_PIN_SENSE_LOW);

	printk("Pwering off device\n");
	pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});

	/* Now we need to go sleep. This will let the idle thread runs and
	 * the pm subsystem will use the forced state. To confirm that the
	 * forced state is used, lets set the same timeout used previously.
	 */
	// k_sleep(2);
	k_msleep(2000);
}
/* Prevent deep sleep (system off) from being entered on long timeouts
 * or `K_FOREVER` due to the default residency policy.
 *
 * This has to be done before anything tries to sleep, which means
 * before the threading system starts up between PRE_KERNEL_2 and
 * POST_KERNEL.  Do it at the start of PRE_KERNEL_2.
 */
static int disable_ds_1(const struct device *dev)
{
	ARG_UNUSED(dev);

	pm_policy_state_lock_get(PM_STATE_SOFT_OFF);
	return 0;
}

SYS_INIT(disable_ds_1, PRE_KERNEL_2, 0);

This is executed when long press the button. Then in the wake up, it works but the button has some strange behavior like it us pulsed 2 times at the same time. The button is configured as an interrupt that enable a timer to test if is a long press or a simple press.

This is the configuration of the GPIO to use it as an interrupt:

gpio_init_callback(&button_cb_data, button_pressed, BIT(btn.pin));
gpio_add_callback(btn.port, &button_cb_data);

Also, there is a way to start the nrf with system off and wake it up with a long press?

Best regards

Parents
  • Hi,

     

    This is executed when long press the button. Then in the wake up, it works but the button has some strange behavior like it us pulsed 2 times at the same time.

    Do you apply an external pull resistor on the pin? How is your debouncing implemented?

     

    Kind regards,

    Håkon

  • Hi Hákon,

    Is a software problem, I'm using the nrf52 DK with the board buttons. The problem is: If I configure one GPIO to use it as interrupt, then only with that I can't wake up the nrf from system_off. So, to be able to wake it up I have to configure the GPIO as sense to wake it up, but after configure as a sense then, when the nrf52 wake up from system off, the GPIO (I'm using the same as interrupt and for wake up) sense 2 time when I push the button. One quick fix that I've made was clean the configuration of the port when it wake up.

    Is a more effective way to configure the same GPIO as an interrupt and to use it a sense to wake up?

    Best regards

Reply
  • Hi Hákon,

    Is a software problem, I'm using the nrf52 DK with the board buttons. The problem is: If I configure one GPIO to use it as interrupt, then only with that I can't wake up the nrf from system_off. So, to be able to wake it up I have to configure the GPIO as sense to wake it up, but after configure as a sense then, when the nrf52 wake up from system off, the GPIO (I'm using the same as interrupt and for wake up) sense 2 time when I push the button. One quick fix that I've made was clean the configuration of the port when it wake up.

    Is a more effective way to configure the same GPIO as an interrupt and to use it a sense to wake up?

    Best regards

Children
Related