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

shutdown BLE_peripheral

this is my code: this is BLE_peripheral UART and i added these lines to main(): my soft device is S130 V2 alpha

// Initialize.
APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_OP_QUEUE_SIZE, false);
uart_init();
buttons_leds_init(&erase_bonds);
ble_stack_init();
gap_params_init();
services_init();
advertising_init();
conn_params_init();

printf("%s",start_string);

err_code = ble_advertising_start(BLE_ADV_MODE_FAST);

APP_ERROR_CHECK(err_code);

// Enter main loop.
for (;;)
{
    int i = 0;
    for(i=0;i<95000000;i++);//delay
    NRF_RADIO->TASKS_DISABLE = 1;
    NRF_RADIO->TASKS_STOP = 1;
	NVIC_DisableIRQ(RTC1_IRQn);
    err_code = sd_ble_gap_disconnect(m_conn_handle, BLE_HCI_REMOTE_DEV_TERMINATION_DUE_TO_POWER_OFF);
    NRF_RADIO->POWER = 0;
    sd_ble_gap_rssi_stop(m_conn_handle);
    printf("A");
    sd_ble_gap_adv_stop();
    for(i=0;i<95000000;i++);//delay
    err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
    printf("b");
    power_manage();
}

it stops advertising but not disconnect from central and I can send or receive data

I want to turn off BLE and turn it on when I want but I don't know how?

Parents
  • Hi Ali,

    On the condition that you want to shutdown BLE you can just call sd_softdevice_disable.

    If you want to re enable, then enable the softdevice and ble using the example functions like ble_stack_init

    static void ble_stack_init(void)
    {
        uint32_t err_code;
        
        nrf_clock_lf_cfg_t clock_lf_cfg = NRF_CLOCK_LFCLKSRC;
        
        // Initialize the SoftDevice handler module.
        SOFTDEVICE_HANDLER_INIT(&clock_lf_cfg, NULL);
    
        ble_enable_params_t ble_enable_params;
        err_code = softdevice_enable_get_default_config(CENTRAL_LINK_COUNT,
                                                        PERIPHERAL_LINK_COUNT,
                                                        &ble_enable_params);
        APP_ERROR_CHECK(err_code);
    
        // Check the ram settings against the used number of links
        CHECK_RAM_START_ADDR(CENTRAL_LINK_COUNT, PERIPHERAL_LINK_COUNT);
    
        // Enable BLE stack.
        err_code = softdevice_enable(&ble_enable_params);
        APP_ERROR_CHECK(err_code);
    
        // Register with the SoftDevice handler module for BLE events.
        err_code = softdevice_ble_evt_handler_set(ble_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    
        // Register with the SoftDevice handler module for BLE events.
        err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
        APP_ERROR_CHECK(err_code);
    }
    

    The documentation for each functions can be found in Nordic infocenter.

  • Hi, when i do sd_softdevice_disable the register is not deinit, the BLE is just in standby. I need to fully deinit because i use a soft with DFU and BEACON. and i can't use 2 in same time. I will deinit fully de BEACON for use DFU without problem. For the moment i can use the DFU independently, and use the Beacon independently but i can't use BEACON and after push button switch into DFU mode.

Reply
  • Hi, when i do sd_softdevice_disable the register is not deinit, the BLE is just in standby. I need to fully deinit because i use a soft with DFU and BEACON. and i can't use 2 in same time. I will deinit fully de BEACON for use DFU without problem. For the moment i can use the DFU independently, and use the Beacon independently but i can't use BEACON and after push button switch into DFU mode.

Children
No Data