@@ -222,14 +222,15 @@ static Sx127x* _Singleton = NULL;
222
222
double freqHz = (double )UseParam (params, " frequency_low" ); // any remaining 0...999,999 Hz
223
223
this ->setFrequency (freq + freqHz);
224
224
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
+
225
229
this ->setSignalBandwidth (UseParam (params, " signal_bandwidth" ));
226
230
227
231
// set LNA boost
228
232
this ->writeRegister (REG_LNA, this ->readRegister (REG_LNA) | 0x03 );
229
233
230
- // set auto AGC
231
- this ->writeRegister (REG_MODEM_CONFIG_3, 0x04 );
232
-
233
234
int powerpin = UseParam (params, " power_pin" ); // powerpin = PA_OUTPUT_PA_BOOST_PIN or PA_OUTPUT_RFO_PIN
234
235
if (powerpin != PA_OUTPUT_PA_BOOST_PIN && powerpin != PA_OUTPUT_RFO_PIN)
235
236
{
@@ -540,16 +541,18 @@ static Sx127x* _Singleton = NULL;
540
541
{
541
542
ASeries.printf (" Set spreading factor to: %d" , sf);
542
543
sf = min (max (sf, 6 ), 12 );
544
+ _SpreadingFactor = sf;
543
545
this ->writeRegister (REG_DETECTION_OPTIMIZE, (sf == 6 ) ? 0xc5 : 0xc3 );
544
546
this ->writeRegister (REG_DETECTION_THRESHOLD, (sf == 6 ) ? 0x0c : 0x0a );
545
547
this ->writeRegister (REG_MODEM_CONFIG_2, (this ->readRegister (REG_MODEM_CONFIG_2) & 0x0f ) | ((sf << 4 ) & 0xf0 ));
548
+ setLowDataRate (); // set the low-data-rate flag
546
549
}
547
550
548
551
void Sx127x::setSignalBandwidth (int sbw)
549
552
{
550
553
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
553
556
for (int i=0 ; i<ARRAY_SIZE (bins); i++)
554
557
{
555
558
if (sbw <= bins[i])
@@ -558,7 +561,9 @@ static Sx127x* _Singleton = NULL;
558
561
break ;
559
562
}
560
563
}
564
+ _SignalBandwidth = bins[bw];
561
565
this ->writeRegister (REG_MODEM_CONFIG_1, (this ->readRegister (REG_MODEM_CONFIG_1) & 0x0f ) | (bw << 4 ));
566
+ setLowDataRate (); // set the low-data-rate flag
562
567
}
563
568
564
569
void Sx127x::setCodingRate (int denominator)
@@ -797,6 +802,17 @@ static Sx127x* _Singleton = NULL;
797
802
}
798
803
}
799
804
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
+
800
816
// This calibrates the system and it reads the current
801
817
// chip temperature as an integer. Standard is around 242 at 25C.
802
818
// The manual says calibration should be done when frequency is set to other than default.
0 commit comments