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

Push button to start BLE for power optimization

Hi,

I am working on an application where the device will be in off mode(only timer and BSP initialized in main ) initially and when I long press button_0 for 5 sec the remaining function will initialize and the device start advertising.

My main function:

int main(void){
    // off mode
	// Initialize.
	log_init();
	
	nrf_cal_init();
    timers_init();
    buttons_leds_init(&erase_bonds);
	power_management_init();
		
    scheduler_init();
	ble_stack_init();
   
   
    // Enter main loop.
    for (;;)
    {
		// ideal state
		idle_state_handle();
    }
}

My Function for handling events from the BSP module.

/**@brief Function for initializing buttons and leds.
 *
 * @param[out] p_erase_bonds  Will be true if the clear bonding button was pressed to wake the application up.
 */
static void buttons_leds_init(bool * p_erase_bonds){
    ret_code_t err_code;
    bsp_event_t startup_event;

    err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_btn_ble_init(NULL, &startup_event);
    APP_ERROR_CHECK(err_code);
	
		err_code = bsp_event_to_button_action_assign(BSP_BOARD_BUTTON_0, BSP_BUTTON_ACTION_LONG_PUSH, BT0_LONG_PUSH);
    APP_ERROR_CHECK(err_code);
	
    *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}


void bsp_event_handler(bsp_event_t event){
    ret_code_t err_code;
    switch (event)
    {	
    case BT0_LONG_PUSH:
        // advertising mode
		gap_params_init();
		gatt_init();
		db_discovery_init();
		services_init();
		advertising_init();
		peer_manager_init();
		conn_params_init();
		advertising_start(erase_bonds);
		
		NRF_LOG_INFO("Application started in Advertising Mode.");    
    
    
    }
    }

Problem:  the power consumption in off mode is almost the same as the advertising mode ( after the long button press), equal to almost 0.500mA.

Please let me know which min. functions I needed to initialize in the main function to minimize my power consumption during off mode.

thanks

Related