CC2500发送数据时,硬件仿真一直停在while (!(TI_CC_GDO0_PxIN&TI_CC_GDO0_PIN));
现在,我在用MSP430F2013控制2.4GHZ CC2500的收发,在调试时,SPI可以与CC2500通信,但在发送时,硬件仿真就一直停在了“ while (!(TI_CC_GDO0_PxIN&TI_CC_GDO0_PIN));// Wait GDO0 to go hi -> sync TX'ed/”这句话上,一直没找到原因,不知道是我的CC2500寄存器错误还是其他什么原因,我提供一下部分程序,希望能为我指点一下:
//*********************************CC2500RF引脚定义***********************************//
#define TI_CC_GDO0_PxOUT P2OUT//GDO0--P2.6
#define TI_CC_GDO0_PxIN P2IN
#define TI_CC_GDO0_PxREN P2REN
#define TI_CC_GDO0_PxDIR P2DIR
#define TI_CC_GDO0_PxSEL P2SEL
#define TI_CC_GDO0_PxIE P2IE
#define TI_CC_GDO0_PxIES P2IES
#define TI_CC_GDO0_PxIFG P2IFG
#define TI_CC_GDO0_PIN 0x40
#define TI_CC_GDO1_PxOUT P1OUT//GDO1 SOMI--P1.7
#define TI_CC_GDO1_PxIN P1IN
#define TI_CC_GDO1_PxDIR P1DIR
#define TI_CC_GDO1_PIN 0x80
extern void writeRFSettings(void);
extern void RFSendPacket(char *txBuffer, char size);
extern char RFReceivePacket(char *rxBuffer, char *length);
//*********************************main函数***********************************//
#include "RFID.h"
char txBuffer[4]={0x55;0xAA;0x55;0xAA};
char rxBuffer[4];
void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
CLOCK_Init(); //时钟初始化
IO_Init(); //I/O初始化
TI_CC_SPISetup(); //SPI端口初始化
TI_CC_PowerUpResetCC2500(); //复位CC2500
writeRFSettings(); //写RF配置寄存器
TI_CC_SPIWriteReg(PATABLE, paTable); //Write PATABLE 0dbm POWER
TI_CC_GDO0_PxREN &=~ TI_CC_GDO0_PIN;
TI_CC_GDO0_PxDIR &=~ TI_CC_GDO0_PIN;
while(1)
{
/WDTCTL = WDT_ARST_1000; // 开看门狗防止发送死机
RFSendPacket(txBuffer, 4); // Send value over RF
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
}
}
//*********************************CC2500发送函数***********************************//
void RFSendPacket(char *txBuffer, char size)
{
//TI_CC_SPIStrobe(SIDLE);
//TI_CC_SPIStrobe(SFTX); //clear txBuffer
TI_CC_SPIWriteBurstReg(TXFIFO, txBuffer, size); // Write TX data
TI_CC_SPIStrobe(STX); // Change state to TX, initiating
while (!(TI_CC_GDO0_PxIN&TI_CC_GDO0_PIN));// Wait GDO0 to go hi -> sync TX'ed//、、、、、硬件仿真时就停在这儿了
if(TI_CC_GDO0_PxIN&TI_CC_GDO0_PIN) P1OUT ^=0X02;
while (TI_CC_GDO0_PxIN&TI_CC_GDO0_PIN);// Wait GDO0 to clear -> end of pkt//
}
还有想问一下,如果操作CC2500工作的话,需配置好哪些基础寄存器,比如同步字的寄存器,发送包长度等等一些重要的,麻烦各位了,谢谢!
CC2500的配置可以用SmartStudio生成。你可以参考simpliciTI协议栈mifi_radio.c中的操作。
其中的发送函数如下,可以看到不仅有Pin的判断还有一个超时设定。你这个写法,有机会进入到一个错误的状态,不是你发了STX就能进入TX状态的。
(你屏蔽了TI_CC_SPIStrobe(SIDLE);)
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 );
}
谢谢,现在CC2500已经能够通信,发送指定的数据了,想问一下,能否通过RSSI的值来计算距离?怎么计算?
RSSI受环境影响很大(天线朝向,模块一致性),与距离是非线性的。只有一个基本规律,距离越远,RSSI越小。
http://www.cse.buffalo.edu/srds2009/F2DA/f2da09_RSSI_Parameswaran.pdf
你好,我在使用CC2500时,发现两个CC2500模块的距离超过2米,发送不成功的频率很高,检测GDO0脚无跳变,放在一起(<0.5米),发送接收很正常。这是怎么回事,我弄不懂。在TI网站哪儿能下载到相关的程序mifi_radio.c。
估计是你的板子的射频性能没有调好。
天线用陶瓷的还是板载的好呢,天线部分预留的空间有讲究吗?
CC2500传输距离能有多远?给些数据参考一下,谢谢!
请问,这个停留的问题后来是怎么解决的,我也遇到了同样的问题。有可参考的发射代码吗,我的邮箱xw1631@163.com,谢谢