From 078641d64d31a7a88e3546bedc2c828a38ba8222 Mon Sep 17 00:00:00 2001 From: BarryPSmith Date: Mon, 11 Nov 2019 09:11:35 -0800 Subject: [PATCH 1/3] Implemented TX PA Clamping, datasheet section 15.2 --- src/modules/SX1262.cpp | 15 +++++++++++++++ src/modules/SX1262.h | 7 +++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/modules/SX1262.cpp b/src/modules/SX1262.cpp index 0bcce47d..59ee7225 100644 --- a/src/modules/SX1262.cpp +++ b/src/modules/SX1262.cpp @@ -22,6 +22,11 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syn return(state); } + state = fixPaClamping(); + if (state != ERR_NONE) { + return state; + } + return(state); } @@ -110,3 +115,13 @@ int16_t SX1262::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); } + +int16_t SX1262::fixPaClamping() { + uint8_t clampConfig; + uint16_t state = readRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); + if (state != ERR_NONE) { + return state; + } + clampConfig |= 0x1E; + return writeRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); +} diff --git a/src/modules/SX1262.h b/src/modules/SX1262.h index 88a49576..5e23d73f 100644 --- a/src/modules/SX1262.h +++ b/src/modules/SX1262.h @@ -8,6 +8,7 @@ //SX126X_CMD_SET_PA_CONFIG #define SX126X_PA_CONFIG_SX1261 0x01 #define SX126X_PA_CONFIG_SX1262 0x00 +#define SX126X_REG_TX_CLAMP_CONFIG 0x08D8 //Datasheet 15.2 /*! \class SX1262 @@ -94,8 +95,10 @@ class SX1262: public SX126x { int16_t setOutputPower(int8_t power); private: - - + /*! + \brief Fixes overly eager PA clamping, as described in section 15.2 of the datasheet + */ + int16_t fixPaClamping(); }; #endif From b8b05262bc15fc14c4c2bc51cbd0a1d7b62fccc4 Mon Sep 17 00:00:00 2001 From: BarryPSmith Date: Tue, 12 Nov 2019 10:39:44 -0800 Subject: [PATCH 2/3] Added PA Clamping fix to FSK and SX1268 --- src/modules/SX1262.cpp | 19 +++++++------------ src/modules/SX1262.h | 5 ----- src/modules/SX1268.cpp | 10 ++++++++++ src/modules/SX126x.cpp | 10 ++++++++++ src/modules/SX126x.h | 5 +++++ 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/modules/SX1262.cpp b/src/modules/SX1262.cpp index 59ee7225..a3b3ad47 100644 --- a/src/modules/SX1262.cpp +++ b/src/modules/SX1262.cpp @@ -22,7 +22,7 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syn return(state); } - state = fixPaClamping(); + state = SX126x::fixPaClamping(); if (state != ERR_NONE) { return state; } @@ -48,6 +48,11 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t return(state); } + state = SX126x::fixPaClamping(); + if (state != ERR_NONE) { + return state; + } + return(state); } @@ -114,14 +119,4 @@ int16_t SX1262::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); -} - -int16_t SX1262::fixPaClamping() { - uint8_t clampConfig; - uint16_t state = readRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); - if (state != ERR_NONE) { - return state; - } - clampConfig |= 0x1E; - return writeRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); -} +} \ No newline at end of file diff --git a/src/modules/SX1262.h b/src/modules/SX1262.h index 5e23d73f..3aef48ee 100644 --- a/src/modules/SX1262.h +++ b/src/modules/SX1262.h @@ -8,7 +8,6 @@ //SX126X_CMD_SET_PA_CONFIG #define SX126X_PA_CONFIG_SX1261 0x01 #define SX126X_PA_CONFIG_SX1262 0x00 -#define SX126X_REG_TX_CLAMP_CONFIG 0x08D8 //Datasheet 15.2 /*! \class SX1262 @@ -95,10 +94,6 @@ class SX1262: public SX126x { int16_t setOutputPower(int8_t power); private: - /*! - \brief Fixes overly eager PA clamping, as described in section 15.2 of the datasheet - */ - int16_t fixPaClamping(); }; #endif diff --git a/src/modules/SX1268.cpp b/src/modules/SX1268.cpp index c0b01a80..bd5297d9 100644 --- a/src/modules/SX1268.cpp +++ b/src/modules/SX1268.cpp @@ -22,6 +22,11 @@ int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint16_t syn return(state); } + state = SX126x::fixPaClamping(); + if (state != ERR_NONE) { + return state; + } + return(state); } int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, float currentLimit, uint16_t preambleLength, float dataShaping) { @@ -42,6 +47,11 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t return(state); } + state = SX126x::fixPaClamping(); + if (state != ERR_NONE) { + return state; + } + return(state); } diff --git a/src/modules/SX126x.cpp b/src/modules/SX126x.cpp index e47ad31c..6d8a934b 100644 --- a/src/modules/SX126x.cpp +++ b/src/modules/SX126x.cpp @@ -1202,6 +1202,16 @@ int16_t SX126x::setFrequencyRaw(float freq) { return(ERR_NONE); } +int16_t SX126x::fixPaClamping() { + uint8_t clampConfig; + uint16_t state = readRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); + if (state != ERR_NONE) { + return state; + } + clampConfig |= 0x1E; + return writeRegister(SX126X_REG_TX_CLAMP_CONFIG, &clampConfig, 1); +} + int16_t SX126x::config(uint8_t modem) { // set regulator mode uint8_t data[7]; diff --git a/src/modules/SX126x.h b/src/modules/SX126x.h index 641d6445..a73eb44d 100644 --- a/src/modules/SX126x.h +++ b/src/modules/SX126x.h @@ -92,6 +92,7 @@ #define SX126X_REG_OCP_CONFIGURATION 0x08E7 #define SX126X_REG_XTA_TRIM 0x0911 #define SX126X_REG_XTB_TRIM 0x0912 +#define SX126X_REG_TX_CLAMP_CONFIG 0x08D8 //Datasheet 15.2 // SX126X SPI command variables @@ -751,6 +752,10 @@ class SX126x: public PhysicalLayer { int16_t setFrequencyRaw(float freq); + /*! + \brief Fixes overly eager PA clamping on SX1262 / SX1268, as described in section 15.2 of the datasheet + */ + int16_t fixPaClamping(); private: Module* _mod; From 5acaf1dfb6e44be22692d93ec6617ad4ddb24a2d Mon Sep 17 00:00:00 2001 From: BarryPSmith Date: Wed, 13 Nov 2019 07:20:21 -0800 Subject: [PATCH 3/3] Fixed a conflict with return brackets. --- src/modules/SX1262.cpp | 2 +- src/modules/SX126x.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/SX1262.cpp b/src/modules/SX1262.cpp index a3b3ad47..75030e54 100644 --- a/src/modules/SX1262.cpp +++ b/src/modules/SX1262.cpp @@ -119,4 +119,4 @@ int16_t SX1262::setOutputPower(int8_t power) { // restore OCP configuration return(writeRegister(SX126X_REG_OCP_CONFIGURATION, &ocp, 1)); -} \ No newline at end of file +} diff --git a/src/modules/SX126x.h b/src/modules/SX126x.h index a73eb44d..70b46dad 100644 --- a/src/modules/SX126x.h +++ b/src/modules/SX126x.h @@ -772,6 +772,8 @@ class SX126x: public PhysicalLayer { int16_t config(uint8_t modem); + + // common low-level SPI interface int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true); int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes, bool waitForBusy = true);