[SX126x] Added TCXO to begin method (#74)

This commit is contained in:
jgromes 2019-11-26 21:22:47 +01:00
parent 4e847b2ec0
commit 49f6a7c75a
13 changed files with 58 additions and 67 deletions

View file

@ -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) {

View file

@ -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):

View file

@ -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() {

View file

@ -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) {

View file

@ -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) {

View file

@ -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() {

View file

@ -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) {

View file

@ -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);

View file

@ -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

View file

@ -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);
}

View file

@ -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

View file

@ -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);

View file

@ -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.