Skip to content

Commit 92e2f33

Browse files
committed
[SX126x] Autocorrect TCXO selected instead of XTAL
1 parent 90511e8 commit 92e2f33

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/modules/SX126x/SX126x.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,27 @@ int16_t SX126x::modSetup(float tcxoVoltage, bool useRegulatorLDO, uint8_t modem)
14651465

14661466
// configure settings not accessible by API
14671467
state = config(modem);
1468+
1469+
// if something failed, check the device errors
1470+
if(state != RADIOLIB_ERR_NONE) {
1471+
// unless mode is forced to standby, device errors will be 0
1472+
(void)standby();
1473+
uint16_t errors = getDeviceErrors();
1474+
RADIOLIB_DEBUG_BASIC_PRINTLN("Config failed, device errors: 0x%X", errors);
1475+
1476+
// SPI command fail and oscillator start error flag indicate incorrectly set oscillator
1477+
if((state == RADIOLIB_ERR_SPI_CMD_FAILED) && (errors & RADIOLIB_SX126X_XOSC_START_ERR)) {
1478+
// typically users with XTAL devices will try to call the default begin method
1479+
// disable TCXO and try to run config again
1480+
this->XTAL = false;
1481+
RADIOLIB_DEBUG_BASIC_PRINTLN("Bad oscillator selected, trying XTAL");
1482+
1483+
state = setTCXO(0);
1484+
RADIOLIB_ASSERT(state);
1485+
1486+
state = config(modem);
1487+
}
1488+
}
14681489
RADIOLIB_ASSERT(state);
14691490

14701491
if (useRegulatorLDO) {

src/modules/SX126x/SX126x_config.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -798,19 +798,7 @@ int16_t SX126x::config(uint8_t modem) {
798798
}
799799

800800
// check calibration result
801-
state = this->mod->SPIcheckStream();
802-
803-
// if something failed, show the device errors
804-
#if RADIOLIB_DEBUG_BASIC
805-
if(state != RADIOLIB_ERR_NONE) {
806-
// unless mode is forced to standby, device errors will be 0
807-
standby();
808-
uint16_t errors = getDeviceErrors();
809-
RADIOLIB_DEBUG_BASIC_PRINTLN("Calibration failed, device errors: 0x%X", errors);
810-
}
811-
#endif
812-
813-
return(state);
801+
return(this->mod->SPIcheckStream());
814802
}
815803

816804
#endif

0 commit comments

Comments
 (0)