Skip to content

sx127x 20dBm support #79

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

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 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 @@ -31,6 +32,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 @@ -426,6 +428,31 @@ void LoRaClass::disableCrc()
writeRegister(REG_MODEM_CONFIG_2, readRegister(REG_MODEM_CONFIG_2) & 0xfb);
}

void LoRaClass::set20dBm_sx127x(bool turn_on)
{
if (turn_on) {
writeRegister(REG_PA_CONFIG, PA_BOOST | (17 - 2));
writeRegister(REG_PA_DAC, 0x87); //Value for High Power
setOCP_sx127x(140);
}
else {
writeRegister(REG_PA_DAC, 0x84); //Default value PA_HF/LF or +17dBm
setOCP_sx127x(100);
}
}

void LoRaClass::setOCP_sx127x(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
6 changes: 6 additions & 0 deletions src/LoRa.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class LoRaClass : public Stream {
void enableCrc();
void disableCrc();

// High Power +20 dBm Operation (Semtech SX1276/77/78/79 5.4.3.)
// Only with PA_BOOST pin connected
void set20dBm_sx127x(bool turn_on);
// Over Current Protection control (Semtech SX1276/77/78/79 5.4.4.)
void setOCP_sx127x(uint8_t mA);

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