Had a quick play and it looks like CAD mode can be added easily enough -
After I added RHModeCad to the RHMode typedef enum (RHGenericDriver.h), and added a handler for the CadDone interrupt (RH_RF95::handleInterrupt(), RH_RF95.cpp), this seems to work -
void RH_RF95::setModeCad()
{
if (_mode != RHModeCad)
{
_mode = RHModeCad;
spiWrite(RH_RF95_REG_40_DIO_MAPPING1, 0x80); // Interrupt on CadDone
spiWrite(RH_RF95_REG_01_OP_MODE, RH_RF95_MODE_CAD);
}
}
Of course, you then need to check the CadDetected flag in the interrupt handler. It is a real shame that the CadDetected interrupt is only available on DIO1 or DIO4 (neither of which are connected on the MoteinoLR). I guess I will physically connect one of these to the AVR and see if that works as expected.
I hope this isn't something that is already well documented here, and I'm just not finding it....?!? :-[
Cool, didn't want to think I was missing a whole LoRa Listen Mode sub forum or anything ;)
There seems to have been a fair number of people viewing this thread, so I will outline some of my initial findings here since others may be interested.
- The RFM95 boasts a Top Level Sequencer to automatically do timed cyclic listening & address checking with external interrupt capability :)
- This sequencer is not available in LoRa mode :o
- RSSI is not a practical indication of an incoming LoRa transmission, as LoRa can receive signals below the noise floor of the receiver ;D
- There is built-in functionality to detect LoRa channel activity, called channel activity detection mode (CAD)
- Activating CAD mode will trigger a hardware interrupt upon completion, and puts the LoRa modem back into standby/idle mode (note not sleep mode)
- If the CAD process detects a LoRa preamble (activity) it also triggers a hardware CAD Detected interrupt
- The CAD Complete hardware interrupt is connected to the AVR on the Moteino, however CAD Detected is not
- The CAD process is fast and appears to be highly [power-consumption] optimized
- Since the sequencer is not available, we need to trigger CAD mode from the microcontroller each cycle
In the absence of the sequencer, the uC needs to put the radio back into sleep mode after each CAD Complete interrupt. The overhead of checking the CAD Detected flag at this point seems like it may actually be quite low, so the non-connected CAD Detected hardware interrupt may not actually be a big deal. Wild guessing - measuring will tell the full story, of course. Later. For now on with the wild guessing!
I have been testing the following and it works just fine. Listening (ie CAD mode) every 500mS. The packet then needs to be read (and parsed for address matching unfortunately).
RH_RF95::cadDetected() was a quick addition to give me visibility into the CAD Detected interrupt flag, which I kept track of with an internal bool.
while(!(rf95.cadDetected())) {
rf95.sleep();
LowPower.powerDown(SLEEP_500MS, ADC_OFF, BOD_OFF); // arbitrary sleep value for testing cyclic listen
rf95.setModeCad();
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
// CAD Complete interrupt will wake us
// CAD Detected interrupt will drop us out of this loop
}
rf95.setModeRx(); // ok let's get the packet & check addressing
The oscilloscope is taunting me from across the bench but I will probably not get a change to have a play until later this coming week.
Anyway, hopefully this is interesting to at least one or two of you out there! 8)