Hello! I'm trying to read data from an SX1278 (specifically it's an Ai-Thinker Ra-02), and if I just try a LoRa.parsePacket() on the loop(), it receives everything correctly (I'm transmitting data about once every 10 seconds). However, when I try to attach an interrupt, I stop getting any information.
I use an ESP8266
Here is my code (simplified):
#include <LoRa.h>
#define LORA_CS 15 // D8
#define LORA_RST 4 // D2
#define LORA_DIO0 5 // D1
volatile bool _packetReceived = false;
volatile int _packetSize = 0;
ICACHE_RAM_ATTR void onPacketReceived(int packSize) {
_packetReceived = true;
_packetSize = packSize;
}
void readPackets();
void setup() {
Serial.begin(115200);
while (!Serial);
delay(3000);
LoRa.setPins(LORA_CS, LORA_RST, LORA_DIO0);
bool ok = LoRa.begin(433E6);
Serial.print("Result = ");
Serial.println(ok);
if (!ok) {
while (1) {
Serial.println("LoRa.begin() FAILED");
delay(2000);
}
}
LoRa.setSpreadingFactor(10);
LoRa.setSignalBandwidth(62.5E3);
LoRa.setCodingRate4(6);
// I've tried both a manual interrupt and using LoRa.onReceive
// pinMode(LORA_DIO0, INPUT);
// attachInterrupt(digitalPinToInterrupt(LORA_DIO0), readPackets, RISING);
LoRa.onReceive(onPacketReceived);
LoRa.receive();
}
void loop() {
if (_packetReceived){
_packetReceived = false;
// process data with _packetSize
Serial.print("Interrupt fired");
}
return;
// readPackets(); // if I skip return and readPackets() continuosly, I get all the data correctly
}
constexpr size_t payloadSize = 10;
void readPackets() {
int packetSize = LoRa.parsePacket(payloadSize);
if (packetSize == 0) return;
// process data
}
If I touch the SX1278's DIO0 pin with a 3v3 wire, the interrupt fires, so I don't think there is something wrong with the code or with the cable connection. It's just not firing when RxDone. I've also switched to RadioLib (the code I shared uses Lora by sandeep mistry) but the problem remains.
If I try measuring with a multimeter, I never see that the tension goes up (although I guess that would happen too quickly for me to even notice).
What is it that I'm doing wrong? I've tried reading about the registers it uses internally but it's currently a bit too advanced for me to try to tinker with.
I'd appreciate any help you may have, thank you!