Other Parts Discussed in Thread: CC1352P
rfEchoTx和rfEchoRx的分别会有一个接收信号强度,我用这个接收信号强度为条件,控制一个IO口的输出值作为射频开关的切换条件,当接收信号强度降低一定阈值后,缩短发送时间,并变换IO值,一共进行四次,选择四次中接收信号强度最高的那次IO输出值作为继续正常发送状态的开关值,我对rfEchoTx代码进行了以下改动:
#define PACKET_INTERVAL_CHANGE (uint32_t)(4000000*0.5f)定义了缩短发送时间的时间间隔0.5s;
/* Get current time */ curtime = RF_getCurrentTime(); int state = 0;//If the state is 1, normal communication is corrected, and the state switch is 0.With an initial value of 0, initialization begins float LastRssi = -300;//Record the last received signal strength, the initial value is a small value int maxAnt = 0;//天线端口选择信号,0_ant00,1_ant01,2_ant10,3_ant11定义state表示当前是正常发送时间间隔还是缩短发送时间间隔,LastRssi记录上一次接收到的接收信号强度;
while(1) { /* Create packet with incrementing sequence number and random payload */ if(state){ txPacket[0] = (uint8_t)(seqNumber >> 8); txPacket[1] = (uint8_t)(seqNumber++); uint8_t i; for (i = 2; i < PAYLOAD_LENGTH; i++) { txPacket[i] = rand(); } /* Set absolute TX time to utilize automatic power management */ curtime += PACKET_INTERVAL; RF_cmdPropTx.startTime = curtime; //GPIO_toggle(CONFIG_GPIO_0); //uint8_t ant = GPIO_read(CONFIG_GPIO_0); /* Transmit a packet and wait for its echo. * - When the first of the two chained commands (TX) completes, the * RF_EventCmdDone event is raised but not RF_EventLastCmdDone * - The RF_EventLastCmdDone in addition to the RF_EventCmdDone events * are raised when the second, and therefore last, command (RX) in the * chain completes * -- If the RF core successfully receives the echo it will also raise * the RF_EventRxEntryDone event * -- If the RF core times out while waiting for the echo it does not * raise the RF_EventRxEntryDone event */ RF_EventMask terminationReason = RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropTx, RF_PriorityNormal, echoCallback, (RF_EventCmdDone | RF_EventRxEntryDone | RF_EventLastCmdDone)); if(rxStatistics.lastRssi < LastRssi -30 ){ state = 0; LastRssi = rxStatistics.lastRssi; } else{ state = 1; LastRssi = rxStatistics.lastRssi; } } else{ int currAnt = 0;//Current antenna status(0_ant00,1_ant01,2_ant10,3_ant11) float currRssi; float maxRssi; txPacket[0] = (uint8_t)(seqNumber >> 8); txPacket[1] = (uint8_t)(seqNumber++); uint8_t a; for (a = 2; a < PAYLOAD_LENGTH; a++) { txPacket[a] = 0; } GPIO_write(CONFIG_GPIO_0,0); curtime += PACKET_INTERVAL_CHANGE; RF_cmdPropTx.startTime = curtime; RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, echoCallback, (RF_EventRxEntryDone | RF_EventLastCmdDone)); currRssi = rxStatistics.lastRssi; maxRssi = currRssi; maxAnt = currAnt; currAnt++; txPacket[0] = (uint8_t)(seqNumber >> 8); txPacket[1] = (uint8_t)(seqNumber++); uint8_t b; for (b = 2; b < PAYLOAD_LENGTH; b++) { txPacket[b] = 3; } curtime += PACKET_INTERVAL_CHANGE; RF_cmdPropTx.startTime = curtime; RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, echoCallback, (RF_EventRxEntryDone | RF_EventLastCmdDone)); currRssi = rxStatistics.lastRssi; if(currRssi>maxRssi){ maxRssi = currRssi; maxAnt = currAnt; } currAnt++; txPacket[0] = (uint8_t)(seqNumber >> 8); txPacket[1] = (uint8_t)(seqNumber++); uint8_t c; for (c = 2; c < PAYLOAD_LENGTH; c++) { txPacket[c] = 2; } GPIO_write(CONFIG_GPIO_0,0); curtime += PACKET_INTERVAL_CHANGE; RF_cmdPropTx.startTime = curtime; RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, echoCallback, (RF_EventRxEntryDone | RF_EventLastCmdDone)); currRssi = rxStatistics.lastRssi; if(currRssi>maxRssi){ maxRssi = currRssi; maxAnt = currAnt; } currAnt++; txPacket[0] = (uint8_t)(seqNumber >> 8); txPacket[1] = (uint8_t)(seqNumber++); uint8_t d; for (d = 2; d < PAYLOAD_LENGTH; d++) { txPacket[d] = 3; } GPIO_write(CONFIG_GPIO_0,1); curtime += PACKET_INTERVAL_CHANGE; RF_cmdPropTx.startTime = curtime; RF_runCmd(rfHandle, (RF_Op*)&RF_cmdPropRx, RF_PriorityNormal, echoCallback, (RF_EventRxEntryDone | RF_EventLastCmdDone)); currRssi = rxStatistics.lastRssi; if(currRssi>maxRssi){ maxRssi = currRssi; maxAnt = currAnt; } state = 1; if(maxAnt < 2){ GPIO_write(CONFIG_GPIO_0,0);//Set the antenna optimally } else{ GPIO_write(CONFIG_GPIO_0,1); } }然后在进行发送时,初始state变量为0,进入到缩短时间间隔的发送状态,然后进行四次发送,完成后state置为1,下次进入到正常时间间隔的发送状态;
我的问题,当我开始发送时,进入到缩短时间间隔的发送状态后,无法接收到由RX端回传回来的数据,TX板子的红灯常亮,直到四次发送完成退出缩短发生时间间隔后的状态,接收回传信号就正常了,请问会是什么问题呢?