From 0b1a421863bc3a0b44ca90d11b2da5f293bcce21 Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 6 Oct 2022 19:30:13 +0200 Subject: [PATCH] [SX126x] Fixed receive always failing after timeout --- src/modules/SX126x/SX126x.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 4662bc3d..ebd259e2 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -552,6 +552,14 @@ int16_t SX126x::startReceiveCommon(uint32_t timeout) { int16_t SX126x::readData(uint8_t* data, size_t len) { // set mode to standby int16_t state = standby(); + + // this method may get called from receive() after Rx timeout + // if that's the case, the standby call will return "SPI command timeout error" + // check the IRQ to be sure this really originated from timeout event + if((state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) && (getIrqStatus() & RADIOLIB_SX126X_IRQ_TIMEOUT)) { + // this is definitely Rx timeout + return(RADIOLIB_ERR_RX_TIMEOUT); + } RADIOLIB_ASSERT(state); // check integrity CRC