1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-04-25 09:22:31 +03:00

Added setGain for LNA Gain (#408)

* Added setGain for LNA Gain

Added setGain for LNA Gain

* Update API.md

Added API for setGain

* Added example to use setGain

Just use setGain after LoRa.begin
// set maximum LNA for better RX sensitivity
// 0: ADC is used and LNA gain is not used.
// 1-6: ADC is not used and LNA gain is used.
LoRa.setGain(6);

* Fixed spacing only

To change tabs to spaces.

* Delete LoRaReceiverCallbackWithLNAGain.ino

To remove as unnecessary.

* To add example for setGain

To add example for setGain as an optional setting.

* Added setGain

To add setGain

* Fixed typo for AGC

Fixed typo for AGC

* Fixed comment for LoRa.setGain(6)

* Make comment for setGain simpler

Make comment for setGain simpler
This commit is contained in:
IoTThinks.com 2020-11-11 08:51:26 +07:00 committed by GitHub
parent 21ec3d44bd
commit 090fe65108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 85 additions and 43 deletions

11
API.md
View File

@ -363,6 +363,17 @@ LoRa.enableInvertIQ();
LoRa.disableInvertIQ();
```
### LNA Gain
Set LNA Gain for better RX sensitivity, by default AGC (Automatic Gain Control) is used and LNA gain is not used.
```arduino
LoRa.setGain(gain);
```
* `gain` - LNA gain
Supported values are between `0` and `6`. If gain is 0, AGC will be enabled and LNA gain will not be used. Else if gain is from 1 to 6, AGC will be disabled and LNA gain will be used.
## Other functions

View File

@ -16,6 +16,9 @@ void setup() {
while (1);
}
// Uncomment the next line to disable the default AGC and set LNA gain, values between 1 - 6 are supported
// LoRa.setGain(6);
// register the receive callback
LoRa.onReceive(onReceive);
@ -40,4 +43,3 @@ void onReceive(int packetSize) {
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}

View File

@ -47,6 +47,7 @@ enableCrc KEYWORD2
disableCrc KEYWORD2
enableInvertIQ KEYWORD2
disableInvertIQ KEYWORD2
setGain KEYWORD2
random KEYWORD2
setPins KEYWORD2

View File

@ -607,6 +607,32 @@ void LoRaClass::setOCP(uint8_t mA)
writeRegister(REG_OCP, 0x20 | (0x1F & ocpTrim));
}
void LoRaClass::setGain(uint8_t gain)
{
// check allowed range
if (gain > 6) {
gain = 6;
}
// set to standby
idle();
// set gain
if (gain == 0) {
// if gain = 0, enable AGC
writeRegister(REG_MODEM_CONFIG_3, 0x04);
} else {
// disable AGC
writeRegister(REG_MODEM_CONFIG_3, 0x00);
// clear Gain and set LNA boost
writeRegister(REG_LNA, 0x03);
// set gain
writeRegister(REG_LNA, readRegister(REG_LNA) | (gain << 5));
}
}
byte LoRaClass::random()
{
return readRegister(REG_RSSI_WIDEBAND);

View File

@ -78,6 +78,8 @@ public:
void setOCP(uint8_t mA); // Over Current Protection control
void setGain(uint8_t gain); // Set LNA gain
// deprecated
void crc() { enableCrc(); }
void noCrc() { disableCrc(); }