Skip to content

Commit 2a72b72

Browse files
author
Mark Zachmann
committed
update low-data-rate flag when changing bw or sf
1 parent a0eb98a commit 2a72b72

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/Sx127x.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,15 @@ static Sx127x* _Singleton = NULL;
222222
double freqHz = (double)UseParam(params, "frequency_low"); // any remaining 0...999,999 Hz
223223
this->setFrequency(freq + freqHz);
224224

225+
// set auto AGC for LNA gain. do this before setting bandwidth,spreading factor
226+
// since they set the low-data-rate flag bit in the same register
227+
this->writeRegister(REG_MODEM_CONFIG_3, 0x04);
228+
225229
this->setSignalBandwidth(UseParam(params, "signal_bandwidth"));
226230

227231
// set LNA boost
228232
this->writeRegister(REG_LNA, this->readRegister(REG_LNA) | 0x03);
229233

230-
// set auto AGC
231-
this->writeRegister(REG_MODEM_CONFIG_3, 0x04);
232-
233234
int powerpin = UseParam(params, "power_pin"); // powerpin = PA_OUTPUT_PA_BOOST_PIN or PA_OUTPUT_RFO_PIN
234235
if(powerpin != PA_OUTPUT_PA_BOOST_PIN && powerpin != PA_OUTPUT_RFO_PIN)
235236
{
@@ -540,16 +541,18 @@ static Sx127x* _Singleton = NULL;
540541
{
541542
ASeries.printf("Set spreading factor to: %d", sf);
542543
sf = min(max(sf, 6), 12);
544+
_SpreadingFactor = sf;
543545
this->writeRegister(REG_DETECTION_OPTIMIZE, (sf == 6) ? 0xc5 : 0xc3);
544546
this->writeRegister(REG_DETECTION_THRESHOLD, (sf == 6) ? 0x0c : 0x0a);
545547
this->writeRegister(REG_MODEM_CONFIG_2, (this->readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
548+
setLowDataRate(); // set the low-data-rate flag
546549
}
547550

548551
void Sx127x::setSignalBandwidth(int sbw)
549552
{
550553
ASeries.printf("Set sbw to: %d", sbw);
551-
int bins[] = {7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000, 250000};
552-
int bw = 9;
554+
int bins[] = {7800, 10400, 15600, 20800, 31250, 41700, 62500, 125000, 250000, 500000};
555+
int bw = 9; // default to 500K
553556
for (int i=0; i<ARRAY_SIZE(bins); i++)
554557
{
555558
if (sbw <= bins[i])
@@ -558,7 +561,9 @@ static Sx127x* _Singleton = NULL;
558561
break;
559562
}
560563
}
564+
_SignalBandwidth = bins[bw];
561565
this->writeRegister(REG_MODEM_CONFIG_1, (this->readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4));
566+
setLowDataRate(); // set the low-data-rate flag
562567
}
563568

564569
void Sx127x::setCodingRate(int denominator)
@@ -797,6 +802,17 @@ static Sx127x* _Singleton = NULL;
797802
}
798803
}
799804

805+
// the low data rate flag must be set dependent on the symbol duration > 16ms per spec
806+
void Sx127x::setLowDataRate()
807+
{
808+
// get symbol duration in ms. Spreading factor max=12 so bw/(2**sf) > 6
809+
uint16_t symbolDuration = 1000 / ( _SignalBandwidth / (1L << _SpreadingFactor) );
810+
uint8_t config3 = readRegister(REG_MODEM_CONFIG_3);
811+
bitWrite(config3, 3, symbolDuration > 16); // set the flag on iff >16ms symbol duration
812+
ASeries.printf("Set low data rate flag register: %d", config3);
813+
writeRegister(REG_MODEM_CONFIG_3, config3);
814+
}
815+
800816
// This calibrates the system and it reads the current
801817
// chip temperature as an integer. Standard is around 242 at 25C.
802818
// The manual says calibration should be done when frequency is set to other than default.

src/Sx127x.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class Sx127x
100100
String _LastError;
101101
int _IrqPin; // the irq pin
102102
bool _ImplicitHeaderMode;
103+
uint8_t _SpreadingFactor; // the spreading factor setting
104+
uint32_t _SignalBandwidth; // the signal bandwidth
103105
double _Frequency; // in Hz
104106
double _FrequencyOffset; // for temperature and static compensation
105107
uint32_t _LastReceivedTime; // last receive interrupt time in milliseconds

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy