nRF51822和nRF52832 广播功率设置

1、nRF51822 广播包的设置(SDK12.3.0):

/**@brief Set the radio's transmit power.
 *
 * @param[in] tx_power Radio transmit power in dBm (accepted values are -40, -30, -20, -16, -12, -8, -4, 0, and 4 dBm).
 *
 * @note The -30dBm setting is only available on nRF51 series ICs.
 * @note The -40dBm setting is only available on nRF52 series ICs.
 *
 * @retval ::NRF_SUCCESS Successfully changed the transmit power.
 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
 */
SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(int8_t tx_power));

1.1、在需要设置的地方加上sd_ble_gap_tx_power_set(int8_t tx_power); tx_power形参的值分别:-30, -20, -16, -12, -8, -4, 0, and 4 dBm,值越大信号越强。

2、nRF52832 广播包的设置(SDK15.0.0):

/**@brief Set the radio's transmit power.
 *
 * @param[in] role The role to set the transmit power for, see @ref BLE_GAP_TX_POWER_ROLES for
 *                 possible roles.
 * @param[in] handle   The handle parameter is interpreted depending on role:
 *                     - If role is @ref BLE_GAP_TX_POWER_ROLE_CONN, this value is the specific connection handle.
 *                     - If role is @ref BLE_GAP_TX_POWER_ROLE_ADV, the advertising set identified with the advertising handle,
 *                       will use the specified transmit power, and include it in the advertising packet headers if
 *                       @ref ble_gap_adv_properties_t::include_tx_power set.
 *                     - For all other roles handle is ignored.
 * @param[in] tx_power Radio transmit power in dBm (see note for accepted values).
 *
  * @note Supported tx_power values: -40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.
  * @note The initiator will have the same transmit power as the scanner.
 * @note When a connection is created it will inherit the transmit power from the initiator or
 *       advertiser leading to the connection.
 *
 * @retval ::NRF_SUCCESS Successfully changed the transmit power.
 * @retval ::NRF_ERROR_INVALID_PARAM Invalid parameter(s) supplied.
 * @retval ::BLE_ERROR_INVALID_ADV_HANDLE Advertising handle not found.
 * @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid connection handle supplied.
 */
SVCALL(SD_BLE_GAP_TX_POWER_SET, uint32_t, sd_ble_gap_tx_power_set(uint8_t role, uint16_t handle, int8_t tx_power));

以广播为例:设置的时候一定在开启广播之后,否则返回错误BLE_ERROR_INVALID_ADV_HANDLE,如果设置tx_power的参数不在这个范围-40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.返回错误NRF_ERROR_INVALID_PARAM

2.1、单通道广播时候

(1)第一个参数是对应角色的功耗

  BLE_GAP_TX_POWER_ROLE_ADV       = 1,           /**< Advertiser role. */广播发射(从机)
  BLE_GAP_TX_POWER_ROLE_SCAN_INIT = 2,           /**< Scanner and initiator role. */扫描和发起者发射(主机)
  BLE_GAP_TX_POWER_ROLE_CONN      = 3,           /**< Connection role. */连接

(2)第二个参数对应角色的句柄

nRF51822和nRF52832 广播功率设置_第1张图片

开启广播之后的句柄有效:m_advertising.adv_handle

(3)第三个参数功率的级别:-40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.填写对应的数字,值越大信号越强。

err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle , 4); APP_ERROR_CHECK(err_code);

2.2、多通道广播时候

1)第一个参数是对应角色的功耗

  BLE_GAP_TX_POWER_ROLE_ADV       = 1,           /**< Advertiser role. */广播发射(从机)
  BLE_GAP_TX_POWER_ROLE_SCAN_INIT = 2,           /**< Scanner and initiator role. */扫描和发起者发射(主机)
  BLE_GAP_TX_POWER_ROLE_CONN      = 3,           /**< Connection role. */连接

(2)第二个参数对应角色的句柄

nRF51822和nRF52832 广播功率设置_第2张图片

开启广播之后的句柄有效:m_adv_handle

(3)第三个参数功率的级别:-40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.填写对应的数字,值越大信号越强。

err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_adv_handle , 4); APP_ERROR_CHECK(err_code);

你可能感兴趣的:(NRF52832,NRF51822)