1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-04-19 13:02:14 +03:00

Add option to specify PA output pin in Lora.setTxPower(...) (#2)

This commit is contained in:
Sandeep Mistry 2017-03-12 16:17:13 -04:00
parent ee09672759
commit 9c9914a2c4
4 changed files with 32 additions and 9 deletions

7
API.md
View File

@ -216,10 +216,15 @@ Change the TX power of the radio.
```arduino ```arduino
LoRa.setTxPower(txPower); LoRa.setTxPower(txPower);
LoRa.setTxPower(txPower, outputPin);
``` ```
* `txPower` - TX power in dB, defaults to `17` * `txPower` - TX power in dB, defaults to `17`
* `outputPin` - (optional) PA output pin, supported values are `PA_OUTPUT_RFO_PIN` and `PA_OUTPUT_PA_BOOST_PIN`, defaults to `PA_OUTPUT_PA_BOOST_PIN`.
Supported values are between `2` and `17`. Supported values are between `2` and `17` for `PA_OUTPUT_PA_BOOST_PIN`, `0` and `14` for `PA_OUTPUT_RFO_PIN`.
Most modules have the PA output pin connected to PA BOOST,
### Frequency ### Frequency

View File

@ -52,3 +52,6 @@ dumpRegisters KEYWORD2
####################################### #######################################
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################
PA_OUTPUT_RFO_PIN LITERAL1
PA_OUTPUT_PA_BOOST_PIN LITERAL1

View File

@ -297,15 +297,27 @@ void LoRaClass::sleep()
writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP); writeRegister(REG_OP_MODE, MODE_LONG_RANGE_MODE | MODE_SLEEP);
} }
void LoRaClass::setTxPower(int level) void LoRaClass::setTxPower(int level, int outputPin)
{ {
if (level < 2) { if (PA_OUTPUT_RFO_PIN == outputPin) {
level = 2; // RFO
} else if (level > 17) { if (level < 0) {
level = 17; level = 0;
} } else if (level > 14) {
level = 14;
}
writeRegister(REG_PA_CONFIG, PA_BOOST | (level - 2)); writeRegister(REG_PA_CONFIG, 0x70 | level);
} else {
// PA BOOST
if (level < 2) {
level = 2;
} else if (level > 17) {
level = 17;
}
writeRegister(REG_PA_CONFIG, PA_BOOST | (level - 2));
}
} }
void LoRaClass::setFrequency(long frequency) void LoRaClass::setFrequency(long frequency)

View File

@ -8,6 +8,9 @@
#define LORA_DEFAULT_RESET_PIN 9 #define LORA_DEFAULT_RESET_PIN 9
#define LORA_DEFAULT_DIO0_PIN 2 #define LORA_DEFAULT_DIO0_PIN 2
#define PA_OUTPUT_RFO_PIN 0
#define PA_OUTPUT_PA_BOOST_PIN 1
class LoRaClass : public Stream { class LoRaClass : public Stream {
public: public:
LoRaClass(); LoRaClass();
@ -38,7 +41,7 @@ public:
void idle(); void idle();
void sleep(); void sleep();
void setTxPower(int level); void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
void setFrequency(long frequency); void setFrequency(long frequency);
void setSpreadingFactor(int sf); void setSpreadingFactor(int sf);
void setSignalBandwidth(long sbw); void setSignalBandwidth(long sbw);