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

Changing the Tx Power in sdk 15.2.0

Hello,

I am trying to change the tx power for my nRF52-DK which is having nRF52832 chip. I trying the following code to change the tx power to -40 dB.

    int8_t tx_power_level = -40;

    init.advdata.p_tx_power_level = &tx_power_level;

    sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, tx_power_level);

I have added the following lines of code to the advertising_init() function. 

Please help, I am a beginner.

Thanks in advance. 

Parents
  •       Hi.

    There is an example which demonstrates how to change the TX power, the example is found in examples\ble_peripheral\ble_app_proximity\main.c

    If you look at this example, the TX power is changed in the function tx_power_set(void), which is called after the advertising_start(erase_bonds) function, which again is called after the advertising is initialised in the advertising_init() function.

    The tx_power_set(void) function looks like this:

    /**@brief Function for changing the tx power.
     */
    static void tx_power_set(void)
    {
        ret_code_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL);
        APP_ERROR_CHECK(err_code);
    }


    You can use this function, and you also need to define the TX_POWER_LEVEL in your main.c file like this:

    #define TX_POWER_LEVEL                  (-40)

    The main(void) function of the example, examples\ble_peripheral\ble_app_proximity, looks like this:


    /**@brief Function for application main entry.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        adc_configure();
        gap_params_init();
        gatt_init();
        advertising_init();
        db_discovery_init();
        services_init();
        conn_params_init();
        peer_manager_init();
    
        // Start execution.
        NRF_LOG_INFO("Proximity example started.");
        advertising_start(erase_bonds);
        tx_power_set();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }


    Here you see that the TX power is changed at the bottom before the main loop, by the function call tx_power_set();.

    Hope this helps.

    Best regards.

    Andreas

Reply
  •       Hi.

    There is an example which demonstrates how to change the TX power, the example is found in examples\ble_peripheral\ble_app_proximity\main.c

    If you look at this example, the TX power is changed in the function tx_power_set(void), which is called after the advertising_start(erase_bonds) function, which again is called after the advertising is initialised in the advertising_init() function.

    The tx_power_set(void) function looks like this:

    /**@brief Function for changing the tx power.
     */
    static void tx_power_set(void)
    {
        ret_code_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, TX_POWER_LEVEL);
        APP_ERROR_CHECK(err_code);
    }


    You can use this function, and you also need to define the TX_POWER_LEVEL in your main.c file like this:

    #define TX_POWER_LEVEL                  (-40)

    The main(void) function of the example, examples\ble_peripheral\ble_app_proximity, looks like this:


    /**@brief Function for application main entry.
     */
    int main(void)
    {
        bool erase_bonds;
    
        // Initialize.
        log_init();
        timers_init();
        buttons_leds_init(&erase_bonds);
        power_management_init();
        ble_stack_init();
        adc_configure();
        gap_params_init();
        gatt_init();
        advertising_init();
        db_discovery_init();
        services_init();
        conn_params_init();
        peer_manager_init();
    
        // Start execution.
        NRF_LOG_INFO("Proximity example started.");
        advertising_start(erase_bonds);
        tx_power_set();
    
        // Enter main loop.
        for (;;)
        {
            idle_state_handle();
        }
    }


    Here you see that the TX power is changed at the bottom before the main loop, by the function call tx_power_set();.

    Hope this helps.

    Best regards.

    Andreas

Children
Related