ADI 技术
直播中

刘建国

8年用户 204经验值
私信 关注
[问答]

ADUCRF101通信距离很短

发送端代码:
int main(void)
{
  int data[12]={0};
  RIE_Responses RIE_Response = RIE_Success;
  WdtGo(T3CON_ENABLE_DIS);
            //uart-----start
            Urt_Init(UART_BAUD_19200);
          Urt_PinSetup(FALSE);   
          printf("**************************rn");
          printf("rn    TX发送端初始化完成 rn");
          printf("**************************rn");
            //uart-----end
  // Initialise the Radio
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioInit(DR_38_4kbps_Dev19_2kpbs);      
  // Set the Frequency to operate at 915 MHz
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioSetFrequency(915000000);
  // Set the PA and Power Level
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioTxSetPA(DifferentialPA,PowerLevel15);
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioTxPacketFixedLen(12, "HELLO WORLD");
  printf("n输入要发送的数据:");
  while (1)
  {   
    Delay1();
    RadioTxPacketFixedLen(12, "hello 123456");
  }
}

接收端代码:
int main(void)
{
  unsigned char  Buffer[0x20];
  RIE_U8         PktLen;
  RIE_S8         RSSI;
  
  RIE_U8 flag=0;


  RIE_Responses RIE_Response = RIE_Success;
  WdtGo(T3CON_ENABLE_DIS);
          //---------------UART code start---------------------
          Urt_Init(UART_BAUD_19200);
          Urt_PinSetup(FALSE);
          printf("rn**************************rn");
          printf("rn    RX接收端初始化完成!nr");
          printf("rn**************************rn");
          //-----------------UART code end---------------------
  
  // Initialise the Radio
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioInit(DR_38_4kbps_Dev19_2kpbs);      
  // Set the Frequency to operate at 915 MHz
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioSetFrequency(915000000);
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioRxPacketFixedLen(12);


          printf("nr正在接收数据nr");
  if (RIE_Response == RIE_Success)
     {
               while (!RadioRxPacketAvailable());
     }
  if (RIE_Response == RIE_Success)
     RIE_Response = RadioRxPacketRead(sizeof(Buffer),
                                      &PktLen,
                                      Buffer,
                                      &RSSI);


  if (RIE_Response == RIE_Success)
     printf("nr-> %s @ RSSI %d",Buffer,(int)RSSI);
  else
     printf("nr-> ERROR");
  while(1)
  {
          //-------------接收数据----------------
          RIE_Response = RadioRxPacketFixedLen(12);
          if (RIE_Response == RIE_Success)
               {
                         while (!RadioRxPacketAvailable());
               }
          if (RIE_Response == RIE_Success)
                         RIE_Response = RadioRxPacketRead(sizeof(Buffer),
                                      &PktLen,
                                      Buffer,
                                      &RSSI);
          //--------------------------------------  
          printf("nr收到的数据:%s RSSI:%d",Buffer,(int)RSSI);
  }
}

发送端和接收端的代码如上所附,通信时通信距离只有十几厘米,是不是有需要
注意的地方我没有注意到,期待解答。

回帖(1)

更多回帖

发帖
×
20
完善资料,
赚取积分