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
  • Hi,

    Error code 12292 = 0x3004 = BLE_ERROR_INVALID_ADV_HANDLE. The issue here is that you do not provide the correct advertising handle, which you get from the call to sd_ble_gap_adv_set_configure(). See this post.

  • thanks for reply, 

    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?

    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 ? 

  • 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.

Reply
  • 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.

Children
  • 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.

  • hi, 

    i am trying to set tx_power through scan response parameter,

    Tx power set through that but not continuosly it gives me one time 0 and one time 4dbm.

    srdata.p_tx_power_level = &m_tx_power;

    printf("after memset_srdata %d\t",&srdata);

    this parameter set in advertising_init() function.

    when data is update that time  err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &m_adv_params); return invalid state error.

    but i need to set tx_power continuously not need to change.

    I am trying to provide new array in advertising_upadate() but not set continuosly .

    please check the log file attached it. Mac_id of my device is Address: e9:98:e4:e3:ad:b1

    15:45:38.965 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f410000020001cdc00000000 
    15:45:38.965 ->  RSSI: -49 TxPower: 0
    15:45:39.287 -> Devices found: 2
    15:45:39.287 -> Scan done!
    15:45:39.407 -> Advertised Device: Name: , Address: 47:af:bd:6d:6b:cf, manufacturer data: 0600010920026c3227c22cdd301dc276a5350e365f64a95c4923e9cda2 
    15:45:39.407 ->  RSSI: -83 TxPower: 0
    15:45:40.007 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f510000020001cdc00000000, txPower: 4 
    15:45:40.007 ->  RSSI: -49 TxPower: 4
    15:45:40.287 -> Devices found: 2
    15:45:40.287 -> Scan done!
    15:45:40.407 -> Advertised Device: Name: , Address: 47:af:bd:6d:6b:cf, manufacturer data: 0600010920026c3227c22cdd301dc276a5350e365f64a95c4923e9cda2 
    15:45:40.407 ->  RSSI: -83 TxPower: 0
    15:45:41.007 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f610000020001cdc00000000 
    15:45:41.007 ->  RSSI: -49 TxPower: 0
    15:45:41.287 -> Devices found: 2
    15:45:41.287 -> Scan done!
    15:45:41.407 -> Advertised Device: Name: , Address: 47:af:bd:6d:6b:cf, manufacturer data: 0600010920026c3227c22cdd301dc276a5350e365f64a95c4923e9cda2 
    15:45:41.407 ->  RSSI: -82 TxPower: 0
    15:45:42.007 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f810000020001cdc00000000, txPower: 4 
    15:45:42.007 ->  RSSI: -49 TxPower: 4
    15:45:42.287 -> Devices found: 2
    15:45:42.287 -> Scan done!
    15:45:42.418 -> Advertised Device: Name: , Address: 47:af:bd:6d:6b:cf, manufacturer data: 0600010920026c3227c22cdd301dc276a5350e365f64a95c4923e9cda2 
    15:45:42.418 ->  RSSI: -86 TxPower: 0
    15:45:42.983 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f910000020001cdc00000000 
    15:45:42.983 ->  RSSI: -49 TxPower: 0
    15:45:43.303 -> Devices found: 2
    15:45:43.303 -> Scan done!
    15:45:43.417 -> Advertised Device: Name: , Address: 47:af:bd:6d:6b:cf, manufacturer data: 0600010920026c3227c22cdd301dc276a5350e365f64a95c4923e9cda2 
    15:45:43.417 ->  RSSI: -85 TxPower: 0
    15:45:44.020 -> Advertised Device: Name: , Address: e9:98:e4:e3:ad:b1, manufacturer data: 59000215454d422d3101000001f910000020001cdc00000000, txPower: 4 
    15:45:44.020 ->  RSSI: -50 TxPower: 4

Related