1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-06-12 19:41:53 +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
5 changed files with 85 additions and 43 deletions

11
API.md
View File

@ -363,6 +363,17 @@ LoRa.enableInvertIQ();
LoRa.disableInvertIQ(); 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 ## Other functions

View File

@ -1,43 +1,45 @@
#include <SPI.h> #include <SPI.h>
#include <LoRa.h> #include <LoRa.h>
#ifdef ARDUINO_SAMD_MKRWAN1300 #ifdef ARDUINO_SAMD_MKRWAN1300
#error "This example is not compatible with the Arduino MKR WAN 1300 board!" #error "This example is not compatible with the Arduino MKR WAN 1300 board!"
#endif #endif
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
while (!Serial); while (!Serial);
Serial.println("LoRa Receiver Callback"); Serial.println("LoRa Receiver Callback");
if (!LoRa.begin(915E6)) { if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!"); Serial.println("Starting LoRa failed!");
while (1); while (1);
} }
// register the receive callback // Uncomment the next line to disable the default AGC and set LNA gain, values between 1 - 6 are supported
LoRa.onReceive(onReceive); // LoRa.setGain(6);
// put the radio into receive mode // register the receive callback
LoRa.receive(); LoRa.onReceive(onReceive);
}
// put the radio into receive mode
void loop() { LoRa.receive();
// do nothing }
}
void loop() {
void onReceive(int packetSize) { // do nothing
// received a packet }
Serial.print("Received packet '");
void onReceive(int packetSize) {
// read packet // received a packet
for (int i = 0; i < packetSize; i++) { Serial.print("Received packet '");
Serial.print((char)LoRa.read());
} // read packet
for (int i = 0; i < packetSize; i++) {
// print RSSI of packet Serial.print((char)LoRa.read());
Serial.print("' with RSSI "); }
Serial.println(LoRa.packetRssi());
} // print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}

View File

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

View File

@ -607,6 +607,32 @@ void LoRaClass::setOCP(uint8_t mA)
writeRegister(REG_OCP, 0x20 | (0x1F & ocpTrim)); 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() byte LoRaClass::random()
{ {
return readRegister(REG_RSSI_WIDEBAND); return readRegister(REG_RSSI_WIDEBAND);

View File

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