|
问题1:nRF52xx默认发射功率是多少?
解答:nRF52832、nRF52810、nRF52840的默认发射功率都是0dBm,也就是如果您没有修改过发射功率,除非特殊说明,否则实验例子使用的发射都是默认值0dBm。
问题2:如何修改发射功率?
解答:各个版本的协议栈修改发射功率有所不同,这里以6.xx版本的协议栈为例说明修改的方法。6.xx版本的协议栈修改发射功率时需要根据角色去修改,也就是广播、连接和扫描的发射功率是分开改的,这种做法无疑增加了程序应用的灵活性,下面是修改的示例。
示例1:BLE串口透传中修改广播发射功率为-40dBm。
- int main(void)
- {
- bool erase_bonds;
- // Initialize.
- uart_init();
- log_init();
- timers_init();
- buttons_leds_init(&erase_bonds);
- power_management_init();
- ble_stack_init();
- gap_params_init();
- gatt_init();
- services_init();
- advertising_init();
- conn_params_init();
- // Start execution.
- printf("\r\nUART started.\r\n");
- NRF_LOG_INFO("Debug logging for UART over RTT started.");
-
- //设置广播的发射功率为-40dBm
- //nRF52832可设置的值为:4,3,0,-4,-8,-12,-16,-20,-30,-40
- //nRF52840可设置的值为:8,7,6,5,4,3,2,0,-4,-8,-12,-16,-20,-30,-40
- uint32_t err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_ADV, m_advertising.adv_handle, -40);
- APP_ERROR_CHECK(err_code);
-
- advertising_start();
- // Enter main loop.
- for (;;)
- {
- idle_state_handle();
- }
- }
复制代码 示例2:BLE串口透传中修改连接发射功率为4dBm。
- static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
- {
- uint32_t err_code;
- switch (p_ble_evt->header.evt_id)
- {
- case BLE_GAP_EVT_CONNECTED:
- NRF_LOG_INFO("Connected");
- err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
- APP_ERROR_CHECK(err_code);
- m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
- err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
- APP_ERROR_CHECK(err_code);
-
- //设置连接的发射功率为4dBm
- //nRF52832可设置的值为:4,3,0,-4,-8,-12,-16,-20,-30,-40
- //nRF52840可设置的值为:8,7,6,5,4,3,2,0,-4,-8,-12,-16,-20,-30,-40
- err_code = sd_ble_gap_tx_power_set(BLE_GAP_TX_POWER_ROLE_CONN, m_conn_handle, 4);
- APP_ERROR_CHECK(err_code);
- break;
- case BLE_GAP_EVT_DISCONNECTED:
- NRF_LOG_INFO("Disconnected");
- // LED indication will be changed when advertising starts.
- m_conn_handle = BLE_CONN_HANDLE_INVALID;
- break;
- case BLE_GAP_EVT_PHY_UPDATE_REQUEST:
- {
- NRF_LOG_DEBUG("PHY update request.");
- ble_gap_phys_t const phys =
- {
- .rx_phys = BLE_GAP_PHY_AUTO,
- .tx_phys = BLE_GAP_PHY_AUTO,
- };
- err_code = sd_ble_gap_phy_update(p_ble_evt->evt.gap_evt.conn_handle, &phys);
- APP_ERROR_CHECK(err_code);
- } break;
- case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
- // Pairing not supported
- err_code = sd_ble_gap_sec_params_reply(m_conn_handle, BLE_GAP_SEC_STATUS_PAIRING_NOT_SUPP, NULL, NULL);
- APP_ERROR_CHECK(err_code);
- break;
- case BLE_GATTS_EVT_SYS_ATTR_MISSING:
- // No system attributes have been stored.
- err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0, 0);
- APP_ERROR_CHECK(err_code);
- break;
- case BLE_GATTC_EVT_TIMEOUT:
- // Disconnect on GATT Client timeout event.
- err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gattc_evt.conn_handle,
- BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
- APP_ERROR_CHECK(err_code);
- break;
- case BLE_GATTS_EVT_TIMEOUT:
- // Disconnect on GATT Server timeout event.
- err_code = sd_ble_gap_disconnect(p_ble_evt->evt.gatts_evt.conn_handle,
- BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
- APP_ERROR_CHECK(err_code);
- break;
- default:
- // No implementation needed.
- break;
- }
- }
复制代码
|
|