所以最好是在读取完数据之后在触发进入RX状态, 参考例子
static uint8 rxRecvPacket(uint8* data, uint8* length)
{
uint8 packet_status[2];
uint8 status;
uint16 key;
packetReceived = FALSE;
status = RX_OK;
// Set radio in RX mode
halRfStrobe(CC1101_SRX);
// Wait for incoming packet
key = halIntLock();
while(!packetReceived)
{
halMcuSetLowPowerMode(HAL_MCU_LPM_3);
key = halIntLock();
}
halIntUnlock(key);
// Read first element of packet from the RX FIFO
status = halRfReadFifo(length, 1);
if ((status & CC1101_STATUS_STATE_BM) == CC1101_STATE_RX_OVERFLOW)
{
halRfStrobe(CC1101_SIDLE);
halRfStrobe(CC1101_SFRX);
status = RX_FIFO_OVERFLOW;
}
else if (*length == 0 || *length > 61)
{
halRfStrobe(CC1101_SIDLE);
halRfStrobe(CC1101_SFRX);
status = RX_LENGTH_VIOLATION;
}
else
{
// Get payload
halRfReadFifo(data, *length);
// Get the packet status bytes [RSSI, LQI]
halRfReadFifo(packet_status, 2);
// Check CRC
if ((packet_status[1] & CC1101_LQI_CRC_OK_BM) != CC1101_LQI_CRC_OK_BM)
{
status = RX_CRC_MISMATCH;
}
else
{
status = RX_OK;
}
}
return(status);
}