nrf51822 如何更改发射功率

当使用softdevice时,可以调用函数:sd_ble_gap_tx_power_set

uint32_t sd_ble_gap_tx_power_set(int8_t 	tx_power)	
Set the radio's transmit power.

Parameters
[in]	tx_power	Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm).
Note
-40 dBm will not actually give -40 dBm, but will instead be remapped to -30 dBm.
Returns
NRF_SUCCESS Successfully changed the transmit power.
NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
NRF_ERROR_BUSY The stack is busy, process pending events and retry.

使用这个函数可以随时随地的更改发射功率,即使已经开始了广播。

在gap_params_init() 函数中调用!!或者在需要的地方调用!!!

/**@brief Function for the GAP initialization.
 *
 * @details This function sets up all the necessary GAP (Generic Access Profile) parameters of the
 *          device including the device name, appearance, and the preferred connection parameters.
 */
static void gap_params_init(void)
{
    uint32_t                err_code;
    ble_gap_conn_params_t   gap_conn_params;
    ble_gap_conn_sec_mode_t sec_mode;

    BLE_GAP_CONN_SEC_MODE_SET_OPEN(&sec_mode);

    err_code = sd_ble_gap_device_name_set(&sec_mode,
                                          (const uint8_t *)DEVICE_NAME,
                                          strlen(DEVICE_NAME));
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_appearance_set(BLE_APPEARANCE_GENERIC_KEYRING);
    APP_ERROR_CHECK(err_code);

    memset(&gap_conn_params, 0, sizeof(gap_conn_params));

    gap_conn_params.min_conn_interval = MIN_CONN_INTERVAL;
    gap_conn_params.max_conn_interval = MAX_CONN_INTERVAL;
    gap_conn_params.slave_latency     = SLAVE_LATENCY;
    gap_conn_params.conn_sup_timeout  = CONN_SUP_TIMEOUT;

    err_code = sd_ble_gap_ppcp_set(&gap_conn_params);
    APP_ERROR_CHECK(err_code);

    err_code = sd_ble_gap_tx_power_set(TX_POWER_LEVEL);
    APP_ERROR_CHECK(err_code);
}



你可能感兴趣的:(nrf51822)