This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
u8 state=0;
u32 correctpkt=0;
u32 errortime=0;
u8 chopflag=0;
u32 timeout=9000;
initCC2500(); //81ms
channr=0;
ledstate=LED_FAILURE;
CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteReg(CC2500_0A_CHANNR,hopping_table[channr]);
CC2500_WriteReg(CC2500_23_FSCAL3, 0x89);
CC2500_Strobe(CC2500_SRX);
delay_usA(3000);
packetlen=0;
state=0;
chopflag=0;
while(1)
{
len = CC2500_ReadReg(CC2500_3B_RXBYTES | CC2500_READ_BURST) & 0x7F;
if(len)
{
CC2500_ReadData(buffer, len);
for(i=0;i<len;i++)
{
packet[packetlen++]=buffer[i];
}
if(packet[0]==0x11)
{
if(packet[0]==(packetlen-3))
{
DebugSendRawPacket();
//跳频 ,包中第4个字节为本次频点
lastchannr=packet[3];
last_alive_time=micros();
state=1;
correctpkt++;
chopflag=1;
}
}
}
//9ms一跳,如果连续10次没有收到数据,就固定在最后的频点
if((((micros()-last_alive_time)>=timeout) && state>=1 && state<10) || chopflag==1)
{
channr = (lastchannr + 1) % 188;
//9ms一跳,4个频点1组(前3个接收,第4个发送,现在只收不发)
if((channr%4)==3)
{
delay_usA(9000);
channr = (channr + 1) % 188;
}
lastchannr=channr;
last_alive_time=micros();
CC2500_Strobe(CC2500_SIDLE);
CC2500_WriteReg(CC2500_0A_CHANNR, hopping_table[channr%47]);
CC2500_WriteReg(CC2500_23_FSCAL3, 0x89);
CC2500_Strobe(CC2500_SFRX);
CC2500_Strobe(CC2500_SRX);
if(chopflag!=1) state++;
packetlen=0;
chopflag=0;
}
}