先将NODE_TYPE改为1(发送),然后可找一个标识为Status的盒子编译烧写此程序(断电) RF数据发送函数 void rfSendData(void) { uint8 pTxData[] = {"你好,我是发送端CC2530过来的数据!\r\n\r\n"}; uint8 ret; printf("send node start up...\r\n"); basicRfReceiveOff(); while(TRUE) { ret = basicRfSendPacket(RECV_ADDR, pTxData, sizeof pTxData); if (ret == SUCCESS) { hal_led_on(1); halMcuWaitMs(100); hal_led_off(1); halMcuWaitMs(900); } else { hal_led_on(1); halMcuWaitMs(1000); hal_led_off(1); } } } RF数据接收函数 1 void rfRecvData(void) 2 { 3 uint8 pRxData[128]; 4 int rlen; 5 6 7 printf("recv node start up...\r\n"); 8 9 basicRfReceiveOn(); 10 11 while(TRUE) 12 { 13 while(!basicRfPacketIsReady()); 14 rlen = basicRfReceive(pRxData, sizeof pRxData, NULL); 15 if(rlen > 0) 16 { 17 printf((char *)pRxData); 18 } 19 } 20 } 主函数 void main() { halMcuInit(); //MCU初始化 hal_led_init(); //LED初始化 hal_uart_init(); //Uart初始化 if(FAILED == halRfInit()) //CC2530-RF 初始化 { HAL_ASSERT(FALSE); } basicRfConfig.panId = PAN_ID; basicRfConfig.channel = RF_CHANNEL; basicRfConfig.ackRequest = TRUE; #if NODE_TYPE basicRfConfig.myAddr = SEND_ADDR; //(0x2530) #else basicRfConfig.myAddr = RECV_ADDR; //(0x2520) #endif if(basicRfInit(&basicRfConfig)==FAILED) { HAL_ASSERT(FALSE); } #if NODE_TYPE rfSendData(); #else rfRecvData(); #endif } 再将刚才烧写好的发送盒子拼接到接收盒子上开串口调试器后(两根线都连接收盒)进行跟踪结果如下:(接收盒子不断有数据过来)"你好,我是发送端CC2530过来的数据!"
|
|