diff --git a/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino b/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino index ae15238a..1e16e593 100644 --- a/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino +++ b/examples/SX126x/SX126x_Channel_Activity_Detection/SX126x_Channel_Activity_Detection.ino @@ -1,9 +1,9 @@ /* RadioLib SX126x Channel Activity Detection Example - This example uses SX1262 to scan the current LoRa + This example uses SX1262 to scan the current LoRa channel and detect ongoing LoRa transmissions. - Unlike SX127x CAD, SX126x can detect any part + Unlike SX127x CAD, SX126x can detect any part of LoRa transmission, not just the preamble. Other modules from SX126x family can also be used. @@ -39,6 +39,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = lora.begin(); if (state == ERR_NONE) { diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index 18050269..cc22f18a 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -40,6 +40,7 @@ void setup() { // current limit: 60.0 mA // preamble length: 16 bits // data shaping: Gaussian, BT = 0.5 + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // sync word: 0x2D 0x01 // CRC: enabled, CRC16 (CCIT) int state = fsk.beginFSK(); @@ -73,7 +74,7 @@ void setup() { Serial.println(state); while (true); } - + // FSK modem on SX126x can handle the sync word setting in bits, not just // whole bytes. The value used is left-justified. // This makes same result as fsk.setSyncWord(syncWord, 8): diff --git a/examples/SX126x/SX126x_Receive/SX126x_Receive.ino b/examples/SX126x/SX126x_Receive/SX126x_Receive.ino index 2f6f8319..e52d2f71 100644 --- a/examples/SX126x/SX126x_Receive/SX126x_Receive.ino +++ b/examples/SX126x/SX126x_Receive/SX126x_Receive.ino @@ -44,6 +44,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = lora.begin(); if (state == ERR_NONE) { @@ -53,28 +54,6 @@ void setup() { Serial.println(state); while (true); } - - // NOTE: Some SX126x modules use TCXO - // (Temprature-Compensated Crystal Oscillator). - // To be able to use these modules, TCXO - // control must be enabled by calling - // setTCXO() and specifying the reference - // voltage. - - /* - Serial.print(F("[SX1262] Setting TCXO reference ... ")); - // enable TCXO - // reference voltage: 1.6 V - // timeout: 5000 us - state = lora.setTCXO(1.6); - if (state == ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - */ } void loop() { diff --git a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino index f61f1602..4fec5d88 100644 --- a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino +++ b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino @@ -45,6 +45,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = lora.begin(); if (state == ERR_NONE) { diff --git a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino index aa509377..6e514a9a 100644 --- a/examples/SX126x/SX126x_Settings/SX126x_Settings.ino +++ b/examples/SX126x/SX126x_Settings/SX126x_Settings.ino @@ -55,6 +55,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = loraSX1262.begin(); if (state == ERR_NONE) { diff --git a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino index 65d24eec..76213f42 100644 --- a/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino +++ b/examples/SX126x/SX126x_Transmit/SX126x_Transmit.ino @@ -40,6 +40,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = lora.begin(); if (state == ERR_NONE) { @@ -49,29 +50,6 @@ void setup() { Serial.println(state); while (true); } - - // NOTE: Some SX126x modules use TCXO - // (Temprature-Compensated Crystal Oscillator). - // To be able to use these modules, TCXO - // control must be enabled by calling - // setTCXO() and specifying the reference - // voltage. - - /* - Serial.print(F("[SX1262] Setting TCXO reference ... ")); - // enable TCXO - // reference voltage: 1.6 V - // timeout: 5000 us - state = lora.setTCXO(1.6); - if (state == ERR_NONE) { - Serial.println(F("success!")); - } else { - Serial.print(F("failed, code ")); - Serial.println(state); - while (true); - } - */ - } void loop() { diff --git a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino index f295c2e5..c06f7cdd 100644 --- a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino +++ b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino @@ -40,6 +40,7 @@ void setup() { // output power: 14 dBm // current limit: 60 mA // preamble length: 8 symbols + // TCXO voltage: 1.6 V (set to 0 to not use TCXO) // CRC: enabled int state = lora.begin(); if (state == ERR_NONE) { diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index 345c7db6..12e1c4b8 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -4,9 +4,9 @@ SX1262::SX1262(Module* mod) : SX126x(mod) { } -int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength) { +int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) { // execute common part - int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength); + int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage); if(state != ERR_NONE) { return(state); } @@ -30,9 +30,9 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syn return(state); } -int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping) { +int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage) { // execute common part - int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping); + int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage); if(state != ERR_NONE) { return(state); } @@ -106,7 +106,7 @@ int16_t SX1262::setOutputPower(int8_t power) { return(state); } - // this function sets the optimal PA settings + // this function sets the optimal PA settings // and adjusts power based on the PA settings chosen // so that output power matches requested power. state = SX126x::setOptimalHiPowerPaConfig(&power); diff --git a/src/modules/SX126x/SX1262.h b/src/modules/SX126x/SX1262.h index de0b5888..513bc766 100644 --- a/src/modules/SX126x/SX1262.h +++ b/src/modules/SX126x/SX1262.h @@ -40,9 +40,11 @@ class SX1262: public SX126x { \param preambleLength LoRa preamble length in symbols.Defaults to 8 symbols. + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6); /*! \brief Initialization method for FSK modem. @@ -63,9 +65,11 @@ class SX1262: public SX126x { \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5, float tcxoVoltage = 1.6); // configuration methods diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 44a671a7..cb064702 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -4,9 +4,9 @@ SX1268::SX1268(Module* mod) : SX126x(mod) { } -int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength) { +int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, int8_t power, float currentLimit, uint16_t preambleLength, float tcxoVoltage) { // execute common part - int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength); + int16_t state = SX126x::begin(bw, sf, cr, syncWord, currentLimit, preambleLength, tcxoVoltage); if(state != ERR_NONE) { return(state); } @@ -29,9 +29,9 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syn return(state); } -int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping) { +int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage) { // execute common part - int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping); + int16_t state = SX126x::beginFSK(br, freqDev, rxBw, currentLimit, preambleLength, dataShaping, tcxoVoltage); if(state != ERR_NONE) { return(state); } diff --git a/src/modules/SX126x/SX1268.h b/src/modules/SX126x/SX1268.h index 8f989498..5a1453d2 100644 --- a/src/modules/SX126x/SX1268.h +++ b/src/modules/SX126x/SX1268.h @@ -41,11 +41,13 @@ class SX1268: public SX126x { \param currentLimit Current protection limit in mA. Defaults to 60.0 mA. - \param preambleLength LoRa preamble length in symbols.Defaults to 8 symbols. + \param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols. + + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. \returns \ref status_codes */ - int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8); + int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint16_t syncWord = SX126X_SYNC_WORD_PRIVATE, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 8, float tcxoVoltage = 1.6); /*! \brief Initialization method for FSK modem. @@ -66,9 +68,11 @@ class SX1268: public SX126x { \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5. + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \returns \ref status_codes */ - int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5); + int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 156.2, int8_t power = 14, float currentLimit = 60.0, uint16_t preambleLength = 16, float dataShaping = 0.5, float tcxoVoltage = 1.6); // configuration methods diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 92d607ee..736d9af9 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -4,7 +4,7 @@ SX126x::SX126x(Module* mod) : PhysicalLayer(SX126X_CRYSTAL_FREQ, SX126X_DIV_EXPO _mod = mod; } -int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength) { +int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage) { // set module properties _mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH); pinMode(_mod->getRx(), INPUT); @@ -32,6 +32,14 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float return(state); } + // set TCXO control, if requested + if(tcxoVoltage > 0.0) { + state = setTCXO(tcxoVoltage); + if(state != ERR_NONE) { + return(state); + } + } + // configure publicly accessible settings state = setSpreadingFactor(sf); if(state != ERR_NONE) { @@ -69,7 +77,7 @@ int16_t SX126x::begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float return(state); } -int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping) { +int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage) { // set module properties _mod->init(RADIOLIB_USE_SPI, RADIOLIB_INT_BOTH); pinMode(_mod->getRx(), INPUT); @@ -96,6 +104,14 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, float currentLimit return(state); } + // set TCXO control, if requested + if(tcxoVoltage > 0.0) { + state = setTCXO(tcxoVoltage); + if(state != ERR_NONE) { + return(state); + } + } + // configure publicly accessible settings state = setBitRate(br); if(state != ERR_NONE) { @@ -1384,7 +1400,8 @@ int16_t SX126x::config(uint8_t modem) { } // wait for calibration completion - delayMicroseconds(1); + //delayMicroseconds(1); + delay(5); while(digitalRead(_mod->getRx())); return(ERR_NONE); diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 9bfac2fd..d9da46bf 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -367,9 +367,11 @@ class SX126x: public PhysicalLayer { \param preambleLength LoRa preamble length in symbols. Allowed values range from 1 to 65535. + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \returns \ref status_codes */ - int16_t begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength); + int16_t begin(float bw, uint8_t sf, uint8_t cr, uint16_t syncWord, float currentLimit, uint16_t preambleLength, float tcxoVoltage); /*! \brief Initialization method for FSK modem. @@ -386,9 +388,11 @@ class SX126x: public PhysicalLayer { \param dataShaping Time-bandwidth product of the Gaussian filter to be used for shaping. Allowed values are 0.3, 0.5, 0.7 and 1.0. Set to 0 to disable shaping. + \param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip. + \returns \ref status_codes */ - int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping); + int16_t beginFSK(float br, float freqDev, float rxBw, float currentLimit, uint16_t preambleLength, float dataShaping, float tcxoVoltage); /*! \brief Blocking binary transmit method.