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

How do you set Tx power for all power roles

I would like to set the tx power for all roles such that the nRF52840 (s140) never transmits anything above my specified level. This includes advertisements, past connections, future connections, etc.

I have the following code to accomplish this:

sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, BLE_CONN_HANDLE_INVALID, transmitPower);
sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_SCAN_INIT, BLE_CONN_HANDLE_INVALID, transmitPower);
sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, BLE_CONN_HANDLE_INVALID, transmitPower);

Does this cover everything? I don't want to have to set this for each connection/advertisement handle.

  •  

    Edit: Very sorry for the wrong answer. I was reminded of this by an application engineer & this answer relates to the mesh sdk. My bad for misreading your question. You are correct that the tx power should be set via the softdevice & not directly via the radio register.

    The proper answer: This is unfortunately not such a good idea. For the BLE_GAP_TX_POWER_ROLE_ADV, you should set the advertising handle after the advertising_init() function (see link for more info). For the BLE_GAP_TX_POWER_ROLE_SCAN_INIT, it seems the connection handle is ignored, so that should be fine. For the BLE_GAP_TX_POWER_ROLE_CONN role, you should set the connection handle after you get the CONNECTED event. See the softdevice documentation for more info.

    The old answer is left below (relevant to the Mesh SDK, not nRF 5 SDK): There have been quite a few questions & answers regarding this on the devzone, but unfortunately it is not possible to use sd_ble_gap_tx_power_set() to change the TX transmit power of the radio (for the Mesh SDK!).

    The radio_config_config() function in radio_config.c sets the transmit power of the radio. If you take a look at mesh sdk v2.1.1 with the light switch example (take provisioner for example), you can see that the advertiser_instance_init() function in advertiser.c calls set_default_broadcast_configuration(). This function sets the TX radio output power. Then, back in advertiser_instance_init(), the timeout_event callback is called. This function calls schedule_broadcast() if the broadcast context is inactive. Inside schedule_broadcast(), the broadcast_send() function is called, which starts the broadcast_start() callback function. It is broadcast_start() which then finally calls radio_config_config(), which sets the tx power:

    NRF_RADIO->TXPOWER = p_config->tx_power;

    To summarize: I believe you will only need to change the radio tx power in set_default_broadcast_configuration().

  • Thank you, I will try this. I don't have a set_default_broadcast_configuration() in my SDK (SDK15.0),  but I will try NRF_RADIO->TXPOWIER = power;

  • I am getting a memory access error when I try to set NRF_RADIO->TXPower = 0. Doesn't this need to be done through the soft device somehow?

  • Sorry for the wrong answer. I updated my first answer below.

Related