我在使用CC2500模块的时候,在多对一的RF系统中,为了避免发送时的冲撞,发送端需要先判断信道是否为空。但是我在调试了2个礼拜之后发现CCA的值一直不变cca = TI_CC_GDO2_PxIN & TI_CC_GDO2_PIN ; cca的值一直检测到为0。 所以我怀疑我的调试方法有误,希望使用过CCA功能的朋友,能给我指点下调试方法。如能有事例程序,那更加感激不尽。在此先行谢过各位!
Yue TANG:
参考simpliciTI协议栈中的MRFI_Transmit()函数。
JiaoXiaojun Jiao Xiao jun:
回复 Yue TANG:
请问一下这个在哪里可以找到simpliciTI协议栈的程序啊,我照了半天了,能不能提供一个详细的连接地址,谢谢了!
Yue TANG:
回复 JiaoXiaojun Jiao Xiao jun:
http://www.ti.com/tool/simpliciti
JiaoXiaojun Jiao Xiao jun:
回复 Yue TANG:
能再具体一点吗?我上下翻了,没找到关于这个函数的文章,麻烦了,谢谢!谢谢!
Yue TANG:
回复 JiaoXiaojun Jiao Xiao jun:
下协议栈,直接看代码,里面有注释。想了解CCA,看数据手册。我附上这段代码吧。
这个函数支持非CCA直接发送和CCA判断再发送。
/************************************************************************************************** * @fn MRFI_Transmit * * @brief Transmit a packet using CCA algorithm. * * @param pPacket – pointer to packet to transmit * txType – FORCED or CCA * * @return Return code indicates success or failure of transmit: * MRFI_TX_RESULT_SUCCESS – transmit succeeded * MRFI_TX_RESULT_FAILED – transmit failed because CCA failed ************************************************************************************************** */uint8_t MRFI_Transmit(mrfiPacket_t * pPacket, uint8_t txType){#ifdef NWK_PLL bspIState_t s;#endif uint8_t ccaRetries; uint8_t returnValue = MRFI_TX_RESULT_SUCCESS; /* radio must be awake to transmit */ MRFI_ASSERT( mrfiRadioState != MRFI_RADIO_STATE_OFF ); /* Turn off reciever. We can ignore/drop incoming packets during transmit. */ Mrfi_RxModeOff(); MRFI_PrepareToTx( pPacket ); /* —————————————————————— * Immediate transmit * ——————— */ if (txType == MRFI_TX_TYPE_FORCED) {//#ifdef NWK_PLL// BSP_ENTER_CRITICAL_SECTION(s);//#endif// MRFI_CompleteTxPrep( pPacket );#ifdef NWK_PLL do { BSP_ENTER_CRITICAL_SECTION(s); if( stx_active == false ) // if the channel was changed { BSP_EXIT_CRITICAL_SECTION(s); Mrfi_RxModeOff(); // turn off the radio MRFI_PrepareToTx( pPacket ); // setup transmission again continue; // restart the loop } MRFI_CompleteTxPrep( pPacket ); } while( 0 );#endif /* Issue the TX strobe. */ mrfiSpiCmdStrobe( STX );#ifdef NWK_PLL BSP_EXIT_CRITICAL_SECTION(s);#endif /* Wait for transmit to complete */ Mrfi_DelayUsecLong( MRFI_MAX_TRANSMIT_TIME_us / 1000, MRFI_MAX_TRANSMIT_TIME_us % 1000, mrfi_TxImmediateDone ); /* Clear the interrupt flag */ MRFI_CLEAR_SYNC_PIN_INT_FLAG(); } else { /* —————————————————————— * CCA transmit * ————— */ MRFI_ASSERT( txType == MRFI_TX_TYPE_CCA ); /* set number of CCA retries */ ccaRetries = MRFI_CCA_RETRIES; /* For CCA algorithm, we need to know the transition from the RX state to * the TX state. There is no need for SYNC signal in this logic. So we * can re-configure the GDO_0 output from the radio to be PA_PD signal * instead of the SYNC signal. * Since both SYNC and PA_PD are used as falling edge interrupts, we * don't need to reconfigure the MCU input. */ MRFI_CONFIG_GDO0_AS_PAPD_SIGNAL(); /* =============================================================================== * Main Loop * ============= */ for (;;) { /* Radio must be in RX mode for CCA to happen. * Otherwise it will transmit without CCA happening. */ /* Can not use the Mrfi_RxModeOn() function here since it turns on the * Rx interrupt, which we don't want in this case. */ mrfiSpiCmdStrobe( SRX ); /* wait for the rssi to be valid. */#ifdef MRFI_TIMER_ALWAYS_ACTIVE MRFI_WaitTimeoutUsec(MRFI_RSSI_VALID_DELAY_US, Mrfi_ValidateRSSI);#else // MRFI_TIMER_ALWAYS_ACTIVE MRFI_RSSI_VALID_WAIT();#endif // MRFI_TIMER_ALWAYS_ACTIVE#ifdef NWK_PLL BSP_ENTER_CRITICAL_SECTION(s); if( stx_active == false ) // if the channel was changed { BSP_EXIT_CRITICAL_SECTION(s); Mrfi_RxModeOff(); // turn off the radio MRFI_PrepareToTx( pPacket ); // setup transmission again continue; // restart the cca loop } MRFI_CompleteTxPrep( pPacket );#endif /* * Clear the PA_PD pin interrupt flag. This flag, not the interrupt itself, * is used to capture the transition that indicates a transmit was started. * The pin level cannot be used to indicate transmit success as timing may * prevent the transition from being detected. The interrupt latch captures * the event regardless of timing. */ MRFI_CLEAR_PAPD_PIN_INT_FLAG(); /* Issue the TX strobe. */ mrfiSpiCmdStrobe( STX );#ifdef NWK_PLL BSP_EXIT_CRITICAL_SECTION(s);#endif /* Delay long enough for the PA_PD signal to indicate a * successful transmit. This is the 250 XOSC periods * (9.6 us for a 26 MHz crystal) See section 19.6 of 2500 datasheet. * Found out that we need a delay of atleast 20 us on CC2500 and * 25 us on CC1100 to see the PA_PD signal change. */ Mrfi_DelayUsec(25); /* PA_PD signal goes from HIGH to LOW when going from RX state. * This transition is trapped as a falling edge interrupt flag * to indicate that CCA passed and the transmit has started. */ if (MRFI_PAPD_INT_FLAG_IS_SET()) { /* —————————————————————— * Clear Channel Assessment passed. * ———————————- */ /* Clear the PA_PD int flag */ MRFI_CLEAR_PAPD_PIN_INT_FLAG(); Mrfi_DelayUsecLong( MRFI_MAX_TRANSMIT_TIME_us / 1000, MRFI_MAX_TRANSMIT_TIME_us % 1000, mrfi_TxCCADone ); /* transmit done, break */ break; } else { /* —————————————————————— * Clear Channel Assessment failed. * ———————————- */ /* Turn off radio and save some power during backoff */ /* NOTE: Can't use Mrfi_RxModeOff() – since it tries to update the * sync signal status which we are not using during the TX operation. */ MRFI_STROBE_IDLE_AND_WAIT(); /* flush the receive FIFO of any residual data */ mrfiSpiCmdStrobe( SFRX ); /* Retry ? */ if (ccaRetries != 0) {#ifdef MRFI_TIMER_ALWAYS_ACTIVE stx_active = false;#endif /* delay for a random number of backoffs */ Mrfi_RandomBackoffDelay(); MRFI_PrepareToTx( pPacket ); // setup transmission again /* decrement CCA retries before loop continues */ ccaRetries–; } else /* No CCA retries are left, abort */ { /* set return value for failed transmit and break */ returnValue = MRFI_TX_RESULT_FAILED; break; } } /* CCA Failed */ } /* CCA loop */ }/* txType is CCA */ /* Done with TX. Clean up time… */ /* Radio is already in IDLE state */#ifdef NWK_PLL stx_active = false; // Packet transmitted, regardless of packet type, remove reference. sTxTimeStampAddr = NULL;#endif /* * Flush the transmit FIFO. It must be flushed so that * the next transmit can start with a clean slate. */ mrfiSpiCmdStrobe( SFTX ); /* Restore GDO_0 to be SYNC signal */ MRFI_CONFIG_GDO0_AS_SYNC_SIGNAL(); /* If the radio was in RX state when transmit was attempted, * put it back to Rx On state. */ if(mrfiRadioState == MRFI_RADIO_STATE_RX) { Mrfi_RxModeOn(); } return( returnValue );}
zhuf1846 zhuf1846:
回复 Yue TANG:
能否详细说明一下源代码在那个标题下下载吗?