From 84ebdddcaf5219699c431ddca590c6c1f033e9a7 Mon Sep 17 00:00:00 2001 From: jgromes Date: Tue, 2 May 2023 18:58:59 +0200 Subject: [PATCH] [SX128x] Wakeup device on standby() call --- src/modules/SX128x/SX128x.cpp | 10 +++++++++- src/modules/SX128x/SX128x.h | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index ab3b40df..d03175f6 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -460,7 +460,15 @@ int16_t SX128x::standby(uint8_t mode) { this->mod->setRfSwitchState(Module::MODE_IDLE); uint8_t data[] = { mode }; - return(this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1)); + int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1); + if(state == RADIOLIB_ERR_NONE) { + return(state); + } else if(state == RADIOLIB_ERR_SPI_CMD_TIMEOUT) { + // the device might be in sleep mode, pull NSS low to wake up and try again + this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow); + return(this->mod->SPIwriteStream(RADIOLIB_SX128X_CMD_SET_STANDBY, data, 1)); + } + return(state); } void SX128x::setDio1Action(void (*func)(void)) { diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 804c4fa8..97dea036 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -460,7 +460,7 @@ class SX128x: public PhysicalLayer { int16_t scanChannel(); /*! - \brief Sets the module to sleep mode. + \brief Sets the module to sleep mode. To wake the device up, call standby(). \param retainConfig Set to true to retain configuration and data buffer or to false to discard current configuration and data buffer. Defaults to true. \returns \ref status_codes