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

Completely disabling bluetooth.

Hey!

I'm working on a device which requires Bluetooth to be completely disabled for short periods of time. It's got a sensor in it that's sensitive to 2.4 GHz radiation. Chip is nRF51822, SoftDevice is S110 v6.0.0.

I disable Bluetooth using the following code snippet:

	// If connected, disconnect
	if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
	{
		err_code = sd_ble_gap_disconnect(m_conn_handle,  BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
		if (err_code != NRF_SUCCESS) return err_code;
	}

	// Stop advertising
	err_code = sd_ble_gap_adv_stop();
	if (err_code != NRF_SUCCESS) return err_code;

And reenable later by calling advertising start.

Does disconnecting and stopping advertising completely shut down the radio or do I need to do something more low-level? I want to be as certain as possible that Bluetooth isn't interfering with the sensor.

Cheers,

Anne.

  • Here are my sleep and wake functions in case anyone else would find them useful.

    uint32_t bluetooth_sleep(void)
    {
    	uint32_t err_code;
    
    	// If connected, disconnect
    	if (m_conn_handle != BLE_CONN_HANDLE_INVALID)
    	{
    		err_code = sd_ble_gap_disconnect(m_conn_handle,  BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
    		if (err_code != NRF_SUCCESS) return err_code;
    	}
    
    	// Stop advertising
    	err_code = sd_ble_gap_adv_stop();
    	if (err_code != NRF_SUCCESS) return err_code;
    
    	// Disable the radio tasks as scytulip suggested
    	// devzone.nordicsemi.com/.../
    	NRF_RADIO->TASKS_DISABLE;
    
    	return NRF_SUCCESS;
    }
    
    uint32_t bluetooth_wake(void)
    {
    	uint32_t err_code;
    
    	err_code = advertising_start();
    	if (err_code != NRF_SUCCESS) return err_code;
    
    	return NRF_SUCCESS;
    }
    
  • I think you mean NRF_RADIO->TASKS_DISABLE = 1;

  • In addition to Jock Murphy's comment, you might need to add "NRF_RADIO->TASKS_DISABLE = 0;" in function "bluetooth_wake()"... From the specs it is not clear if implementation of the "advertising_start()" also enables the radio task.

  • Adding NRF_RADIO->TASK_DISABLE = 1 won't do anything for two reasons: First of all when the SoftDevice is enabled, the Radio registers are not accessible (unless using the Timeslot API), see here. Second the TASK_DISABLE is most likely connected to the END event through something called SHORTS in the RADIO registers. This means that the radio is automatically disabled when a packet is sent or received, meaning it will be disabled most of the time.

  • I reopened this case because the answers are not totally correct.

    First: The radio peripheral is blocked by the SoftDevice, so the call NRF_RADIO->TASK_DISABLE = 1 will not have any effect if the SoftDevice is enabled. Worst case it will lead to a hardfault. The peripherals that are used by the SoftDevice and either blocked or restricted can be seen here.

    Second: When the SoftDevice is done sending or receiving packets on the radio, it will call NRF_RADIO->TASK_DISABLE = 1, probably this is done automatically with PPI. It will also turn off the radio peripheral with NRF_RADIO->POWER = 0 to additionally save power. When it is going to send a packet it will turn the radio peripheral on and call NRF_RADIO->TASK_ENABLE = 1. Calling NRF_RADIO->TASK_DISABLE = 1in the meantime will not change this.

    To know that the radio is off, you have to make sure that you are not in a connection and not advertising. You can disable the SoftDevice also, but this is not necessary.

Related