Using one button How to enter into Deep sleep mode and wake up the device

Hello!
I am using nRF Connect SDK 2.6.0v.

I want to enter the device into deep sleep mode when i press the button 2 sec
When Next time I press the button 2 sec, wake up from deep sleep mode 

I tried but its not working as expected 
I  want to use GPIO pin to power off and power on the device 

Thank you in advance.

Parents
  • You should give a bit more on information like what does it mean by "not working as expected"

    1. code snippets of the power on power off
    2. code snippets for configuring gpio for power off and wakeup configuration.
    3. What steps you followed 
    4. and finally what steps you tried to debug.
  • void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
    	if(BIT(button.pin) & pins)
    	{
    		if(gpio_pin_get_dt(&button))
    		{
    			k_timer_start(&mytimer, K_SECONDS(2), K_NO_WAIT);
    			printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    
    		}
    		else
    		{
    		    k_timer_stop(&mytimer);
    		}
    		
    	}
    	
    }
    /*Define a variable of type static struct gpio_callback */
    static struct gpio_callback button_cb_data;
    
    struct k_work ads_work;
    /* timer call back function */
    static void my_timer(struct k_timer *dummy)
    {
    	if(gpio_pin_get_dt(&button))
    	{
    		printk("work in timer");
    		k_work_submit(&ads_work);
    	}
    
    }
    struct k_timer mytimer;
    
    
    static void ads_work_cb(struct k_work *work)
    {
    		printk("Button presssed to off the device partially\n");
    		gpio_pin_set_dt(&led, 1);
    		sys_poweroff();
    		//nrf_power_system_off(NRF_POWER);
    		//NVIC_SystemReset();
    	
    			
    		
    	
    	
    }
    
    in main()
    	ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
    	if (ret < 0) {
    		return -1;
    	}
    	/* STEP 3 - Configure the interrupt on the button's pin */
    	ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_LEVEL_ACTIVE);
    
    	/* STEP 6 - Initialize the static struct gpio_callback variable   */
        gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin)); 	
    	
    	/* STEP 7 - Add the callback function by calling gpio_add_callback()   */
    	gpio_add_callback(button.port, &button_cb_data);
    	k_work_init(&ads_work, ads_work_cb);


    I want to enter the device into deep sleep mode when i press the button 2 sec
    When Next time I press the button 2 sec, wake up from deep sleep mode 

    I am expecting like this

    I  want to use GPIO pin to power off and power on the device 

    using button to power off and power on the device using GPIO

Reply
  • void button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
    {
    	if(BIT(button.pin) & pins)
    	{
    		if(gpio_pin_get_dt(&button))
    		{
    			k_timer_start(&mytimer, K_SECONDS(2), K_NO_WAIT);
    			printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
    
    		}
    		else
    		{
    		    k_timer_stop(&mytimer);
    		}
    		
    	}
    	
    }
    /*Define a variable of type static struct gpio_callback */
    static struct gpio_callback button_cb_data;
    
    struct k_work ads_work;
    /* timer call back function */
    static void my_timer(struct k_timer *dummy)
    {
    	if(gpio_pin_get_dt(&button))
    	{
    		printk("work in timer");
    		k_work_submit(&ads_work);
    	}
    
    }
    struct k_timer mytimer;
    
    
    static void ads_work_cb(struct k_work *work)
    {
    		printk("Button presssed to off the device partially\n");
    		gpio_pin_set_dt(&led, 1);
    		sys_poweroff();
    		//nrf_power_system_off(NRF_POWER);
    		//NVIC_SystemReset();
    	
    			
    		
    	
    	
    }
    
    in main()
    	ret = gpio_pin_configure_dt(&button, GPIO_INPUT);
    	if (ret < 0) {
    		return -1;
    	}
    	/* STEP 3 - Configure the interrupt on the button's pin */
    	ret = gpio_pin_interrupt_configure_dt(&button, GPIO_INT_LEVEL_ACTIVE);
    
    	/* STEP 6 - Initialize the static struct gpio_callback variable   */
        gpio_init_callback(&button_cb_data, button_pressed, BIT(button.pin)); 	
    	
    	/* STEP 7 - Add the callback function by calling gpio_add_callback()   */
    	gpio_add_callback(button.port, &button_cb_data);
    	k_work_init(&ads_work, ads_work_cb);


    I want to enter the device into deep sleep mode when i press the button 2 sec
    When Next time I press the button 2 sec, wake up from deep sleep mode 

    I am expecting like this

    I  want to use GPIO pin to power off and power on the device 

    using button to power off and power on the device using GPIO

Children
No Data
Related