diff --git a/src/main.cpp b/src/main.cpp index f4fb24fa91..48dec89e7e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -112,6 +112,10 @@ AccelerometerThread *accelerometerThread = nullptr; AudioThread *audioThread = nullptr; #endif +#if defined(TCXO_OPTIONAL) +float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if TCXO is optional, put this here so it can be changed further down. +#endif + using namespace concurrency; // We always create a screen object, but we only init it if we find the hardware @@ -890,7 +894,7 @@ void setup() } #endif -#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) +#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && !defined(TCXO_OPTIONAL) if (!rIf) { rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); if (!rIf->init()) { @@ -904,6 +908,40 @@ void setup() } #endif +#if defined(USE_SX1262) && !defined(ARCH_PORTDUINO) && defined(TCXO_OPTIONAL) + if (!rIf) { + // Try using the specified TCXO voltage + rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); + if (!rIf->init()) { + LOG_WARN("Failed to find SX1262 radio with TCXO using DIO3 reference voltage at %f V\n", tcxoVoltage); + delete rIf; + rIf = NULL; + tcxoVoltage = 0; // if it fails, set the TCXO voltage to zero for the next attempt + } else { + LOG_INFO("SX1262 Radio init succeeded, using "); + LOG_WARN("SX1262 Radio with TCXO"); + LOG_INFO(", reference voltage at %f V\n", tcxoVoltage); + radioType = SX1262_RADIO; + } + } + + if (!rIf) { + // If specified TCXO voltage fails, attempt to use DIO3 as a reference instea + rIf = new SX1262Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); + if (!rIf->init()) { + LOG_WARN("Failed to find SX1262 radio with XTAL using DIO3 reference voltage at %f V\n", tcxoVoltage); + delete rIf; + rIf = NULL; + tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // if it fails, set the TCXO voltage back for the next radio search + } else { + LOG_INFO("SX1262 Radio init succeeded, using "); + LOG_WARN("SX1262 Radio with XTAL"); + LOG_INFO(", reference voltage at %f V\n", tcxoVoltage); + radioType = SX1262_RADIO; + } + } +#endif + #if defined(USE_SX1268) if (!rIf) { rIf = new SX1268Interface(RadioLibHAL, SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY); diff --git a/src/mesh/SX126xInterface.cpp b/src/mesh/SX126xInterface.cpp index b564ba287e..39ffb0ac95 100644 --- a/src/mesh/SX126xInterface.cpp +++ b/src/mesh/SX126xInterface.cpp @@ -40,7 +40,7 @@ template bool SX126xInterface::init() 0; // "TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip." per // https://github.com/jgromes/RadioLib/blob/690a050ebb46e6097c5d00c371e961c1caa3b52e/src/modules/SX126x/SX126x.h#L471C26-L471C104 // (DIO3 is free to be used as an IRQ) -#else +#elif !defined(TCXO_OPTIONAL) float tcxoVoltage = SX126X_DIO3_TCXO_VOLTAGE; // (DIO3 is not free to be used as an IRQ) #endif @@ -345,4 +345,4 @@ template bool SX126xInterface::sleep() #endif return true; -} \ No newline at end of file +} diff --git a/variants/diy/nrf52_promicro_diy_tcxo/variant.h b/variants/diy/nrf52_promicro_diy_tcxo/variant.h index b09d3bdb49..2e506d0552 100644 --- a/variants/diy/nrf52_promicro_diy_tcxo/variant.h +++ b/variants/diy/nrf52_promicro_diy_tcxo/variant.h @@ -128,22 +128,29 @@ NRF52 PRO MICRO PIN ASSIGNMENT #define SX126X_RXEN (0 + 17) // P0.17 #define SX126X_TXEN RADIOLIB_NC // Assuming that DIO2 is connected to TXEN pin. If not, TXEN must be connected. -/* -On the SX1262, DIO3 sets the voltage for an external TCXO, if one is present. If one is not present, then this should not be used. - -Ebyte -e22-900mm22s has no TCXO -e22-900m22s has TCXO -e220-900mm22s has no TCXO, works with/without this definition, looks like DIO3 not connected at all - -AI-thinker -RA-01SH does not have TCXO +// #define SX126X_MAX_POWER 8 set this if using a high-power board! -Waveshare -Core1262 has TCXO +/* +On the SX1262, DIO3 sets the voltage for an external TCXO, if one is present. If one is not present, use TCXO_OPTIONAL to try both settings. + +| Mfr | Module | TCXO | RF Switch | Notes | +| ---------- | ---------------- | ---- | --------- | -------------------------------------------- | +| Ebyte | E22-900M22S | Yes | Ext | | +| Ebyte | E22-900MM22S | No | Ext | | +| Ebyte | E22-900M30S | Yes | Ext | | +| Ebyte | E22-900M33S | Yes | Ext | MAX_POWER must be set to 8 for this | +| Ebyte | E220-900M22S | No | Ext | LLCC68, looks like DIO3 not connected at all | +| AI-Thinker | RA-01SH | No | Int | | +| Heltec | HT-RA62 | Yes | Int | | +| NiceRF | Lora1262 | yes | Int | | +| Waveshare | Core1262-HF | yes | Ext | | +| Waveshare | LoRa Node Module | yes | Int | | */ + #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define TCXO_OPTIONAL // make it so that the firmware can try both TCXO and XTAL +extern float tcxoVoltage; // make this available everywhere #ifdef __cplusplus } @@ -153,4 +160,4 @@ Core1262 has TCXO * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif \ No newline at end of file +#endif