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

How to set tx_power using sd_ble_gap_tx_power_set() on nrf52832?

Hi Everyone,

I am working on nrf52832, I am using sdk15.0.0 ble_peripheral /ble_app_beacon as reference.

I want to set TX_POWER using sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV,m_adv_handle,RADIO_TXPOWER_TXPOWER_Pos4dBm);

  m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;

when I called this function after the ble_advertising function,err_code return 12292.

actually i am not understood BLE_GAP_ADV_SET_HANDLE_NOT_SET=0xFF.

Initially tx_power set to 4dbm but when softdevice enable getting error (code stuck at blx ,r3).

I am also trying using NRF_RADIO->TX_POWER=RADIO_TXPOWER_TXPOWER_Pos4dBm;

Register initially set to 4dbm but after call ble_stack_init() it set to 0dbm.When you change txpower, you need to update this value of the advertising data, it doesn't get updated automatically by the softdevice. 

 I think I forgot some configuration in my code, Can you suggest a proper solution to see the changes in TXPOWER.

thanks.

Parents Reply Children
  • dewal said:

    i am passing below parameter, 

    err_code = sd_ble_gap_adv_set_configure(&(m_adv_handle), &m_adv_data, &m_adv_params);

    Is this wrong?

    Yes, from your original post I see this is BLE_GAP_ADV_SET_HANDLE_NOT_SET, so it will not be valid. You need to use the advertising handle you get returned when you configure the advertiser.

    dewal said:

    I want to set TX_POWER using sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV,m_adv_handle,RADIO_TXPOWER_TXPOWER_Pos4dBm);

    This function called after the advertising_start() .

    Is this right way to set the tx_power ? 

    If m_adv_handle is set by the call to sd_ble_gap_adv_set_configure(), then this should be OK. But you must keep that value and not set it to BLE_GAP_ADV_SET_HANDLE_NOT_SET. The advertising handle will be 0, as only one set is supported, so you could also just hard code to that to see that it works.

  • thanks for reply,

    can you please provide any example for passing this parameter correctly.

    actually i am not understood which handler parameter need to set for this function work properly.

    please someone help me.

  • Hi,

    This diff shows exactly how you can set the Tx power of the beacon example in SDK 15.0.0:

    diff --git a/examples/ble_peripheral/ble_app_beacon/main.c b/examples/ble_peripheral/ble_app_beacon/main.c
    index e8ddfe0..c767dfb 100644
    --- a/examples/ble_peripheral/ble_app_beacon/main.c
    +++ b/examples/ble_peripheral/ble_app_beacon/main.c
    @@ -198,6 +198,9 @@ static void advertising_init(void)
     
         err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params);
         APP_ERROR_CHECK(err_code);
    +
    +    err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_adv_handle,RADIO_TXPOWER_TXPOWER_Pos4dBm);
    +    APP_ERROR_CHECK(err_code);
     }
     
     
    

  • thanks for reply,

    after above setting err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params); err_code return 6.

    please help me for setting tx_power using default  gap function.

  • Hi, 

    ande_dewal said:
    after above setting err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params); err_code return 6.

    I did not intend to suggest that you make any changes in your call to sd_ble_gap_adv_set_configure().  The point is just that you take the advertising handle you get from there (or even 0 as that is what it will be), and use that in the call to sd_ble_gap_tx_power_set(). Regarding the error 6 is NRF_ERROR_NOT_SUPPORTED, which means that the configuration or length you provide is invalid. If this was working in your code before, then just keep what you had. 

    ande_dewal said:
    please help me for setting tx_power using default  gap function.

    The default (and only) function to set the Tx power is sd_ble_gap_tx_power_set(), and to set the Tx power for advertising you use it as shown in my previous post.

Related