From cb5c8d63132177cf451d231ea2ce4f1044e2f4f5 Mon Sep 17 00:00:00 2001 From: jgromes Date: Mon, 6 Jan 2020 17:20:51 +0100 Subject: [PATCH] [SX127x] Moved reset to chip detection loop --- src/modules/SX127x/SX127x.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/SX127x/SX127x.cpp b/src/modules/SX127x/SX127x.cpp index 60f63b2f..866b82ef 100644 --- a/src/modules/SX127x/SX127x.cpp +++ b/src/modules/SX127x/SX127x.cpp @@ -11,9 +11,6 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi Module::pinMode(_mod->getIrq(), INPUT); Module::pinMode(_mod->getGpio(), INPUT); - // reset the module - reset(); - // try to find the SX127x chip if(!SX127x::findChip(chipVersion)) { RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!")); @@ -23,8 +20,13 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!")); } + // set mode to standby + int16_t state = standby(); + if(state != ERR_NONE) { + return(state); + } + // check active modem - int16_t state; if(getActiveModem() != SX127X_LORA) { // set LoRa mode state = setActiveModem(SX127X_LORA); @@ -1090,6 +1092,10 @@ bool SX127x::findChip(uint8_t ver) { uint8_t i = 0; bool flagFound = false; while((i < 10) && !flagFound) { + // reset the module + reset(); + + // check version register uint8_t version = _mod->SPIreadRegister(SX127X_REG_VERSION); if(version == ver) { flagFound = true;