From c3fa027108af71a3975d75754ec21159b293c680 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 23 Oct 2022 20:40:13 +0200 Subject: [PATCH] [SX127x] Fixed CAD interrupt example --- ...x_Channel_Activity_Detection_Interrupt.ino | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino b/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino index c1e0b105..1c41ed37 100644 --- a/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino +++ b/examples/SX127x/SX127x_Channel_Activity_Detection_Interrupt/SX127x_Channel_Activity_Detection_Interrupt.ino @@ -30,11 +30,9 @@ SX1278 radio = new Module(10, 2, 9, 3); // https://github.com/jgromes/RadioShield //SX1278 radio = RadioShield.ModuleA; -// save state between loops -int scanState = RADIOLIB_ERR_NONE; - void setup() { - Serial.begin(9600); + // Serial port speed must be high enough for this example + Serial.begin(115200); // initialize SX1278 with default settings Serial.print(F("[SX1278] Initializing ... ")); @@ -110,22 +108,21 @@ void setFlagDetected(void) { } void loop() { - // check if we got a preamble - if(detectedFlag) { + // check if we need to restart channel activity detection + if(detectedFlag || timeoutFlag) { // disable the interrupt service routine while // processing the data enableInterrupt = false; - // reset flag - detectedFlag = false; - - // LoRa preamble was detected - Serial.print(F("[SX1278] Preamble detected!")); - - } - - // check if we need to restart channel activity detection - if(detectedFlag || timeoutFlag) { + // check if we got a preamble + if(detectedFlag) { + // LoRa preamble was detected + Serial.println(F("[SX1278] Preamble detected!")); + } else { + // nothing was detected + Serial.println(F("[SX1278] Channel free!")); + } + // start scanning the channel Serial.print(F("[SX1278] Starting scan for LoRa preamble ... ")); @@ -138,5 +135,13 @@ void loop() { Serial.println(state); } + // reset flags + timeoutFlag = false; + detectedFlag = false; + + // enable interrupts again + enableInterrupt = true; + } + }