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

How to disable the timer before sleep?

nRF52832, SDK15.0.0, S132

Hello.

I want to go into system on sleep and not wake up until I press the button.

But I'm using timer 1, so it seems to continue wakeup.

So I tried to disable the timer before sleeping.

timer_configure();                  // Timer Enable

while(1){
  
  //nrf_drv_timer_disable(&hTIMER);
  //nrf_drv_timer_uninit(&hTIMER);
  NRF_TIMER1->TASKS_STOP = 1;

  nrf_pwr_mgmt_run();

  //nrf_drv_timer_enable(&hTIMER);
  
  NRF_TIMER1->TASKS_START = 1;
  
  nrf_gpio_pin_write(24,false);
  nrf_delay_ms(100);
  nrf_gpio_pin_write(24,true);
  nrf_delay_ms(100);
}

(P0.24 : LED)

But it does not sleep.

If "//NRF_TIMER1-> TASKS_START = 1;"

It seems to wakeup only when the button is pressed.

I do not know why.
Is there any reason other than a timer?

(The code is based on the ble_uart example.)

Parents
  • Hi,

    Can you upload your main.c file here? The provided code snippet does not provided enough information unfortunately. 

  • Hi,

    Main.c is as follows.

    int main(void)
    {   
        ret_code_t err_code;    
    
        // Initialize.
        //uart_init(); 
        //log_init();
        timers_init();
        power_management_init();
        ble_stack_init(); 
        sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
        peer_manager_init();
        
        /* EEPROM Init */ 
        ret_code_t rc;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(rc);
        nrf_delay_ms(100);
        
        
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        bsp_board_init(BSP_INIT_BUTTONS);   
        bsp_board_init(BSP_INIT_LEDS); 
        interrupt_configure(); 
        timer_configure();  
    
        advertising_start();
    
        saadc_init();     
        HX711_init();   
        PWM_configure(); 
        
    
        while(1){       
    	//nrf_drv_timer_disable(&hTIMER);
    	//nrf_drv_timer_uninit(&hTIMER);
    	NRF_TIMER1->TASKS_STOP = 1;
    
    	nrf_pwr_mgmt_run();
    
    	//nrf_drv_timer_enable(&hTIMER);
    
    	NRF_TIMER1->TASKS_START = 1;
    
    	nrf_gpio_pin_write(24,false);
    	nrf_delay_ms(100);
    	nrf_gpio_pin_write(24,true);
    	nrf_delay_ms(100);	
        }
    }

    I also use a lot of current in sleep.
    Should I disable my use of timer, adc, pwm, twi, spi, etc before sleep, whether it is system on sleep or system off phase?
    I wonder what I should do before I go to sleep.

Reply
  • Hi,

    Main.c is as follows.

    int main(void)
    {   
        ret_code_t err_code;    
    
        // Initialize.
        //uart_init(); 
        //log_init();
        timers_init();
        power_management_init();
        ble_stack_init(); 
        sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE);
        peer_manager_init();
        
        /* EEPROM Init */ 
        ret_code_t rc;
        nrf_fstorage_api_t * p_fs_api;
        p_fs_api = &nrf_fstorage_sd;
        rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
        APP_ERROR_CHECK(rc);
        nrf_delay_ms(100);
        
        
        gap_params_init();
        gatt_init();
        services_init();
        advertising_init();
        conn_params_init();
    
        bsp_board_init(BSP_INIT_BUTTONS);   
        bsp_board_init(BSP_INIT_LEDS); 
        interrupt_configure(); 
        timer_configure();  
    
        advertising_start();
    
        saadc_init();     
        HX711_init();   
        PWM_configure(); 
        
    
        while(1){       
    	//nrf_drv_timer_disable(&hTIMER);
    	//nrf_drv_timer_uninit(&hTIMER);
    	NRF_TIMER1->TASKS_STOP = 1;
    
    	nrf_pwr_mgmt_run();
    
    	//nrf_drv_timer_enable(&hTIMER);
    
    	NRF_TIMER1->TASKS_START = 1;
    
    	nrf_gpio_pin_write(24,false);
    	nrf_delay_ms(100);
    	nrf_gpio_pin_write(24,true);
    	nrf_delay_ms(100);	
        }
    }

    I also use a lot of current in sleep.
    Should I disable my use of timer, adc, pwm, twi, spi, etc before sleep, whether it is system on sleep or system off phase?
    I wonder what I should do before I go to sleep.

Children
Related