In the low-power application I am working on, my gateway sends a wakeup burst to a node, and I then use radio.delay
(from this thread) to wait N ms from the start of the wakeup burst until the node responds with data. The logic is simple:
radio.listenModeStart();
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
burstRemaining = radio.LISTEN_BURST_REMAINING_MS;
radio.listenModeEnd();
radio.delay(burstRemaining + N); // followed by 3x LowPower.powerDown()
radio.ListenModeEnd();
It doesn't quite work. The actual delay varies in a range of 250 ms from the trial to trial. The variation is in direct relation to (burstRemaining % 250).
But it
does work if I replace radio.delay() with plain old delay(). I get very precise timing (+/- 3 ms) with this:
radio.listenModeStart();
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
burstRemaining = radio.LISTEN_BURST_REMAINING_MS;
radio.listenModeEnd();
delay(burstRemaining + N);
Or if I replace radio.delay(burstRemaining + N) with two separate radio.delays(), one for burstRemaining and one for N:
radio.listenModeStart();
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);
burstRemaining = radio.LISTEN_BURST_REMAINING_MS;
radio.listenModeEnd();
radio.delay(burstRemaining); // followed by 3x LowPower.powerDown()
radio.ListenModeEnd();
radio.delay(burstRemaining + N); // followed by 3x LowPower.powerDown()
radio.ListenModeEnd();
I'd use this last idea, except that it crashes after several hours of operation. The processor gets stuck somewhere inside the first radio.delay().
So it seems like there is some odd interaction between radio.listenModeStart and radio.delay, but I am not well versed enough in how the RFM69 works to figure out what the issue is. Any help would be welcome.