Skip to content

sx127x 20dBm support 2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion API.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ LoRa.setTxPower(txPower, outputPin);
* `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` for `PA_OUTPUT_PA_BOOST_PIN`, `0` and `14` for `PA_OUTPUT_RFO_PIN`.
Supported values are `2` to `20` for `PA_OUTPUT_PA_BOOST_PIN`, and `0` to `14` for `PA_OUTPUT_RFO_PIN`.

Most modules have the PA output pin connected to PA BOOST,

Expand Down
37 changes: 33 additions & 4 deletions src/LoRa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define REG_FRF_MID 0x07
#define REG_FRF_LSB 0x08
#define REG_PA_CONFIG 0x09
#define REG_OCP 0x0b
#define REG_LNA 0x0c
#define REG_FIFO_ADDR_PTR 0x0d
#define REG_FIFO_TX_BASE_ADDR 0x0e
Expand All @@ -34,6 +35,7 @@
#define REG_SYNC_WORD 0x39
#define REG_DIO_MAPPING_1 0x40
#define REG_VERSION 0x42
#define REG_PA_DAC 0x4d

// modes
#define MODE_LONG_RANGE_MODE 0x80
Expand Down Expand Up @@ -352,10 +354,24 @@ void LoRaClass::setTxPower(int level, int outputPin)
writeRegister(REG_PA_CONFIG, 0x70 | level);
} else {
// PA BOOST
if (level < 2) {
level = 2;
} else if (level > 17) {
level = 17;
if (level > 17) {
if (level > 20) {
level = 20;
}

// subtract 3 from level, so 18 - 20 maps to 15 - 17
level -= 3;

// High Power +20 dBm Operation (Semtech SX1276/77/78/79 5.4.3.)
writeRegister(REG_PA_DAC, 0x87);
setOCP(140);
} else {
if (level < 2) {
level = 2;
}
//Default value PA_HF/LF or +17dBm
writeRegister(REG_PA_DAC, 0x84);
setOCP(100);
}

writeRegister(REG_PA_CONFIG, PA_BOOST | (level - 2));
Expand Down Expand Up @@ -472,6 +488,19 @@ void LoRaClass::disableCrc()
writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb);
}

void LoRaClass::setOCP(uint8_t mA)
{
uint8_t ocpTrim = 27;

if (mA <= 120) {
ocpTrim = (mA - 45) / 5;
} else if (mA <=240) {
ocpTrim = (mA + 30) / 10;
}

writeRegister(REG_OCP, 0x20 | (0x1F & ocpTrim));
}

byte LoRaClass::random()
{
return readRegister(REG_RSSI_WIDEBAND);
Expand Down
1 change: 1 addition & 0 deletions src/LoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class LoRaClass : public Stream {
void setSyncWord(int sw);
void enableCrc();
void disableCrc();
void setOCP(uint8_t mA); // Over Current Protection control

// deprecated
void crc() { enableCrc(); }
Expand Down