diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 077b9675..bf25174a 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -453,8 +453,16 @@ int16_t SX126x::standby(uint8_t mode) { // set RF switch (if present) this->mod->setRfSwitchState(Module::MODE_IDLE); - uint8_t data[] = {mode}; - return(this->mod->SPIwriteStream(RADIOLIB_SX126X_CMD_SET_STANDBY, data, 1)); + uint8_t data[] = { mode }; + int16_t state = this->mod->SPIwriteStream(RADIOLIB_SX126X_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_SX126X_CMD_SET_STANDBY, data, 1)); + } + return(state); } void SX126x::setDio1Action(void (*func)(void)) { diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 01981ffa..f24fa807 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -538,7 +538,7 @@ class SX126x: public PhysicalLayer { int16_t scanChannel(uint8_t symbolNum = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak = RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin = RADIOLIB_SX126X_CAD_PARAM_DEFAULT); /*! - \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 of the currently active modem ("warm start") or to false to discard current configuration ("cold start"). Defaults to true. \returns \ref status_codes