From 3ec90c02b433e1bd34cf783823cc36a09f24bbf5 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Thu, 21 Dec 2017 20:18:45 -0500 Subject: [PATCH] Stabilize onReceive(...) callback handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using SPI.usingInterrupt(…) and SPI.notUsingInterrupt(…) --- src/LoRa.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/LoRa.cpp b/src/LoRa.cpp index 5fb4256..3d62073 100644 --- a/src/LoRa.cpp +++ b/src/LoRa.cpp @@ -283,9 +283,13 @@ void LoRaClass::onReceive(void(*callback)(int)) writeRegister(REG_DIO_MAPPING_1, 0x00); + SPI.usingInterrupt(digitalPinToInterrupt(_dio0)); attachInterrupt(digitalPinToInterrupt(_dio0), LoRaClass::onDio0Rise, RISING); } else { detachInterrupt(digitalPinToInterrupt(_dio0)); +#ifdef SPI_HAS_NOTUSINGINTERRUPT + SPI.notUsingInterrupt(digitalPinToInterrupt(_dio0)); +#endif } }