Hi,
I read the thread and thought of something. If you do not have a CCA, the TX will not occur (according to user manual you have to strobe stx again in order to attempt to send the packet once more). Your if statement will be true, and you return false. But the data you loaded into the TX FIFO will still be there. So next time you call your function, the same thing may happen again - and the FIFO will be loaded with even more bytes (eventually tx fifo overflow occurs). If you have a CCA though (the second time), the previous packet will now be sent. But the packet you actually wanted to send is still in the TX FIFO.
Part of your code, with possible modification:
// Set data length at the first position of the TX FIFO
writeReg(CC1101_TXFIFO, packet.length);
// Write data into the TX FIFO
writeBurstReg(CC1101_TXFIFO, packet.data, packet.length);
// CCA enabled: will enter TX state only if the channel is clear
cmdStrobe(CC1101_STX);
// Check that TX state is being entered (state = RXTX_SETTLING)
marcState = readStatusReg(CC1101_MARCSTATE) & 0x1F;
if((marcState != 0x13) && (marcState != 0x14) && (marcState != 0x15))
{
=> FLUSH YOUR TX FIFO HERE, THE DATA YOU LOADED SHOULD BE REMOVED
setRxState(); // Back to RX state
return false;
}
Best Regards
Hans Christian