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

High power consumption after disable and enable BLE.

Hi,

I use nRF5 SDK v15.0.0. In my application I need periodically disable and enable  Bluetooth because they are wifi also, which connected to the same antenna. Its mean the receiver of the Bluetooth also mast be disabled. 

From the attached code you can see that they are ble_init(), ble_enable and ble_disable. When the first time ble_init( ) called then the all is working fine and the power consumption is normal aprox. 800uA. But when disable by calling the ble_disable(), then enable by ble_enable() function again all working fine but power consumption drastically increase 6.4mA. 

Do you have an ideas whats happening ? Or maybe I'm not properly disabling the BLE ?

int ble_init(void)
{
    // Initialize.
    log_init();
    leds_init();
    timers_init();
    power_management_init();
    ble_stack_init();
    gap_params_init();
    gatt_init();
    services_init();
    advertising_init();
    conn_params_init();   
    
    // Start execution.
    NRF_LOG_INFO("LpPT sensors monitoring started.");
    advertising_start();
    ble_enabled = true;
}

void ble_enable(void)
{
    ret_code_t         err_code;
    ble_lbs_init_t     init     = {0};
    init.led_write_handler = led_write_handler;
    ble_nus_init_t     nus_init;
    int8_t buff[20];
    int32_t data = 0;
    memset(buff,0,20);
    data = (int32_t)(stm_state.current_sensor_data[LIGHT].value);
    data = (((data << 24) & 0xff000000) | ((data << 8) & 0x00ff0000) | ((data >> 8) & 0x0000ff00) | ((data >> 24) & 0x000000ff));
    memcpy(&buff[0],&data,4);
    data = (int32_t)(stm_state.current_sensor_data[LOAD_DET].value);
    data = (((data << 24) & 0xff000000) | ((data << 8) & 0x00ff0000) | ((data >> 8) & 0x0000ff00) | ((data >> 24) & 0x000000ff));
    memcpy(&buff[4],&data,4);  
    if(!ble_enabled)
    {
    	NRF_LOG_INFO("Enabling BLE ");
        ble_stack_init();
        gap_params_init();
        gatt_init();
        err_code = ble_lbs_init(&m_lbs, &init);
        APP_ERROR_CHECK(err_code);
            // Initialize NUS.
        memset(&nus_init, 0, sizeof(nus_init));

        nus_init.data_handler = nus_data_handler;

        err_code = ble_nus_init(&m_nus, &nus_init, buff, 8);
        APP_ERROR_CHECK(err_code);
        adv_message_update();
        conn_params_init();
        advertising_start();
        ble_enabled = true;
     }
}
void ble_disable()
{
    ret_code_t err_code;
    if(ble_enabled)
    {
     	NRF_LOG_INFO("Disabling BLE");
        if(ble_connected)
        {
            err_code = sd_ble_gap_disconnect(m_conn_handle,
                                             BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
            APP_ERROR_CHECK(err_code);
            ble_connected = false;
            //m_conn_handle = 
        }
        else
        {
            if(adv_started)
            {
                err_code = sd_ble_gap_adv_stop(m_adv_handle);
                APP_ERROR_CHECK(err_code);
            }
        }
        err_code = ble_conn_params_stop();
        APP_ERROR_CHECK(err_code);
        err_code = nrf_sdh_disable_request();     
        APP_ERROR_CHECK(err_code);
        ble_enabled = false;
       
    }
}

I used ble_app_blinky example functions for initializing modules. Changed only advertising_init function (attached bellow) and added ble_nus service initialization in services_init function.

void advertising_init(void)
{
    ret_code_t    err_code;
    ble_advdata_t advdata;
    ble_advdata_t srdata;

    ble_uuid_t adv_uuids[] = {{LBS_UUID_SERVICE, m_lbs.uuid_type}};

    // Build and set advertising data.
    memset(&advdata, 0, sizeof(advdata));

    advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    uint8_t       service_data[ADV_SERVICE_DATA_SIZE];
    memset(service_data, 0, ADV_SERVICE_DATA_SIZE);
    uint8_t       service_data_len = sizeof(service_data)/sizeof(service_data[0]);
    ble_advdata_service_data_t service_data_struct;
    advdata.p_service_data_array = &service_data_struct;    
    advdata.p_service_data_array->service_uuid = ADV_SERVICE_DATA_UUID;
    advdata.p_service_data_array->data.p_data = service_data;
    advdata.p_service_data_array->data.size   = service_data_len;
    advdata.service_data_count = 1;
    err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
    APP_ERROR_CHECK(err_code);

    ble_gap_adv_params_t adv_params;

    // Set advertising parameters.
    memset(&adv_params, 0, sizeof(adv_params));

    adv_params.primary_phy     = BLE_GAP_PHY_1MBPS;
    adv_params.duration        = APP_ADV_DURATION;
    adv_params.properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_params.p_peer_addr     = NULL;
    adv_params.filter_policy   = BLE_GAP_ADV_FP_ANY;
    adv_params.interval        = APP_ADV_INTERVAL; // TODO:get from profile  stm_state.config.normal_mode_options.ble_adv_interval

    err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
    APP_ERROR_CHECK(err_code);
}

Thanks.

Parents Reply Children
No Data
Related