Skip to content

Commit 99b0dc2

Browse files
committed
SPI.usingInterrupts() is not supported on ESP platforms #1
Use noInterrupt() and interrupt() for ESP platforms instead. See #1
1 parent cac8c0c commit 99b0dc2

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/nRF905.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ static const uint8_t config[] PROGMEM = {
2626

2727
inline uint8_t nRF905::cselect()
2828
{
29+
#if defined(ESP32) || defined(ESP8266)
30+
if(!isrBusy)
31+
noInterrupts();
32+
#endif
2933
spi.beginTransaction(spiSettings);
3034
digitalWrite(csn, LOW);
3135
return 1;
@@ -35,6 +39,10 @@ inline uint8_t nRF905::cdeselect()
3539
{
3640
digitalWrite(csn, HIGH);
3741
spi.endTransaction();
42+
#if defined(ESP32) || defined(ESP8266)
43+
if(!isrBusy)
44+
interrupts();
45+
#endif
3846
return 0;
3947
}
4048

@@ -209,8 +217,13 @@ void nRF905::begin(
209217
if(pwr != NRF905_PIN_UNUSED)
210218
pinMode(pwr, OUTPUT);
211219

212-
spi.usingInterrupt(digitalPinToInterrupt(dr));
213-
spi.usingInterrupt(digitalPinToInterrupt(am));
220+
#if !defined(ESP32) && !defined(ESP8266)
221+
// SPI.usingInterrupts() is not supported on ESP platforms. More info: https://github.com/zkemble/nRF905-arduino/issues/1
222+
if(dr != NRF905_PIN_UNUSED)
223+
spi.usingInterrupt(digitalPinToInterrupt(dr));
224+
if(am != NRF905_PIN_UNUSED)
225+
spi.usingInterrupt(digitalPinToInterrupt(am));
226+
#endif
214227

215228
powerOn(false);
216229
standbyMode(true);
@@ -230,7 +243,9 @@ void nRF905::begin(
230243

231244
void nRF905::otherSPIinterrupts()
232245
{
246+
#if !defined(ESP32) && !defined(ESP8266)
233247
spi.usingInterrupt(255);
248+
#endif
234249
}
235250

236251
void nRF905::events(
@@ -580,6 +595,10 @@ void nRF905::interrupt_dr()
580595
{
581596
// If DR && AM = RX new packet
582597
// If DR && !AM = TX finished
598+
599+
#if defined(ESP32) || defined(ESP8266)
600+
isrBusy = 1;
601+
#endif
583602

584603
if(addressMatched())
585604
{
@@ -592,12 +611,20 @@ void nRF905::interrupt_dr()
592611
if(onTxComplete != NULL)
593612
onTxComplete(this);
594613
}
614+
615+
#if defined(ESP32) || defined(ESP8266)
616+
isrBusy = 0;
617+
#endif
595618
}
596619

597620
void nRF905::interrupt_am()
598621
{
599622
// If AM goes HIGH then LOW without DR going HIGH then we got a bad packet
600623

624+
#if defined(ESP32) || defined(ESP8266)
625+
isrBusy = 1;
626+
#endif
627+
601628
if(addressMatched())
602629
{
603630
if(onAddrMatch != NULL)
@@ -609,6 +636,10 @@ void nRF905::interrupt_am()
609636
onRxInvalid(this);
610637
}
611638
validPacket = 0;
639+
640+
#if defined(ESP32) || defined(ESP8266)
641+
isrBusy = 0;
642+
#endif
612643
}
613644

614645
void nRF905::poll()

src/nRF905.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ class nRF905 //: public Stream // TODO see Wire library
101101
private:
102102
SPIClass spi;
103103
SPISettings spiSettings;
104+
105+
#if defined(ESP32) || defined(ESP8266)
106+
volatile uint8_t isrBusy;
107+
#endif
104108

105109
// Pins
106110
uint8_t csn; // SPI SS

0 commit comments

Comments
 (0)