Skip to content

Commit 09f46d0

Browse files
committed
Add missing call to SPI.usingInterrupt()
The RFM69 driver accesses SPI in interrupt context. This can (and does) cause a lockup if another SPI device is being accessed in non-interrupt context at the moment that the RFM69 interrupt occurs. I had this problem on a board with both an Ethernet2 device and an RFM69 device. Occasionally, the SPI interface would lock up hard, crashing the application. The fix is simple. One must call SPI.usingInterrupt() and pass in the interrupt number during setup. The SPI library will record that fact, and will automatically disable the interrupt whenever the SPI interface is busy. More information is available here: arduino/Arduino#2381 Please note that this is a race condition, and is somewhat hard to trigger. You need a board with several active SPI devices, and the timing has to be such that interrupts happen in the middle of other SPI transactions.
1 parent 2da600e commit 09f46d0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

RFM69.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ bool RFM69::initialize(uint8_t freqBand, uint8_t nodeID, uint8_t networkID)
106106
if (millis()-start >= timeout)
107107
return false;
108108
_inISR = false;
109+
SPI.usingInterrupt(_interruptNum);
109110
attachInterrupt(_interruptNum, RFM69::isr0, RISING);
110111

111112
selfPointer = this;

0 commit comments

Comments
 (0)