From 7f2663366ec7a4bcdac1d43a0d0e17e231d90e66 Mon Sep 17 00:00:00 2001 From: tomelec Date: Mon, 14 Oct 2019 23:16:30 +0200 Subject: [PATCH] LoRa: Enable LowDataRateOptimize for symbol length >16ms --- LoRa.cpp | 16 ++++++++++++++++ LoRa.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/LoRa.cpp b/LoRa.cpp index eb3ec2a..dcf5edc 100644 --- a/LoRa.cpp +++ b/LoRa.cpp @@ -418,6 +418,8 @@ void LoRaClass::setSpreadingFactor(int sf) } writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0)); + + handleLowDataRate(); } long LoRaClass::getSignalBandwidth() @@ -437,6 +439,18 @@ long LoRaClass::getSignalBandwidth() } } +void LoRaClass::handleLowDataRate(){ + int sf = (readRegister(REG_MODEM_CONFIG_2) >> 4); + if ( long( (1< 16) { + // set auto AGC and LowDataRateOptimize + writeRegister(REG_MODEM_CONFIG_3, (1<<3)|(1<<2)); + } + else { + // set auto AGC + writeRegister(REG_MODEM_CONFIG_3, (1<<2)); + } +} + void LoRaClass::setSignalBandwidth(long sbw) { int bw; @@ -464,6 +478,8 @@ void LoRaClass::setSignalBandwidth(long sbw) } writeRegister(REG_MODEM_CONFIG_1, (readRegister(REG_MODEM_CONFIG_1) & 0x0f) | (bw << 4)); + + handleLowDataRate(); } void LoRaClass::setCodingRate4(int denominator) diff --git a/LoRa.h b/LoRa.h index c65ce64..f191a74 100644 --- a/LoRa.h +++ b/LoRa.h @@ -82,6 +82,8 @@ private: static void onDio0Rise(); + void handleLowDataRate(); + private: SPISettings _spiSettings; int _ss;