SX126x-Arduino timeout interrupts not being processed

Hello! First time here.

I’m having an issue with the SX126x-Arduino library where the LoRa RxTimeout callback is not getting called. I’m using an RAK4631 with Arduino BSP. I’m using the latest version of the library from the Github repo.

This happens with a clean LoRaP2P_RX example, when I have no device transmitting. The receive process starts, but the callback function is never called. In the library, RadioOnRxTimeoutIrq() is getting called, but it seems the IRQ processing functions are not. I can add “Radio.BgIrqProcess();” to my loop(), and then the function gets called, but in V2 of the library, the Irq processing should get handled automatically, right?

Is there something I’m missing here?

Thanks!

Welcome to the forum @cclose

Seems to be a bug in the SX126x-Arduino library. Checking it.

@cclose
Can you try latest version 2.0.24 of the library.
I tested today and the bug should be fixed.

Worked! Thanks for the quick response!

Okay, so now I’m having an issue when trying to receive and then transmit data. If there’s data to receive, then the transmit works just fine, but if the receive times out, then the transmit will also time out. Is there something I need to do to take it out of receive mode after a timeout? Standby() doesn’t seem to do it.

Thanks for your time!

#include <Arduino.h>
#include <SX126x-RAK4630.h>
#include <SPI.h>

#define LORA_OUTPWR 22 // dBm
#define LORA_BNDWTH 0 // 0: 125kHz, 1: 250kHz, 2: 500kHz
#define LORA_DATARATE 7 // 6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips
#define LORA_CODINGRATE 1 // 1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8
#define LORA_PREAMBLELEN 8 // # of symbols
#define LORA_FIXLEN false // fixed length packets
#define LORA_SYMBTIMEOUT 0 // # of symbols
#define LORA_CRC true // error checking on
#define LORA_HOPPERIOD 0 // # of symbols
#define LORA_IQINV false // Invert IQ symbols
#define LORA_RXCONT true // Continuous read mode on the SX126X (set to true, the library allows longer timeouts)
#define LORA_RXTIMEOUT 3000 //ms
#define LORA_TXTIMEOUT 3000 // ms

RadioEvents_t callbacks;

uint8_t buffer[3] = {1,2,3};

void setup() {
  Serial.begin(9600);
  while(!Serial)
    delay(10);
  Serial.println("Init");

  lora_rak4630_init();

  callbacks.RxTimeout = RxTimeout;
  callbacks.TxTimeout = TxTimeout;
  callbacks.RxDone = RxDone;
  callbacks.TxDone = TxDone;

  Radio.Init(&callbacks);
  Radio.SetChannel(915000000);
  Radio.SetPublicNetwork(false);
  
  Radio.SetTxConfig(MODEM_LORA, LORA_OUTPWR, 0, LORA_BNDWTH, LORA_DATARATE, 
                    LORA_CODINGRATE, LORA_PREAMBLELEN, LORA_FIXLEN, LORA_CRC,
                    0, LORA_HOPPERIOD, LORA_IQINV, LORA_TXTIMEOUT);


  Radio.SetRxConfig(MODEM_LORA, LORA_BNDWTH, LORA_DATARATE, LORA_CODINGRATE, 
                    0, LORA_PREAMBLELEN, LORA_SYMBTIMEOUT, LORA_FIXLEN, 0,
                    LORA_CRC, false, LORA_HOPPERIOD, LORA_IQINV, LORA_RXCONT);

  Serial.println("RX");
  Radio.Rx(1000);
}

void loop() {}

void RxTimeout() {
  Serial.println("RxTimeout");

  Radio.Standby();
  Serial.println("Sending");
  Radio.Send(buffer, 2);
}

void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
  Serial.println("RxDone");

  Radio.Standby();
  Serial.println("Sending");
  Radio.Send(buffer, 2);
}

void TxDone() { Serial.println("TxDone"); }

void TxTimeout() { Serial.println("TxTimeout"); }

I am not sure.
Your code throws problems, but when I try my LoRa P2P PingPong example code it works.

Not sure why, but if I change

#define LORA_RXCONT true	// Continuous read mode on the SX126X (set to true, the library allows longer timeouts)

to false, it works.

Ah, interesting, that does do it.

I was trying to avoid not being in continuous mode because it messes with the timeout length. My best guess was that the SX126X internally has a short timeout supported, and that the library was allowing longer timeouts by setting the chip to continuous mode & then taking it out of receive mode whenever the longer timer went off.

So when not in continuous mode, the Rx timeout value gets capped at around 890ms. I don’t know if that’s the intended functionality or not, but I can make it work. Being able to transmit & receive is much more important.

Okay, so additional piece of information. Your fix of setting continuous mode to false does work, but only when the timeout given to Radio.Rx() is greater than the 890ish ms value I described above. In other words, letting the SX126X finish its RX rather than having the library’s timer stop it?

There are two sources that can stop the RX mode.
(1) the SX1262 itself
(2) a software timer started by the the library

That part of control was taken from the original Semtech code (just adapted for Arduino) and I did not do much change to it.
I never tested the RX continuous flag, I had it always on false. I guess there is some glitch in the code, because Radio.Rx(0) is starting RX in continuous mode anyway,m so that flag is actually not needed.