PER
(误包率检测)实验是Basic RF
的第二个实验,和无线点灯一样是没有使用协议栈的点对点通讯。
实验现象:两块WeBee
模块通信,一个模块作发射,另外一个模块接收,接收模块通过串口在PC
机上显示当前的误包率、RSSI
值和接收到数据包的个数。
void main ( void ) {
uint8 appMode;
appState = IDLE;
appStarted = TRUE;
/* Config basicRF 配置“Basic RF” */
basicRfConfig.panId = PAN_ID;
basicRfConfig.ackRequest = FALSE;
/* Initialise board peripherals 初始化外围硬件 */
halBoardInit();
/* Initalise hal_rf 初始化hal_rf */
if ( halRfInit() == FAILED ) {
HAL_ASSERT ( FALSE );
}
/* Indicate that device is powered */
halLedSet ( 1 );
/* Print Logo and splash screen on LCD */
utilPrintLogo ( "PER Tester" );
/* Wait for user to press S1 to enter menu */
halMcuWaitMs ( 350 );
/* Set channel 设置信道,规范要求信道只能为为11至25,这里选择信道11 */
basicRfConfig.channel = 0x0B;
#ifdef MODE_SEND /* 设置模块的模式,一个作为发射,另一个为接收,看是否“define MODE_SEND” */
appMode = MODE_TX;
#else
appMode = MODE_RX;
#endif
/* Transmitter application */
if ( appMode == MODE_TX ) {
/* No return from here 如果“define MODE_SEND”,则进入appTransmitter发射模式 */
appTransmitter();
} else if ( appMode == MODE_RX ) {
/* Receiver application */
/* No return from here 如果没有“define MODE_SEND”,则进入appReceiver接收模式 */
appReceiver();
}
HAL_ASSERT ( FALSE ); /* Role is undefined. This code should not be reached */
}
大家看注释也应该知道main.c
做了哪些事情:
- 一大堆的初始化(都是必须的)。
- 设置信道,发射和接收模块的信道必须一致。
- 选择为发射或者接收模式。
发射函数define MODE_SEND
则进入appTransmitter
:
static void appTransmitter() {
uint32 burstSize = 0;
uint32 pktsSent = 0;
uint8 appTxPower;
uint8 n;
/* Initialize BasicRF 初始化“Basic RF” */
basicRfConfig.myAddr = TX_ADDR;
if ( basicRfInit ( &basicRfConfig ) == FAILED ) {
HAL_ASSERT ( FALSE );
}
/* Set TX output power 设置输出功率 */
halRfSetTxPower ( 2 ); /* HAL_RF_TXPOWER_4_DBM */
/* Set burst size 设置进行一次测试所发送的数据包数量 */
burstSize = 1000;
/* Basic RF puts on receiver before transmission of packet, and turns off after packet is sent */
basicRfReceiveOff();
/* Config timer and IO 配置定时器和IO */
appConfigTimer ( 0xC8 );
/* Initalise packet payload 初始化数据包载荷 */
txPacket.seqNumber = 0;
for ( n = 0; n < sizeof ( txPacket