RadioLib Universal wireless communication library for Arduino

SX1278.h
1 #if !defined(_RADIOLIB_SX1278_H)
2 #define _RADIOLIB_SX1278_H
3
4 #include "../../TypeDef.h"
5
6 #if !RADIOLIB_EXCLUDE_SX127X
7
8 #include "../../Module.h"
9 #include "SX127x.h"
10
11 // SX1278 specific register map
12 #define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26
13 #define RADIOLIB_SX1278_REG_PLL_HOP 0x44
14 #define RADIOLIB_SX1278_REG_TCXO 0x4B
15 #define RADIOLIB_SX1278_REG_PA_DAC 0x4D
16 #define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B
17 #define RADIOLIB_SX1278_REG_BIT_RATE_FRAC 0x5D
18 #define RADIOLIB_SX1278_REG_AGC_REF 0x61
19 #define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62
20 #define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63
21 #define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64
22 #define RADIOLIB_SX1278_REG_PLL 0x70
23
24 // SX1278 LoRa modem settings
25 // RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION
26 #define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
27 #define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
28
29 // RADIOLIB_SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
30 #define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
31 #define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
32 #define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
33
34 // RADIOLIB_SX1278_REG_PA_CONFIG
35 #define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
36 #define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4
37
38 // RADIOLIB_SX1278_REG_LNA
39 #define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
40
41 // SX127X_REG_MODEM_CONFIG_1
42 #define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz
43 #define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz
44 #define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz
45 #define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz
46 #define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz
47 #define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz
48 #define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz
49 #define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz
50 #define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz
51 #define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz
52 #define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5
53 #define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6
54 #define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7
55 #define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8
56 #define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
57 #define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
58
59 // SX127X_REG_MODEM_CONFIG_2
60 #define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
61 #define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
62
63 // RADIOLIB_SX1278_REG_MODEM_CONFIG_3
64 #define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
65 #define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
66 #define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
67 #define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
68
69 // SX127X_REG_VERSION
70 #define RADIOLIB_SX1278_CHIP_VERSION 0x12 // this is the "official" version listed in datasheet
71 #define RADIOLIB_SX1278_CHIP_VERSION_ALT 0x13 // appears sometimes
72 #define RADIOLIB_SX1278_CHIP_VERSION_RFM9X 0x11 // this value is used for the RFM9x
73
74 // SX1278 FSK modem settings
75 // SX127X_REG_PA_RAMP
76 #define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default)
77 #define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0
78 #define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5
79 #define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3
80 #define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR
81 #define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR
82
83 // RADIOLIB_SX1278_REG_AGC_REF
84 #define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz
85 #define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz
86
87 // RADIOLIB_SX1278_REG_AGC_THRESH_1
88 #define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz
89 #define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz
90
91 // RADIOLIB_SX1278_REG_AGC_THRESH_2
92 #define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz
93 #define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz
94 #define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold
95
96 // RADIOLIB_SX1278_REG_AGC_THRESH_3
97 #define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
98 #define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
99
105 class SX1278: public SX127x {
106 public:
107
108 // constructor
109
114 SX1278(Module* mod);
115
116 // basic methods
117
132 int16_t begin(float freq = 434.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);
133
146 int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
147
151 void reset() override;
152
153 // configuration methods
154
160 int16_t setFrequency(float freq);
161
167 int16_t setBandwidth(float bw);
168
174 int16_t setSpreadingFactor(uint8_t sf);
175
181 int16_t setCodingRate(uint8_t cr);
182
188 int16_t setBitRate(float br) override;
189
195 int16_t setDataRate(DataRate_t dr) override;
196
202 int16_t checkDataRate(DataRate_t dr) override;
203
210 int16_t setOutputPower(int8_t power) override;
211
219 int16_t setOutputPower(int8_t power, bool useRfo);
220
227 int16_t setGain(uint8_t gain);
228
235 int16_t setDataShaping(uint8_t sh) override;
236
244 int16_t setDataShapingOOK(uint8_t sh);
245
251 float getRSSI();
252
259 float getRSSI(bool packet, bool skipReceive = false);
260
268 int16_t setCRC(bool enable, bool mode = false);
269
277 int16_t forceLDRO(bool enable);
278
284 int16_t autoLDRO();
285
291 int16_t implicitHeader(size_t len);
292
297 int16_t explicitHeader();
298
299 #if !RADIOLIB_GODMODE
300 protected:
301 #endif
302 int16_t setBandwidthRaw(uint8_t newBandwidth);
303 int16_t setSpreadingFactorRaw(uint8_t newSpreadingFactor);
304 int16_t setCodingRateRaw(uint8_t newCodingRate);
305 int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
306
307 int16_t configFSK();
308 void errataFix(bool rx);
309
310 #if !RADIOLIB_GODMODE
311 private:
312 #endif
313 bool ldroAuto = true;
314 bool ldroEnabled = false;
315
316 };
317
322 RADIOLIB_TYPE_ALIAS(SX1278, RFM98)
323
324 #endif
325
326 #endif
Module
Implements all common low-level methods to control the wireless module. Every module class contains o...
Definition: Module.h:68
RFM98
Only exists as alias for SX1278, since there seems to be no difference between RFM98 and SX1278 modul...
SX1278
Derived class for SX1278 modules. Also used as base class for SX1276, SX1277, SX1279,...
Definition: SX1278.h:105
SX1278::SX1278
SX1278(Module *mod)
Default constructor. Called from Arduino sketch when creating new LoRa instance.
Definition: SX1278.cpp:5
SX1278::getRSSI
float getRSSI()
Gets recorded signal strength indicator. Overload with packet mode enabled for PhysicalLayer compatib...
Definition: SX1278.cpp:451
SX1278::setDataShapingOOK
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: SX1278.cpp:418
SX1278::setDataRate
int16_t setDataRate(DataRate_t dr) override
Set data.
Definition: SX1278.cpp:240
SX1278::setBandwidth
int16_t setBandwidth(float bw)
Sets LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125,...
Definition: SX1278.cpp:96
SX1278::implicitHeader
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission. Required for spreading factor 6.
Definition: SX1278.cpp:515
SX1278::setFrequency
int16_t setFrequency(float freq)
Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz.
Definition: SX1278.cpp:85
SX1278::setOutputPower
int16_t setOutputPower(int8_t power) override
Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA...
Definition: SX1278.cpp:292
SX1278::reset
void reset() override
Reset method. Will reset the chip to the default state using RST pin.
Definition: SX1278.cpp:76
SX1278::forceLDRO
int16_t forceLDRO(bool enable)
Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,...
Definition: SX1278.cpp:492
SX1278::explicitHeader
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition: SX1278.cpp:519
SX1278::checkDataRate
int16_t checkDataRate(DataRate_t dr) override
Check the data rate can be configured by this module.
Definition: SX1278.cpp:269
SX1278::setCodingRate
int16_t setCodingRate(uint8_t cr)
Sets LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in LoRa mode...
Definition: SX1278.cpp:202
SX1278::beginFSK
int16_t beginFSK(float freq=434.0, float br=4.8, float freqDev=5.0, float rxBw=125.0, int8_t power=10, uint16_t preambleLength=16, bool enableOOK=false)
FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the m...
Definition: SX1278.cpp:41
SX1278::begin
int16_t begin(float freq=434.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)
LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the ...
Definition: SX1278.cpp:9
SX1278::setGain
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: SX1278.cpp:345
SX1278::setCRC
int16_t setCRC(bool enable, bool mode=false)
Enables/disables CRC check of received packets.
Definition: SX1278.cpp:463
SX1278::autoLDRO
int16_t autoLDRO()
Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,...
Definition: SX1278.cpp:506
SX1278::setSpreadingFactor
int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa link spreading factor. Allowed values range from 6 to 12. Only available in LoRa mode.
Definition: SX1278.cpp:148
SX1278::setDataShaping
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: SX1278.cpp:382
SX1278::setBitRate
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: SX1278.cpp:236
SX127x
Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from thi...
Definition: SX127x.h:583
DataRate_t
Common data rate structure.
Definition: PhysicalLayer.h:38