5 SX127x_OPMODE_FSK_OOK
= 0b00000000,
6 SX127x_OPMODE_LORA
= 0b10000000,
7 SX127X_ACCESS_SHARED_REG_OFF
= 0b00000000,
8 SX127X_ACCESS_SHARED_REG_ON
= 0b01000000
9 } SX127x_ModulationModes
;
13 SX127x_OPMODE_SLEEP
= 0b00000000,
14 SX127x_OPMODE_STANDBY
= 0b00000001,
15 SX127x_OPMODE_FSTX
= 0b00000010,
16 SX127x_OPMODE_TX
= 0b00000011,
17 SX127x_OPMODE_FSRX
= 0b00000100,
18 SX127x_OPMODE_RXCONTINUOUS
= 0b00000101,
19 SX127x_OPMODE_RXSINGLE
= 0b00000110,
20 SX127x_OPMODE_CAD
= 0b00000111,
21 } SX127x_RadioOPmodes
;
23 #if defined(RADIO_SX1272)
26 SX127x_BW_125_00_KHZ
= 0b00000000,
27 SX127x_BW_250_00_KHZ
= 0b01000000,
28 SX127x_BW_500_00_KHZ
= 0b10000000
33 SX127x_BW_125_00_KHZ
= 0b01110000,
34 SX127x_BW_250_00_KHZ
= 0b10000000,
35 SX127x_BW_500_00_KHZ
= 0b10010000
41 SX127x_SF_6
= 0b01100000,
42 SX127x_SF_7
= 0b01110000,
43 SX127x_SF_8
= 0b10000000,
44 SX127x_SF_9
= 0b10010000,
45 SX127x_SF_10
= 0b10100000,
46 SX127x_SF_11
= 0b10110000,
47 SX127x_SF_12
= 0b11000000
48 } SX127x_SpreadingFactor
;
49 #define SX127X_SPREADING_FACTOR_MASK 0b11110000
51 #if defined(RADIO_SX1272)
54 SX127x_CR_4_5
= 0b00001000,
55 SX127x_CR_4_6
= 0b00010000,
56 SX127x_CR_4_7
= 0b00011000,
57 SX127x_CR_4_8
= 0b00100000,
62 SX127x_CR_4_5
= 0b00000010,
63 SX127x_CR_4_6
= 0b00000100,
64 SX127x_CR_4_7
= 0b00000110,
65 SX127x_CR_4_8
= 0b00001000,
69 // SX127x series common registers
70 #define SX127X_REG_FIFO 0x00
71 #define SX127X_REG_OP_MODE 0x01
72 #define SX127X_REG_FRF_MSB 0x06
73 #define SX127X_REG_FRF_MID 0x07
74 #define SX127X_REG_FRF_LSB 0x08
75 #define SX127X_REG_PA_CONFIG 0x09
76 #define SX127X_REG_PA_RAMP 0x0A
77 #define SX127X_REG_OCP 0x0B
78 #define SX127X_REG_LNA 0x0C
79 #define SX127X_REG_FIFO_ADDR_PTR 0x0D
80 #define SX127X_REG_FIFO_TX_BASE_ADDR 0x0E
81 #define SX127X_REG_FIFO_RX_BASE_ADDR 0x0F
82 #define SX127X_REG_FIFO_RX_CURRENT_ADDR 0x10
83 #define SX127X_REG_IRQ_FLAGS_MASK 0x11
84 #define SX127X_REG_IRQ_FLAGS 0x12
85 #define SX127X_REG_RX_NB_BYTES 0x13
86 #define SX127X_REG_RX_HEADER_CNT_VALUE_MSB 0x14
87 #define SX127X_REG_RX_HEADER_CNT_VALUE_LSB 0x15
88 #define SX127X_REG_RX_PACKET_CNT_VALUE_MSB 0x16
89 #define SX127X_REG_RX_PACKET_CNT_VALUE_LSB 0x17
90 #define SX127X_REG_MODEM_STAT 0x18
91 #define SX127X_REG_PKT_SNR_VALUE 0x19
92 #define SX127X_REG_PKT_RSSI_VALUE 0x1A
93 #define SX127X_REG_RSSI_VALUE 0x1B
94 #define SX127X_REG_HOP_CHANNEL 0x1C
95 #define SX127X_REG_MODEM_CONFIG_1 0x1D
96 #define SX127X_REG_MODEM_CONFIG_2 0x1E
97 #define SX127X_REG_SYMB_TIMEOUT_MSB 0x1E
98 #define SX127X_REG_SYMB_TIMEOUT_MSB_MASK 0b00000011
99 #define SX127X_REG_SYMB_TIMEOUT_LSB 0x1F
100 #define SX127X_REG_PREAMBLE_MSB 0x20
101 #define SX127X_REG_PREAMBLE_LSB 0x21
102 #define SX127X_REG_PAYLOAD_LENGTH 0x22
103 #define SX127X_REG_MAX_PAYLOAD_LENGTH 0x23
104 #define SX127X_REG_HOP_PERIOD 0x24
105 #define SX127X_REG_FIFO_RX_BYTE_ADDR 0x25
106 #define SX127X_REG_FEI_MSB 0x28
107 #define SX127X_REG_FEI_MID 0x29
108 #define SX127X_REG_FEI_LSB 0x2A
109 #define SX127X_REG_RSSI_WIDEBAND 0x2C
110 #define SX127X_REG_DETECT_OPTIMIZE 0x31
111 #define SX127X_REG_INVERT_IQ 0b01000001
112 #define SX127X_REG_INVERT_IQ_MASK 0b01000001
113 #define SX127X_REG_DETECTION_THRESHOLD 0x37
114 #define SX127X_REG_SYNC_WORD 0x39
115 #define SX127X_REG_DIO_MAPPING_1 0x40
116 #define SX127X_REG_DIO_MAPPING_2 0x41
117 #define SX127X_REG_VERSION 0x42
119 #if defined(RADIO_SX1272)
120 #define SX127X_VERSION 0x22
122 #define SX127X_VERSION 0x12
125 // SX127X_REG_PA_CONFIG
126 #define SX127X_PA_SELECT_RFO 0b00000000 // 7 7 RFO pin output, power limited to +14 dBm
127 #define SX127X_PA_SELECT_BOOST 0b10000000 // 7 7 PA_BOOST pin output, power limited to +20 dBm
128 #define SX127X_PA_POWER_MASK 0b01111111 // 6 0 PA MAX_POWER and OUTPUT_POWER combined bit mask
129 #define SX127X_MAX_OUTPUT_POWER_RFO_HF 0b00000000 // Max output power when using RFO_HF
130 #define SX127X_MAX_OUTPUT_POWER 0b01110000 // Enable max output power
132 #define SX127X_OCP_OFF 0b00000000 // 5 5 PA overload current protection disabled
133 #define SX127X_OCP_ON 0b00100000 // 5 5 PA overload current protection enabled
134 #define SX127X_OCP_TRIM 0b00001011 // 4 0 OCP current: I_max(OCP_TRIM = 0b1011) = 100 mA
135 #define SX127X_OCP_150MA 0b00010010 // 4 0 OCP current: I_max(OCP_TRIM = 10010) = 150 mA
136 #define SX127X_OCP_MASK 0b00111111
139 #define SX127X_LNA_GAIN_0 0b00000000 // 7 5 LNA gain setting: not used
140 #define SX127X_LNA_GAIN_1 0b00100000 // 7 5 max gain
141 #define SX127X_LNA_GAIN_2 0b01000000 // 7 5 .
142 #define SX127X_LNA_GAIN_3 0b01100000 // 7 5 .
143 #define SX127X_LNA_GAIN_4 0b10000000 // 7 5 .
144 #define SX127X_LNA_GAIN_5 0b10100000 // 7 5 .
145 #define SX127X_LNA_GAIN_6 0b11000000 // 7 5 min gain
146 #define SX127X_LNA_GAIN_7 0b11100000 // 7 5 not used
147 #define SX127X_LNA_BOOST_OFF 0b00000000 // 1 0 default LNA current
148 #define SX127X_LNA_BOOST_ON 0b00000011 // 1 0 150% LNA current
150 #define SX127X_TX_MODE_SINGLE 0b00000000 // 3 3 single TX
151 #define SX127X_TX_MODE_CONT 0b00001000 // 3 3 continuous TX
152 #define SX127X_TX_MODE_MASK 0b00001000 // 3 3
153 #define SX127X_RX_TIMEOUT_MSB 0b00000000 // 1 0
155 // SX127X_REG_SYMB_TIMEOUT_LSB
156 #define SX127X_RX_TIMEOUT_LSB 0b01100100 // 7 0 10 bit RX operation timeout
158 // SX127X_REG_PREAMBLE_MSB + REG_PREAMBLE_LSB
159 #define SX127X_PREAMBLE_LENGTH_MSB 0b00000000 // 7 0 2 byte preamble length setting: l_P = PREAMBLE_LENGTH + 4.25
160 #define SX127X_PREAMBLE_LENGTH_LSB 0b00001000 // 7 0 where l_p = preamble length
161 //#define SX127X_PREAMBLE_LENGTH_LSB 0b00000100 // 7 0 where l_p = preamble length //CHANGED
163 // SX127X_REG_DETECT_OPTIMIZE
164 #define SX127X_DETECT_OPTIMIZE_SF_6 0b00000101 // 2 0 SF6 detection optimization
165 #define SX127X_DETECT_OPTIMIZE_SF_7_12 0b00000011 // 2 0 SF7 to SF12 detection optimization
166 #define SX127X_DETECT_OPTIMIZE_SF_MASK 0b00000111 // 2 0
168 // SX127X_REG_DETECTION_THRESHOLD
169 #define SX127X_DETECTION_THRESHOLD_SF_6 0b00001100 // 7 0 SF6 detection threshold
170 #define SX127X_DETECTION_THRESHOLD_SF_7_12 0b00001010 // 7 0 SF7 to SF12 detection threshold
173 #define SX127X_PA_BOOST_OFF 0b00000100 // 2 0 PA_BOOST disabled
174 #define SX127X_PA_BOOST_ON 0b00000111 // 2 0 +20 dBm on PA_BOOST when OUTPUT_POWER = 0b1111
176 // SX127X_REG_HOP_PERIOD
177 #define SX127X_HOP_PERIOD_OFF 0b00000000 // 7 0 number of periods between frequency hops; 0 = disabled
178 #define SX127X_HOP_PERIOD_MAX 0b11111111 // 7 0
180 // SX127X_REG_DIO_MAPPING_1
181 #define SX127X_DIO0_RX_DONE 0b00000000 // 7 6
182 #define SX127X_DIO0_TX_DONE 0b01000000 // 7 6
183 #define SX127X_DIO0_RXTX_DONE 0b11000000 // 7 6
184 #define SX127X_DIO0_CAD_DONE 0b10000000 // 7 6
185 #define SX127X_DIO0_MASK 0b11000000 // 7 6
186 #define SX127X_DIO1_RX_TIMEOUT 0b00000000 // 5 4
187 #define SX127X_DIO1_FHSS_CHANGE_CHANNEL 0b00010000 // 5 4
188 #define SX127X_DIO1_CAD_DETECTED 0b00100000 // 5 4
190 // SX127X_REG_IRQ_FLAGS
191 #define SX127X_CLEAR_IRQ_FLAG_ALL 0b11111111
192 #define SX127X_CLEAR_IRQ_FLAG_RX_TIMEOUT 0b10000000 // 7 7 timeout
193 #define SX127X_CLEAR_IRQ_FLAG_RX_DONE 0b01000000 // 6 6 packet reception complete
194 #define SX127X_CLEAR_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b00100000 // 5 5 payload CRC error
195 #define SX127X_CLEAR_IRQ_FLAG_VALID_HEADER 0b00010000 // 4 4 valid header received
196 #define SX127X_CLEAR_IRQ_FLAG_TX_DONE 0b00001000 // 3 3 payload transmission complete
197 #define SX127X_CLEAR_IRQ_FLAG_CAD_DONE 0b00000100 // 2 2 CAD complete
198 #define SX127X_CLEAR_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b00000010 // 1 1 FHSS change channel
199 #define SX127X_CLEAR_IRQ_FLAG_CAD_DETECTED 0b00000001 // 0 0 valid LoRa signal detected during CAD operation
200 #define SX127X_CLEAR_IRQ_FLAG_NONE 0b00000000
202 // SX127X_REG_IRQ_FLAGS_MASK
203 #define SX127X_MASK_IRQ_FLAG_RX_TIMEOUT 0b01111111 // 7 7 timeout
204 #define SX127X_MASK_IRQ_FLAG_RX_DONE 0b10111111 // 6 6 packet reception complete
205 #define SX127X_MASK_IRQ_FLAG_PAYLOAD_CRC_ERROR 0b11011111 // 5 5 payload CRC error
206 #define SX127X_MASK_IRQ_FLAG_VALID_HEADER 0b11101111 // 4 4 valid header received
207 #define SX127X_MASK_IRQ_FLAG_TX_DONE 0b11110111 // 3 3 payload transmission complete
208 #define SX127X_MASK_IRQ_FLAG_CAD_DONE 0b11111011 // 2 2 CAD complete
209 #define SX127X_MASK_IRQ_FLAG_FHSS_CHANGE_CHANNEL 0b11111101 // 1 1 FHSS change channel
210 #define SX127X_MASK_IRQ_FLAG_CAD_DETECTED 0b11111110 // 0 0 valid LoRa signal detected during CAD operation
212 // SX127X_REG_FIFO_TX_BASE_ADDR
213 #define SX127X_FIFO_TX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for TX only
215 // SX127X_REG_FIFO_RX_BASE_ADDR
216 #define SX127X_FIFO_RX_BASE_ADDR_MAX 0b00000000 // 7 0 allocate the entire FIFO buffer for RX only
218 // SX127X_REG_SYNC_WORD
219 //#define SX127X_SYNC_WORD 0xC8 // 200 0 default ExpressLRS sync word - 200Hz
220 #define SX127X_SYNC_WORD 0x12 // 18 0 default LoRa sync word
221 #define SX127X_SYNC_WORD_LORAWAN 0x34 // 52 0 sync word reserved for LoRaWAN networks
226 #define SX127x_TXCONTINUOUSMODE_MASK 0xF7
227 #define SX127x_TXCONTINUOUSMODE_ON 0x08
228 #define SX127x_TXCONTINUOUSMODE_OFF 0x00
229 #define SX127x_PPMOFFSET 0x27
231 ///// SX1278 Regs /////
232 //SX1278 specific register map
233 #define SX1278_REG_MODEM_CONFIG_3 0x26
234 #define SX1278_REG_TCXO 0x4B
235 #define SX1278_REG_PA_DAC 0x4D
236 #define SX1278_REG_FORMER_TEMP 0x5D
237 #define SX1278_REG_AGC_REF 0x61
238 #define SX1278_REG_AGC_THRESH_1 0x62
239 #define SX1278_REG_AGC_THRESH_2 0x63
240 #define SX1278_REG_AGC_THRESH_3 0x64
241 #define SX1278_REG_PLL 0x70
243 //SX1278 LoRa modem settings
244 //SX1278_REG_OP_MODE MSB LSB DESCRIPTION
245 #define SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
246 #define SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
248 //SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
249 #define SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
250 #define SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
251 #define SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
253 //SX1278_REG_PA_CONFIG
254 #define SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
255 //#define SX1278_MAX_POWER 0b00010000 // 6 4 changed
258 #define SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
260 //SX127X_REG_MODEM_CONFIG_1
261 #if defined(RADIO_SX1272)
262 #define SX127x_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
263 #define SX127x_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
265 #define SX127x_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
266 #define SX127x_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
269 //SX1278_REG_MODEM_CONFIG_2
270 #define SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
271 #define SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
272 #define SX1278_RX_CRC_MODE_MASK 0b00000100
274 //SX1272_REG_MODEM_CONFIG_1
275 #define SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
276 #define SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
277 #define SX1272_RX_CRC_MODE_MASK 0b00000010
279 //SX1278_REG_MODEM_CONFIG_3
280 #define SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
281 #define SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
282 #define SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
283 #define SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
286 #define ERR_NONE 0x00
287 #define ERR_CHIP_NOT_FOUND 0x01
288 #define ERR_EEPROM_NOT_INITIALIZED 0x02
290 #define ERR_PACKET_TOO_LONG 0x10
291 #define ERR_TX_TIMEOUT 0x11
293 #define ERR_RX_TIMEOUT 0x20
294 #define ERR_CRC_MISMATCH 0x21
296 #define ERR_INVALID_BANDWIDTH 0x30
297 #define ERR_INVALID_SPREADING_FACTOR 0x31
298 #define ERR_INVALID_CODING_RATE 0x32
299 #define ERR_INVALID_FREQUENCY 0x33
301 #define ERR_INVALID_BIT_RANGE 0x40
303 #define CHANNEL_FREE 0x50
304 #define PREAMBLE_DETECTED 0x51
306 #define SPI_READ 0b00000000
307 #define SPI_WRITE 0b10000000