dBm和mW对照表和nRF52发射功率配置

在这里插入图片描述

nRF52发射功率配置

#define TX_POWER_LEVEL                  (-8)  //Supported tx_power values: -40dBm, -20dBm, -16dBm, -12dBm, -8dBm, -4dBm, 0dBm, +3dBm and +4dBm.
/**@brief Function for initializing the Advertising functionality.
 *
 * @details Encodes the required advertising data and passes it to the stack.
 *          Also builds a structure to be passed to the stack when starting advertising.
 */
static void advertising_init(void)
{
    uint32_t               err_code;
    ble_advertising_init_t init;
    int8_t        tx_power_level = TX_POWER_LEVEL;//设置发射功率
    memset(&init, 0, sizeof(init));
    init.advdata.name_type          = BLE_ADVDATA_FULL_NAME;
    init.advdata.include_appearance = false;
    //设备需要一直广播不休眠,必须设置为普通发现模式
    init.advdata.flags              = BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE;//蓝牙设备模式
	init.advdata.p_tx_power_level        = &tx_power_level;
    init.srdata.uuids_complete.uuid_cnt = sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
    init.srdata.uuids_complete.p_uuids  = m_adv_uuids;
    init.config.ble_adv_fast_enabled  = true;
    init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;//广播间隔
    //注释后不进入IDLE无效模式
    //init.config.ble_adv_fast_timeout  = APP_ADV_DURATION;//广播超时 
    init.evt_handler = on_adv_evt;
    err_code = ble_advertising_init(&m_advertising, &init);
    APP_ERROR_CHECK(err_code);
    ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
}

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);
}

获取接收信号强度RSSI

	int8_t rssi=0;
	uint8_t p_ch_index;

	sd_ble_gap_rssi_start(m_conn_handle,BLE_GAP_RSSI_THRESHOLD_INVALID,0);
	sd_ble_gap_rssi_get(m_conn_handle, &rssi,&p_ch_index);
	//	    sd_ble_gap_rssi_stop(m_conn_handle);
	NRF_LOG_INFO("rssi: %d",rssi);
	NRF_LOG_INFO("Channel: %d",p_ch_index);
发布了49 篇原创文章 · 获赞 30 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/liurunjiang/article/details/104695733