What i would like to do is set the radio channel in my transmitter app and have the receiver “find” and lock on to the transmitted channel. I’ll include my actual transmission channel number in the packet structure, and I’m hoping the receiver can easily just scan through ALL the channels. As soon as soon it gets close enough to get a good CRC on one of my packets, the receiver can then take the exact channel right from the transmitted message.
So based on the spectrum anylyzer I’ve seen in another post, it seems I can pretty much set up for receiving, and change the CHANNR variable anytime I want? Could someone verify this is true or if I’m missing something? Here is my proposed code. I understand the seek time could be improved by doing something more robust than incrementing a channel number by “1”, but I’m just trying to verify whether changing CHANNR is all I need to do. My initialization will be something like this, and is based on testRadioSignalRx.c
void receiverInit()
{
radioRegistersInit();
CHANNR = 128; // any initial value
PKTLEN = RADIO_PACKET_SIZE; // my expected pre-defined packet size
MCSM0 = 0x14; // Auto-calibrate when going from idle to RX or TX.
MCSM1 = 0x00; // Disable CCA. After RX, go to IDLE. After TX, go to IDLE.
// We leave MCSM2 at its default value.
// this DMA config is always the same for DMA->radio transfers
dmaConfig.radio.DC6 = 19; // WORDSIZE = 0, TMODE = 0, TRIG = 19 (always 19 for RADIO)
dmaConfig.radio.SRCADDRH = XDATA_SFR_ADDRESS(RFD) >> 8;
dmaConfig.radio.SRCADDRL = XDATA_SFR_ADDRESS(RFD);
dmaConfig.radio.DESTADDRH = (unsigned int)packet >> 8; // my actual packet adr
dmaConfig.radio.DESTADDRL = (unsigned int)packet;
dmaConfig.radio.LENL = 1 + RADIO_PACKET_SIZE + 2; // my expected packet size + 2
dmaConfig.radio.VLEN_LENH = 0b10000000; // Transfer length is FirstByte+3
dmaConfig.radio.DC7 = 0x10; // SRCINC = 0, DESTINC = 1, IRQMASK = 0, M8 = 0, PRIORITY = 0
DMAARM |= (1<<DMA_CHANNEL_RADIO); // Arm DMA channel
RFST = 2; // Switch radio to RX mode.
}
So with that done, I’m hoping all I will have to do is form a “detect()” function loop, where I listen until I get a good message, and permanently switch CHANNR, and I’m done, like the below?
void detect() // detect my packet and switch to that channel permanently when found.
{
uint16 timeNow = getMs();
static uint16 timer= 0;
uint8 channel = 0, try;
while(1) // do forever till we detect.
{
CHANNR = channel;
channel = channel++; // keep revolving 0->255 and back
// listen 4 times if bad CRC, 100MS between tries.
for (try = 0; try < 4; try++)
{
while (getMs() - timeNow) < 100)); // retry every 100mS
timeNow = getMs();
if (!(RFIF & (1<<4))) break; // nothing at all... try a different channel
if (!radioCrcPassed()) continue; // BAD crc.. try again
// got a good CRC, so extract my embedded channel
// assume pPacketStruct already -> my packet structure
CHANNR = pPacketStruct->myChannelID;
return;
}
}
}