本篇博文最后修改时间:2017年06月02日,02:58。
一、简介
本文以SimpleBLEPeripheral工程为例,介绍如何在工程中修改发射功率。
二、实验平台
协议栈版本:ble_cc26xx_2_01_00_44423
编译软件:IAR Embedded Workbench for ARM Version 7.40
硬件平台:CC26xxDK开发板
仿真器:XDS100V3(香瓜)
三、版权声明
博主:甜甜的大香瓜
声明:喝水不忘挖井人,转载请注明出处。
原文地址:http://blog.csdn.NET/feilusia
联系方式:[email protected]
香瓜BLE之CC2541群:127442605
香瓜BLE之CC2640群:557278427
香瓜BLE之Android群:541462902
//设置发射功率
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_21_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_18_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_15_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_12_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_9_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_6_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_3_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_1_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_2_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_3_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_4_DBM);
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_5_DBM);
由上述代码的形参可知CC2640一共有13个档。
static uint8 sTxPowerStatus = 0;
#define sTxPowerStatus_MINUS_21_DBM 0
#define sTxPowerStatus_MINUS_18_DBM 1
#define sTxPowerStatus_MINUS_15_DBM 2
#define sTxPowerStatus_MINUS_12_DBM 3
#define sTxPowerStatus_MINUS_9_DBM 4
#define sTxPowerStatus_MINUS_6_DBM 5
#define sTxPowerStatus_MINUS_3_DBM 6
#define sTxPowerStatus_0_DBM 7
#define sTxPowerStatus_1_DBM 8
#define sTxPowerStatus_2_DBM 9
#define sTxPowerStatus_3_DBM 10
#define sTxPowerStatus_4_DBM 11
#define sTxPowerStatus_5_DBM 12
static void GUA_HandleKeys(uint8 keys)
{
//SELECT键
if ( keys & KEY_SELECT )
{
switch(sTxPowerStatus)
{
case sTxPowerStatus_MINUS_21_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_21_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_18_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_18_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_15_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_15_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_12_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_12_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_9_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_9_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_6_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_6_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_MINUS_3_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_3_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_0_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_1_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_1_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_2_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_2_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_3_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_3_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_4_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_4_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus++; //指向下一个发射功率
break;
}
case sTxPowerStatus_5_DBM:
{
HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_5_DBM); //设置发射功率
GUA_Led_Set(HAL_LED_1, HAL_LED_MODE_TOGGLE); //LED1反转一次
sTxPowerStatus = 0; //指向下一个发射功率,回首位重复
break;
}
default:break;
}
}
}
香瓜在这里添加了按键修改发射功率的测试代码,进行测试发射功率的进一步测试。
//设置发射功率(默认-54~-56dB)
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_21_DBM); //-75~-78dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_18_DBM); //-74~-79dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_15_DBM); //-72~-76dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_12_DBM); //-71~-76dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_9_DBM); //-62~-70dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_6_DBM); //-62~-64dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_MINUS_3_DBM); //-59~-61dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_0_DBM); //-55~-61dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_1_DBM); //-54~-58dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_2_DBM); //-51~-55dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_3_DBM); //-52~-56dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_4_DBM); //-48~-52dB
//HCI_EXT_SetTxPowerCmd(HCI_EXT_TX_POWER_5_DBM); //-48~-52dB