RadioLib
Universal wireless communication library for Arduino
Loading...
Searching...
No Matches
SX1272.h
1#if !defined(_RADIOLIB_SX1272_H)
2#define _RADIOLIB_SX1272_H
3
4#include "../../TypeDef.h"
5
6#if !RADIOLIB_EXCLUDE_SX127X
7
8#include "../../Module.h"
9#include "SX127x.h"
10
11// SX1272 specific register map
12#define RADIOLIB_SX1272_REG_AGC_REF 0x43
13#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44
14#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45
15#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46
16#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B
17#define RADIOLIB_SX1272_REG_TCXO 0x58
18#define RADIOLIB_SX1272_REG_PA_DAC 0x5A
19#define RADIOLIB_SX1272_REG_PLL 0x5C
20#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E
21#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C
22#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70
23
24// SX1272 LoRa modem settings
25// RADIOLIB_SX1272_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
26#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
27#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
28#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
29
30// RADIOLIB_SX127X_REG_MODEM_CONFIG_1
31#define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz
32#define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz
33#define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz
34#define RADIOLIB_SX1272_CR_4_4 0b00000000 // 5 3 error coding rate: 4/4 (undocumented)
35#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 4/5
36#define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6
37#define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7
38#define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8
39#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
40#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
41#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
42#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
43#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled
44#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
45
46// RADIOLIB_SX127X_REG_MODEM_CONFIG_2
47#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
48#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
49
50// RADIOLIB_SX127X_REG_VERSION
51#define RADIOLIB_SX1272_CHIP_VERSION 0x22
52
53// SX1272 FSK modem settings
54// RADIOLIB_SX127X_REG_OP_MODE
55#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default)
56#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0
57#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5
58#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3
59#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR
60#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR
61
62// RADIOLIB_SX127X_REG_PA_RAMP
63#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default)
64#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode
65
66// RADIOLIB_SX127X_REG_SYNC_CONFIG
67#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default)
68#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set
69
70// RADIOLIB_SX1272_REG_AGC_REF
71#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
72
73// RADIOLIB_SX1272_REG_AGC_THRESH_1
74#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold
75
76// RADIOLIB_SX1272_REG_AGC_THRESH_2
77#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold
78#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold
79
80// RADIOLIB_SX1272_REG_AGC_THRESH_3
81#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold
82#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold
83
84// RADIOLIB_SX1272_REG_PLL_LOW_PN
85#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz
86#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz
87#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
88#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
89
95class SX1272: public SX127x {
96 public:
97
98 // constructor
99
104 SX1272(Module* mod); // cppcheck-suppress noExplicitConstructor
105
106 // basic methods
107
115 virtual int16_t begin(const ConfigLoRa_t& config);
116
133 virtual int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
134
142 int16_t beginFSK(const ConfigFSK_t& config);
143
157 int16_t beginFSK(float freq = 915.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
158
162 void reset() override;
163
164 // configuration methods
165
171 int16_t setFrequency(float freq) override;
172
178 int16_t setBandwidth(float bw);
179
185 virtual int16_t setSpreadingFactor(uint8_t sf);
186
193 int16_t setCodingRate(uint8_t cr);
194
200 int16_t setBitRate(float br) override;
201
209 int16_t setDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE) override;
210
218 int16_t checkDataRate(DataRate_t dr, ModemType_t modem = RADIOLIB_MODEM_NONE) override;
219
226 int16_t setOutputPower(int8_t power) override;
227
235 int16_t setOutputPower(int8_t power, bool forceRfo);
236
244 int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
245
253 int16_t checkOutputPower(int8_t power, int8_t* clipped, bool useRfo);
254
261 int16_t setGain(uint8_t gain);
262
269 int16_t setDataShaping(uint8_t sh) override;
270
278 int16_t setDataShapingOOK(uint8_t sh);
279
285 float getRSSI() override;
286
293 float getRSSI(bool packet, bool skipReceive = false);
294
303 int16_t setCRC(bool enable, bool mode = false);
304
311 int16_t forceLDRO(bool enable);
312
318 int16_t autoLDRO();
319
325 int16_t implicitHeader(size_t len);
326
331 int16_t explicitHeader();
332
339 int16_t setModem(ModemType_t modem) override;
340
341#if !RADIOLIB_GODMODE
342 protected:
343#endif
344 int16_t setBandwidthRaw(uint8_t newBandwidth);
345 int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
346 int16_t setCodingRateRaw(uint8_t newCodingRate);
347
348 int16_t configFSK() override;
349 void errataFix(bool rx) override;
350
351};
352
353#endif
354
355#endif
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition Module.h:69
Derived class for SX1272 modules. Also used as base class for SX1273. Both modules use the same basic...
Definition SX1272.h:95
void reset() override
Reset method. Will reset the chip to the default state using RST pin.
Definition SX1272.cpp:97
int16_t setBandwidth(float bw)
Sets LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in LoRa mode.
Definition SX1272.cpp:117
int16_t checkOutputPower(int8_t power, int8_t *clipped) override
Check if output power is configurable. This method is needed for compatibility with PhysicalLayer::ch...
Definition SX1272.cpp:363
int16_t setModem(ModemType_t modem) override
Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default p...
Definition SX1272.cpp:618
int16_t setDataShapingOOK(uint8_t sh)
Sets filter cutoff frequency that will be used for data shaping. Allowed values are 1 for frequency e...
Definition SX1272.cpp:451
int16_t setDataRate(DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE) override
Set data rate.
Definition SX1272.cpp:252
int16_t forceLDRO(bool enable)
Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,...
Definition SX1272.cpp:522
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission. Required for spreading factor 6.
Definition SX1272.cpp:546
float getRSSI() override
Gets received signal strength indicator. Overload with packet mode enabled for PhysicalLayer compatib...
Definition SX1272.cpp:485
int16_t checkDataRate(DataRate_t dr, ModemType_t modem=RADIOLIB_MODEM_NONE) override
Check the data rate can be configured by this module.
Definition SX1272.cpp:295
virtual int16_t begin(const ConfigLoRa_t &config)
Initialization method for LoRa modem.
Definition SX1272.cpp:9
virtual int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa link spreading factor. Allowed values range from 6 to 12. Only available in LoRa mode.
Definition SX1272.cpp:157
int16_t setDataShaping(uint8_t sh) override
Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK...
Definition SX1272.cpp:420
int16_t setCodingRate(uint8_t cr)
Sets LoRa link coding rate denominator. Allowed values range from 4 to 8. Only available in LoRa mode...
Definition SX1272.cpp:211
int16_t setBitRate(float br) override
Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode.
Definition SX1272.cpp:248
int16_t autoLDRO()
Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,...
Definition SX1272.cpp:537
int16_t setCRC(bool enable, bool mode=false)
Enables/disables CRC check of received packets.
Definition SX1272.cpp:493
int16_t setFrequency(float freq) override
Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz.
Definition SX1272.cpp:106
int16_t setGain(uint8_t gain)
Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is...
Definition SX1272.cpp:383
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition SX1272.cpp:551
int16_t beginFSK(const ConfigFSK_t &config)
Initialization method for FSK modem.
Definition SX1272.cpp:52
int16_t setOutputPower(int8_t power) override
Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA...
Definition SX1272.cpp:323
Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from thi...
Definition SX127x.h:583
bool enableOOK
Use OOK modulation instead of FSK.
Definition SX127x.h:611
uint8_t gain
Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the ...
Definition SX127x.h:605
Definition PhysicalLayer.h:298
Definition PhysicalLayer.h:280
Common data rate structure.
Definition PhysicalLayer.h:74