RadioLib
Universal wireless communication library for Arduino
RF69.h
1 #if !defined(_RADIOLIB_RF69_H)
2 #define _RADIOLIB_RF69_H
3 
4 #include "../../TypeDef.h"
5 
6 #if !defined(RADIOLIB_EXCLUDE_RF69)
7 
8 #include "../../Module.h"
9 
10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h"
11 
12 // RF69 physical layer properties
13 #define RF69_FREQUENCY_STEP_SIZE 61.03515625
14 #define RF69_MAX_PACKET_LENGTH 64
15 #define RF69_CRYSTAL_FREQ 32.0
16 #define RF69_DIV_EXPONENT 19
17 
18 // RF69 register map
19 #define RF69_REG_FIFO 0x00
20 #define RF69_REG_OP_MODE 0x01
21 #define RF69_REG_DATA_MODUL 0x02
22 #define RF69_REG_BITRATE_MSB 0x03
23 #define RF69_REG_BITRATE_LSB 0x04
24 #define RF69_REG_FDEV_MSB 0x05
25 #define RF69_REG_FDEV_LSB 0x06
26 #define RF69_REG_FRF_MSB 0x07
27 #define RF69_REG_FRF_MID 0x08
28 #define RF69_REG_FRF_LSB 0x09
29 #define RF69_REG_OSC_1 0x0A
30 #define RF69_REG_AFC_CTRL 0x0B
31 #define RF69_REG_LISTEN_1 0x0D
32 #define RF69_REG_LISTEN_2 0x0E
33 #define RF69_REG_LISTEN_3 0x0F
34 #define RF69_REG_VERSION 0x10
35 #define RF69_REG_PA_LEVEL 0x11
36 #define RF69_REG_PA_RAMP 0x12
37 #define RF69_REG_OCP 0x13
38 #define RF69_REG_LNA 0x18
39 #define RF69_REG_RX_BW 0x19
40 #define RF69_REG_AFC_BW 0x1A
41 #define RF69_REG_OOK_PEAK 0x1B
42 #define RF69_REG_OOK_AVG 0x1C
43 #define RF69_REG_OOK_FIX 0x1D
44 #define RF69_REG_AFC_FEI 0x1E
45 #define RF69_REG_AFC_MSB 0x1F
46 #define RF69_REG_AFC_LSB 0x20
47 #define RF69_REG_FEI_MSB 0x21
48 #define RF69_REG_FEI_LSB 0x22
49 #define RF69_REG_RSSI_CONFIG 0x23
50 #define RF69_REG_RSSI_VALUE 0x24
51 #define RF69_REG_DIO_MAPPING_1 0x25
52 #define RF69_REG_DIO_MAPPING_2 0x26
53 #define RF69_REG_IRQ_FLAGS_1 0x27
54 #define RF69_REG_IRQ_FLAGS_2 0x28
55 #define RF69_REG_RSSI_THRESH 0x29
56 #define RF69_REG_RX_TIMEOUT_1 0x2A
57 #define RF69_REG_RX_TIMEOUT_2 0x2B
58 #define RF69_REG_PREAMBLE_MSB 0x2C
59 #define RF69_REG_PREAMBLE_LSB 0x2D
60 #define RF69_REG_SYNC_CONFIG 0x2E
61 #define RF69_REG_SYNC_VALUE_1 0x2F
62 #define RF69_REG_SYNC_VALUE_2 0x30
63 #define RF69_REG_SYNC_VALUE_3 0x31
64 #define RF69_REG_SYNC_VALUE_4 0x32
65 #define RF69_REG_SYNC_VALUE_5 0x33
66 #define RF69_REG_SYNC_VALUE_6 0x34
67 #define RF69_REG_SYNC_VALUE_7 0x35
68 #define RF69_REG_SYNC_VALUE_8 0x36
69 #define RF69_REG_PACKET_CONFIG_1 0x37
70 #define RF69_REG_PAYLOAD_LENGTH 0x38
71 #define RF69_REG_NODE_ADRS 0x39
72 #define RF69_REG_BROADCAST_ADRS 0x3A
73 #define RF69_REG_AUTO_MODES 0x3B
74 #define RF69_REG_FIFO_THRESH 0x3C
75 #define RF69_REG_PACKET_CONFIG_2 0x3D
76 #define RF69_REG_AES_KEY_1 0x3E
77 #define RF69_REG_AES_KEY_2 0x3F
78 #define RF69_REG_AES_KEY_3 0x40
79 #define RF69_REG_AES_KEY_4 0x41
80 #define RF69_REG_AES_KEY_5 0x42
81 #define RF69_REG_AES_KEY_6 0x43
82 #define RF69_REG_AES_KEY_7 0x44
83 #define RF69_REG_AES_KEY_8 0x45
84 #define RF69_REG_AES_KEY_9 0x46
85 #define RF69_REG_AES_KEY_10 0x47
86 #define RF69_REG_AES_KEY_11 0x48
87 #define RF69_REG_AES_KEY_12 0x49
88 #define RF69_REG_AES_KEY_13 0x4A
89 #define RF69_REG_AES_KEY_14 0x4B
90 #define RF69_REG_AES_KEY_15 0x4C
91 #define RF69_REG_AES_KEY_16 0x4D
92 #define RF69_REG_TEMP_1 0x4E
93 #define RF69_REG_TEMP_2 0x4F
94 #define RF69_REG_TEST_LNA 0x58
95 #define RF69_REG_TEST_PA1 0x5A
96 #define RF69_REG_TEST_PA2 0x5C
97 #define RF69_REG_TEST_DAGC 0x6F
98 
99 // RF69 modem settings
100 // RF69_REG_OP_MODE MSB LSB DESCRIPTION
101 #define RF69_SEQUENCER_OFF 0b00000000 // 7 7 disable automatic sequencer
102 #define RF69_SEQUENCER_ON 0b10000000 // 7 7 enable automatic sequencer
103 #define RF69_LISTEN_OFF 0b00000000 // 6 6 disable Listen mode
104 #define RF69_LISTEN_ON 0b01000000 // 6 6 enable Listen mode
105 #define RF69_LISTEN_ABORT 0b00100000 // 5 5 abort Listen mode (has to be set together with RF69_LISTEN_OFF)
106 #define RF69_SLEEP 0b00000000 // 4 2 sleep
107 #define RF69_STANDBY 0b00000100 // 4 2 standby
108 #define RF69_FS 0b00001000 // 4 2 frequency synthesis
109 #define RF69_TX 0b00001100 // 4 2 transmit
110 #define RF69_RX 0b00010000 // 4 2 receive
111 
112 // RF69_REG_DATA_MODUL
113 #define RF69_PACKET_MODE 0b00000000 // 6 5 packet mode (default)
114 #define RF69_CONTINUOUS_MODE_WITH_SYNC 0b01000000 // 6 5 continuous mode with bit synchronizer
115 #define RF69_CONTINUOUS_MODE 0b01100000 // 6 5 continuous mode without bit synchronizer
116 #define RF69_FSK 0b00000000 // 4 3 modulation: FSK (default)
117 #define RF69_OOK 0b00001000 // 4 3 OOK
118 #define RF69_NO_SHAPING 0b00000000 // 1 0 modulation shaping: no shaping (default)
119 #define RF69_FSK_GAUSSIAN_1_0 0b00000001 // 1 0 FSK modulation Gaussian filter, BT = 1.0
120 #define RF69_FSK_GAUSSIAN_0_5 0b00000010 // 1 0 FSK modulation Gaussian filter, BT = 0.5
121 #define RF69_FSK_GAUSSIAN_0_3 0b00000011 // 1 0 FSK modulation Gaussian filter, BT = 0.3
122 #define RF69_OOK_FILTER_BR 0b00000001 // 1 0 OOK modulation filter, f_cutoff = BR
123 #define RF69_OOK_FILTER_2BR 0b00000010 // 1 0 OOK modulation filter, f_cutoff = 2*BR
124 
125 // RF69_REG_BITRATE_MSB + REG_BITRATE_LSB
126 #define RF69_BITRATE_MSB 0x1A // 7 0 bit rate setting: rate = F(XOSC) / BITRATE
127 #define RF69_BITRATE_LSB 0x0B // 7 0 default value: 4.8 kbps 0x40 // 7 0
128 
129 // RF69_REG_FDEV_MSB + REG_FDEV_LSB
130 #define RF69_FDEV_MSB 0x00 // 5 0 frequency deviation: f_dev = f_step * FDEV
131 #define RF69_FDEV_LSB 0x52 // 7 0 default value: 5 kHz
132 
133 // RF69_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
134 #define RF69_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
135 #define RF69_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
136 #define RF69_FRF_LSB 0x00 // 7 0 default value: 915 MHz
137 
138 // RF69_REG_OSC_1
139 #define RF69_RC_CAL_START 0b10000000 // 7 7 force RC oscillator calibration
140 #define RF69_RC_CAL_RUNNING 0b00000000 // 6 6 RC oscillator calibration is still running
141 #define RF69_RC_CAL_DONE 0b00000000 // 5 5 RC oscillator calibration has finished
142 
143 // RF69_REG_AFC_CTRL
144 #define RF69_AFC_LOW_BETA_OFF 0b00000000 // 5 5 standard AFC routine
145 #define RF69_AFC_LOW_BETA_ON 0b00100000 // 5 5 improved AFC routine for signals with modulation index less than 2
146 
147 // RF69_REG_LISTEN_1
148 #define RF69_LISTEN_RES_IDLE_64_US 0b01000000 // 7 6 resolution of Listen mode idle time: 64 us
149 #define RF69_LISTEN_RES_IDLE_4_1_MS 0b10000000 // 7 6 4.1 ms (default)
150 #define RF69_LISTEN_RES_IDLE_262_MS 0b11000000 // 7 6 262 ms
151 #define RF69_LISTEN_RES_RX_64_US 0b00010000 // 5 4 resolution of Listen mode rx time: 64 us (default)
152 #define RF69_LISTEN_RES_RX_4_1_MS 0b00100000 // 5 4 4.1 ms
153 #define RF69_LISTEN_RES_RX_262_MS 0b00110000 // 5 4 262 ms
154 #define RF69_LISTEN_ACCEPT_ABOVE_RSSI_THRESH 0b00000000 // 3 3 packet acceptance criteria: RSSI above threshold
155 #define RF69_LISTEN_ACCEPT_MATCH_SYNC_ADDRESS 0b00001000 // 3 3 RSSI above threshold AND sync address matched
156 #define RF69_LISTEN_END_KEEP_RX 0b00000000 // 2 1 action after packet acceptance: stay in Rx mode
157 #define RF69_LISTEN_END_KEEP_RX_TIMEOUT 0b00000010 // 2 1 stay in Rx mode until timeout (default)
158 #define RF69_LISTEN_END_KEEP_RX_TIMEOUT_RESUME 0b00000100 // 2 1 stay in Rx mode until timeout, Listen mode will resume
159 
160 // RF69_REG_LISTEN_2
161 #define RF69_LISTEN_COEF_IDLE 0xF5 // 7 0 duration of idle phase in Listen mode
162 
163 // RF69_REG_LISTEN_3
164 #define RF69_LISTEN_COEF_RX 0x20 // 7 0 duration of Rx phase in Listen mode
165 
166 // RF69_REG_VERSION
167 #define RF69_CHIP_VERSION 0x24 // 7 0
168 
169 // RF69_REG_PA_LEVEL
170 #define RF69_PA0_OFF 0b00000000 // 7 7 PA0 disabled
171 #define RF69_PA0_ON 0b10000000 // 7 7 PA0 enabled (default)
172 #define RF69_PA1_OFF 0b00000000 // 6 6 PA1 disabled (default)
173 #define RF69_PA1_ON 0b01000000 // 6 6 PA1 enabled
174 #define RF69_PA2_OFF 0b00000000 // 5 5 PA2 disabled (default)
175 #define RF69_PA2_ON 0b00100000 // 5 5 PA2 enabled
176 #define RF69_OUTPUT_POWER 0b00011111 // 4 0 output power: P_out = -18 + OUTPUT_POWER
177 
178 // RF69_REG_PA_RAMP
179 #define RF69_PA_RAMP_3_4_MS 0b00000000 // 3 0 PA ramp rise/fall time: 3.4 ms
180 #define RF69_PA_RAMP_2_MS 0b00000001 // 3 0 2 ms
181 #define RF69_PA_RAMP_1_MS 0b00000010 // 3 0 1 ms
182 #define RF69_PA_RAMP_500_US 0b00000011 // 3 0 500 us
183 #define RF69_PA_RAMP_250_US 0b00000100 // 3 0 250 us
184 #define RF69_PA_RAMP_125_US 0b00000101 // 3 0 125 us
185 #define RF69_PA_RAMP_100_US 0b00000110 // 3 0 100 us
186 #define RF69_PA_RAMP_62_US 0b00000111 // 3 0 62 us
187 #define RF69_PA_RAMP_50_US 0b00001000 // 3 0 50 us
188 #define RF69_PA_RAMP_40_US 0b00001001 // 3 0 40 us (default)
189 #define RF69_PA_RAMP_31_US 0b00001010 // 3 0 31 us
190 #define RF69_PA_RAMP_25_US 0b00001011 // 3 0 25 us
191 #define RF69_PA_RAMP_20_US 0b00001100 // 3 0 20 us
192 #define RF69_PA_RAMP_15_US 0b00001101 // 3 0 15 us
193 #define RF69_PA_RAMP_12_US 0b00001110 // 3 0 12 us
194 #define RF69_PA_RAMP_10_US 0b00001111 // 3 0 10 us
195 
196 // RF69_REG_OCP
197 #define RF69_OCP_OFF 0b00000000 // 4 4 PA overload current protection disabled
198 #define RF69_OCP_ON 0b00010000 // 4 4 PA overload current protection enabled
199 #define RF69_OCP_TRIM 0b00001010 // 3 0 OCP current: I_max(OCP_TRIM = 0b1010) = 95 mA
200 
201 // RF69_REG_LNA
202 #define RF69_LNA_Z_IN_50_OHM 0b00000000 // 7 7 LNA input impedance: 50 ohm
203 #define RF69_LNA_Z_IN_200_OHM 0b10000000 // 7 7 200 ohm
204 #define RF69_LNA_CURRENT_GAIN 0b00001000 // 5 3 manually set LNA current gain
205 #define RF69_LNA_GAIN_AUTO 0b00000000 // 2 0 LNA gain setting: set automatically by AGC
206 #define RF69_LNA_GAIN_MAX 0b00000001 // 2 0 max gain
207 #define RF69_LNA_GAIN_MAX_6_DB 0b00000010 // 2 0 max gain - 6 dB
208 #define RF69_LNA_GAIN_MAX_12_DB 0b00000011 // 2 0 max gain - 12 dB
209 #define RF69_LNA_GAIN_MAX_24_DB 0b00000100 // 2 0 max gain - 24 dB
210 #define RF69_LNA_GAIN_MAX_36_DB 0b00000101 // 2 0 max gain - 36 dB
211 #define RF69_LNA_GAIN_MAX_48_DB 0b00000110 // 2 0 max gain - 48 dB
212 
213 // RF69_REG_RX_BW
214 #define RF69_DCC_FREQ 0b01000000 // 7 5 DC offset canceller cutoff frequency (4% Rx BW by default)
215 #define RF69_RX_BW_MANT_16 0b00000000 // 4 3 Channel filter bandwidth FSK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 2))
216 #define RF69_RX_BW_MANT_20 0b00001000 // 4 3 OOK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 3))
217 #define RF69_RX_BW_MANT_24 0b00010000 // 4 3
218 #define RF69_RX_BW_EXP 0b00000101 // 2 0 default RxBwExp value = 5
219 
220 // RF69_REG_AFC_BW
221 #define RF69_DCC_FREQ_AFC 0b10000000 // 7 5 default DccFreq parameter for AFC
222 #define RF69_DCC_RX_BW_MANT_AFC 0b00001000 // 4 3 default RxBwMant parameter for AFC
223 #define RF69_DCC_RX_BW_EXP_AFC 0b00000011 // 2 0 default RxBwExp parameter for AFC
224 
225 // RF69_REG_OOK_PEAK
226 #define RF69_OOK_THRESH_FIXED 0b00000000 // 7 6 OOK threshold type: fixed
227 #define RF69_OOK_THRESH_PEAK 0b01000000 // 7 6 peak (default)
228 #define RF69_OOK_THRESH_AVERAGE 0b10000000 // 7 6 average
229 #define RF69_OOK_PEAK_THRESH_STEP_0_5_DB 0b00000000 // 5 3 OOK demodulator step size: 0.5 dB (default)
230 #define RF69_OOK_PEAK_THRESH_STEP_1_0_DB 0b00001000 // 5 3 1.0 dB
231 #define RF69_OOK_PEAK_THRESH_STEP_1_5_DB 0b00010000 // 5 3 1.5 dB
232 #define RF69_OOK_PEAK_THRESH_STEP_2_0_DB 0b00011000 // 5 3 2.0 dB
233 #define RF69_OOK_PEAK_THRESH_STEP_3_0_DB 0b00100000 // 5 3 3.0 dB
234 #define RF69_OOK_PEAK_THRESH_STEP_4_0_DB 0b00101000 // 5 3 4.0 dB
235 #define RF69_OOK_PEAK_THRESH_STEP_5_0_DB 0b00110000 // 5 3 5.0 dB
236 #define RF69_OOK_PEAK_THRESH_STEP_6_0_DB 0b00111000 // 5 3 6.0 dB
237 #define RF69_OOK_PEAK_THRESH_DEC_1_1_CHIP 0b00000000 // 2 0 OOK demodulator step period: once per chip (default)
238 #define RF69_OOK_PEAK_THRESH_DEC_1_2_CHIP 0b00000001 // 2 0 once every 2 chips
239 #define RF69_OOK_PEAK_THRESH_DEC_1_4_CHIP 0b00000010 // 2 0 once every 4 chips
240 #define RF69_OOK_PEAK_THRESH_DEC_1_8_CHIP 0b00000011 // 2 0 once every 8 chips
241 #define RF69_OOK_PEAK_THRESH_DEC_2_1_CHIP 0b00000100 // 2 0 2 times per chip
242 #define RF69_OOK_PEAK_THRESH_DEC_4_1_CHIP 0b00000101 // 2 0 4 times per chip
243 #define RF69_OOK_PEAK_THRESH_DEC_8_1_CHIP 0b00000110 // 2 0 8 times per chip
244 #define RF69_OOK_PEAK_THRESH_DEC_16_1_CHIP 0b00000111 // 2 0 16 times per chip
245 
246 // RF69_REG_OOK_AVG
247 #define RF69_OOK_AVG_THRESH_FILT_32_PI 0b00000000 // 7 6 OOK average filter coefficient: chip rate / 32*pi
248 #define RF69_OOK_AVG_THRESH_FILT_8_PI 0b01000000 // 7 6 chip rate / 8*pi
249 #define RF69_OOK_AVG_THRESH_FILT_4_PI 0b10000000 // 7 6 chip rate / 4*pi (default)
250 #define RF69_OOK_AVG_THRESH_FILT_2_PI 0b11000000 // 7 6 chip rate / 2*pi
251 
252 // RF69_REG_OOK_FIX
253 #define RF69_OOK_FIXED_THRESH 0b00000110 // 7 0 default OOK fixed threshold (6 dB)
254 
255 // RF69_REG_AFC_FEI
256 #define RF69_FEI_RUNNING 0b00000000 // 6 6 FEI status: on-going
257 #define RF69_FEI_DONE 0b01000000 // 6 6 done
258 #define RF69_FEI_START 0b00100000 // 5 5 force new FEI measurement
259 #define RF69_AFC_RUNNING 0b00000000 // 4 4 AFC status: on-going
260 #define RF69_AFC_DONE 0b00010000 // 4 4 done
261 #define RF69_AFC_AUTOCLEAR_OFF 0b00000000 // 3 3 AFC register autoclear disabled
262 #define RF69_AFC_AUTOCLEAR_ON 0b00001000 // 3 3 AFC register autoclear enabled
263 #define RF69_AFC_AUTO_OFF 0b00000000 // 2 2 perform AFC only manually
264 #define RF69_AFC_AUTO_ON 0b00000100 // 2 2 perform AFC each time Rx mode is started
265 #define RF69_AFC_CLEAR 0b00000010 // 1 1 clear AFC register
266 #define RF69_AFC_START 0b00000001 // 0 0 start AFC
267 
268 // RF69_REG_RSSI_CONFIG
269 #define RF69_RSSI_RUNNING 0b00000000 // 1 1 RSSI status: on-going
270 #define RF69_RSSI_DONE 0b00000010 // 1 1 done
271 #define RF69_RSSI_START 0b00000001 // 0 0 start RSSI measurement
272 
273 // RF69_REG_DIO_MAPPING_1
274 #define RF69_DIO0_CONT_MODE_READY 0b11000000 // 7 6
275 #define RF69_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
276 #define RF69_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
277 #define RF69_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
278 #define RF69_DIO0_CONT_RSSI 0b10000000 // 7 6
279 #define RF69_DIO0_CONT_TX_READY 0b01000000 // 7 6
280 #define RF69_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
281 #define RF69_DIO0_PACK_CRC_OK 0b00000000 // 7 6
282 #define RF69_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
283 #define RF69_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
284 #define RF69_DIO0_PACK_RSSI 0b11000000 // 7 6
285 #define RF69_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
286 #define RF69_DIO0_PACK_TX_READY 0b01000000 // 7 6
287 #define RF69_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
288 #define RF69_DIO1_CONT_DCLK 0b00000000 // 5 4
289 #define RF69_DIO1_CONT_RX_READY 0b00010000 // 5 4
290 #define RF69_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
291 #define RF69_DIO1_CONT_TX_READY 0b00010000 // 5 4
292 #define RF69_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
293 #define RF69_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
294 #define RF69_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
295 #define RF69_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
296 #define RF69_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
297 #define RF69_DIO2_CONT_DATA 0b00000000 // 3 2
298 
299 // RF69_REG_DIO_MAPPING_2
300 #define RF69_CLK_OUT_FXOSC 0b00000000 // 2 0 ClkOut frequency: F(XOSC)
301 #define RF69_CLK_OUT_FXOSC_2 0b00000001 // 2 0 F(XOSC) / 2
302 #define RF69_CLK_OUT_FXOSC_4 0b00000010 // 2 0 F(XOSC) / 4
303 #define RF69_CLK_OUT_FXOSC_8 0b00000011 // 2 0 F(XOSC) / 8
304 #define RF69_CLK_OUT_FXOSC_16 0b00000100 // 2 0 F(XOSC) / 16
305 #define RF69_CLK_OUT_FXOSC_32 0b00000101 // 2 0 F(XOSC) / 31
306 #define RF69_CLK_OUT_RC 0b00000110 // 2 0 RC
307 #define RF69_CLK_OUT_OFF 0b00000111 // 2 0 disabled (default)
308 
309 // RF69_REG_IRQ_FLAGS_1
310 #define RF69_IRQ_MODE_READY 0b10000000 // 7 7 requested mode was set
311 #define RF69_IRQ_RX_READY 0b01000000 // 6 6 Rx mode ready
312 #define RF69_IRQ_TX_READY 0b00100000 // 5 5 Tx mode ready
313 #define RF69_IRQ_PLL_LOCK 0b00010000 // 4 4 PLL is locked
314 #define RF69_IRQ_RSSI 0b00001000 // 3 3 RSSI value exceeded RssiThreshold
315 #define RF69_IRQ_TIMEOUT 0b00000100 // 2 2 timeout occurred
316 #define RF69_IRQ_AUTO_MODE 0b00000010 // 1 1 entered intermediate mode
317 #define RF69_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address detected
318 
319 // RF69_REG_IRQ_FLAGS_2
320 #define RF69_IRQ_FIFO_FULL 0b10000000 // 7 7 FIFO is full
321 #define RF69_IRQ_FIFO_NOT_EMPTY 0b01000000 // 6 6 FIFO contains at least 1 byte
322 #define RF69_IRQ_FIFO_LEVEL 0b00100000 // 5 5 FIFO contains more than FifoThreshold bytes
323 #define RF69_IRQ_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred
324 #define RF69_IRQ_PACKET_SENT 0b00001000 // 3 3 packet was sent
325 #define RF69_IRQ_PAYLOAD_READY 0b00000100 // 2 2 last payload byte received and CRC check passed
326 #define RF69_IRQ_CRC_OK 0b00000010 // 1 1 CRC check passed
327 
328 // RF69_REG_RSSI_THRESH
329 #define RF69_RSSI_THRESHOLD 0xE4 // 7 0 RSSI threshold level (2 dB by default)
330 
331 // RF69_REG_RX_TIMEOUT_1
332 #define RF69_TIMEOUT_RX_START_OFF 0x00 // 7 0 RSSI interrupt timeout disabled (default)
333 #define RF69_TIMEOUT_RX_START 0xFF // 7 0 timeout will occur if RSSI interrupt is not received
334 
335 // RF69_REG_RX_TIMEOUT_2
336 #define RF69_TIMEOUT_RSSI_THRESH_OFF 0x00 // 7 0 PayloadReady interrupt timeout disabled (default)
337 #define RF69_TIMEOUT_RSSI_THRESH 0xFF // 7 0 timeout will occur if PayloadReady interrupt is not received
338 
339 // RF69_REG_PREAMBLE_MSB + REG_PREAMBLE_MSB
340 #define RF69_PREAMBLE_MSB 0x00 // 7 0 2-byte preamble size value
341 #define RF69_PREAMBLE_LSB 0x03 // 7 0
342 
343 // RF69_REG_SYNC_CONFIG
344 #define RF69_SYNC_OFF 0b00000000 // 7 7 sync word detection off
345 #define RF69_SYNC_ON 0b10000000 // 7 7 sync word detection on (default)
346 #define RF69_FIFO_FILL_CONDITION_SYNC 0b00000000 // 6 6 FIFO fill condition: on SyncAddress interrupt (default)
347 #define RF69_FIFO_FILL_CONDITION 0b01000000 // 6 6 as long as the bit is set
348 #define RF69_SYNC_SIZE 0b00001000 // 5 3 size of sync word: SyncSize + 1 bytes
349 #define RF69_SYNC_TOL 0b00000000 // 2 0 number of tolerated errors in sync word
350 
351 // RF69_REG_SYNC_VALUE_1 - SYNC_VALUE_8
352 #define RF69_SYNC_BYTE_1 0x01 // 7 0 sync word: 1st byte (MSB)
353 #define RF69_SYNC_BYTE_2 0x01 // 7 0 2nd byte
354 #define RF69_SYNC_BYTE_3 0x01 // 7 0 3rd byte
355 #define RF69_SYNC_BYTE_4 0x01 // 7 0 4th byte
356 #define RF69_SYNC_BYTE_5 0x01 // 7 0 5th byte
357 #define RF69_SYNC_BYTE_6 0x01 // 7 0 6th byte
358 #define RF69_SYNC_BYTE_7 0x01 // 7 0 7th byte
359 #define RF69_SYNC_BYTE_8 0x01 // 7 0 8th byte (LSB)
360 
361 // RF69_REG_PACKET_CONFIG_1
362 #define RF69_PACKET_FORMAT_FIXED 0b00000000 // 7 7 fixed packet length (default)
363 #define RF69_PACKET_FORMAT_VARIABLE 0b10000000 // 7 7 variable packet length
364 #define RF69_DC_FREE_NONE 0b00000000 // 6 5 DC-free encoding: none (default)
365 #define RF69_DC_FREE_MANCHESTER 0b00100000 // 6 5 Manchester
366 #define RF69_DC_FREE_WHITENING 0b01000000 // 6 5 Whitening
367 #define RF69_CRC_OFF 0b00000000 // 4 4 CRC disabled
368 #define RF69_CRC_ON 0b00010000 // 4 4 CRC enabled (default)
369 #define RF69_CRC_AUTOCLEAR_ON 0b00000000 // 3 3 discard packet when CRC check fails (default)
370 #define RF69_CRC_AUTOCLEAR_OFF 0b00001000 // 3 3 keep packet when CRC check fails
371 #define RF69_ADDRESS_FILTERING_OFF 0b00000000 // 2 1 address filtering: none (default)
372 #define RF69_ADDRESS_FILTERING_NODE 0b00000010 // 2 1 node
373 #define RF69_ADDRESS_FILTERING_NODE_BROADCAST 0b00000100 // 2 1 node or broadcast
374 
375 // RF69_REG_PAYLOAD_LENGTH
376 #define RF69_PAYLOAD_LENGTH 0xFF // 7 0 payload length
377 
378 // RF69_REG_AUTO_MODES
379 #define RF69_ENTER_COND_NONE 0b00000000 // 7 5 condition for entering intermediate mode: none, AutoModes disabled (default)
380 #define RF69_ENTER_COND_FIFO_NOT_EMPTY 0b00100000 // 7 5 FifoNotEmpty rising edge
381 #define RF69_ENTER_COND_FIFO_LEVEL 0b01000000 // 7 5 FifoLevel rising edge
382 #define RF69_ENTER_COND_CRC_OK 0b01100000 // 7 5 CrcOk rising edge
383 #define RF69_ENTER_COND_PAYLOAD_READY 0b10000000 // 7 5 PayloadReady rising edge
384 #define RF69_ENTER_COND_SYNC_ADDRESS 0b10100000 // 7 5 SyncAddress rising edge
385 #define RF69_ENTER_COND_PACKET_SENT 0b11000000 // 7 5 PacketSent rising edge
386 #define RF69_ENTER_COND_FIFO_EMPTY 0b11100000 // 7 5 FifoNotEmpty falling edge
387 #define RF69_EXIT_COND_NONE 0b00000000 // 4 2 condition for exiting intermediate mode: none, AutoModes disabled (default)
388 #define RF69_EXIT_COND_FIFO_EMPTY 0b00100000 // 4 2 FifoNotEmpty falling edge
389 #define RF69_EXIT_COND_FIFO_LEVEL 0b01000000 // 4 2 FifoLevel rising edge
390 #define RF69_EXIT_COND_CRC_OK 0b01100000 // 4 2 CrcOk rising edge
391 #define RF69_EXIT_COND_PAYLOAD_READY 0b10000000 // 4 2 PayloadReady rising edge
392 #define RF69_EXIT_COND_SYNC_ADDRESS 0b10100000 // 4 2 SyncAddress rising edge
393 #define RF69_EXIT_COND_PACKET_SENT 0b11000000 // 4 2 PacketSent rising edge
394 #define RF69_EXIT_COND_TIMEOUT 0b11100000 // 4 2 timeout rising edge
395 #define RF69_INTER_MODE_SLEEP 0b00000000 // 1 0 intermediate mode: sleep (default)
396 #define RF69_INTER_MODE_STANDBY 0b00000001 // 1 0 standby
397 #define RF69_INTER_MODE_RX 0b00000010 // 1 0 Rx
398 #define RF69_INTER_MODE_TX 0b00000011 // 1 0 Tx
399 
400 // RF69_REG_FIFO_THRESH
401 #define RF69_TX_START_CONDITION_FIFO_LEVEL 0b00000000 // 7 7 packet transmission start condition: FifoLevel
402 #define RF69_TX_START_CONDITION_FIFO_NOT_EMPTY 0b10000000 // 7 7 FifoNotEmpty (default)
403 #define RF69_FIFO_THRESHOLD 0b00001111 // 6 0 default threshold to trigger FifoLevel interrupt
404 
405 // RF69_REG_PACKET_CONFIG_2
406 #define RF69_INTER_PACKET_RX_DELAY 0b00000000 // 7 4 delay between FIFO empty and start of new RSSI phase
407 #define RF69_RESTART_RX 0b00000100 // 2 2 force receiver into wait mode
408 #define RF69_AUTO_RX_RESTART_OFF 0b00000000 // 1 1 auto Rx restart disabled
409 #define RF69_AUTO_RX_RESTART_ON 0b00000010 // 1 1 auto Rx restart enabled (default)
410 #define RF69_AES_OFF 0b00000000 // 0 0 AES encryption disabled (default)
411 #define RF69_AES_ON 0b00000001 // 0 0 AES encryption enabled, payload size limited to 66 bytes
412 
413 // RF69_REG_TEST_LNA
414 #define RF69_TEST_LNA_BOOST_NORMAL 0x1B // 7 0
415 #define RF69_TEST_LNA_BOOST_HIGH 0x2D // 7 0
416 
417 // RF69_REG_TEMP_1
418 #define RF69_TEMP_MEAS_START 0b00001000 // 3 3 trigger temperature measurement
419 #define RF69_TEMP_MEAS_RUNNING 0b00000100 // 2 2 temperature measurement status: on-going
420 #define RF69_TEMP_MEAS_DONE 0b00000000 // 2 2 done
421 
422 // RF69_REG_TEST_DAGC
423 #define RF69_CONTINUOUS_DAGC_NORMAL 0x00 // 7 0 fading margin improvement: normal mode
424 #define RF69_CONTINUOUS_DAGC_LOW_BETA_ON 0x20 // 7 0 improved mode for AfcLowBetaOn
425 #define RF69_CONTINUOUS_DAGC_LOW_BETA_OFF 0x30 // 7 0 improved mode for AfcLowBetaOff (default)
426 
427 // RF69_REG_TEST_PA1
428 #define RF69_PA1_NORMAL 0x55 // 7 0 PA_BOOST: none
429 #define RF69_PA1_20_DBM 0x5D // 7 0 +20 dBm
430 
431 // RF69_REG_TEST_PA2
432 #define RF69_PA2_NORMAL 0x70 // 7 0 PA_BOOST: none
433 #define RF69_PA2_20_DBM 0x7C // 7 0 +20 dBm
434 
440 class RF69: public PhysicalLayer {
441  public:
442  // introduce PhysicalLayer overloads
447 
453  RF69(Module* module);
454 
455  // basic methods
456 
474  int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
475 
479  void reset();
480 
493  int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
494 
505  int16_t receive(uint8_t* data, size_t len) override;
506 
512  int16_t sleep();
513 
519  int16_t standby() override;
520 
528  int16_t transmitDirect(uint32_t frf = 0) override;
529 
535  int16_t receiveDirect() override;
536 
540  int16_t packetMode();
541 
542  // hardware AES support
543 
549  void setAESKey(uint8_t* key);
550 
556  int16_t enableAES();
557 
563  int16_t disableAES();
564 
565  // interrupt methods
566 
572  void setDio0Action(void (*func)(void));
573 
577  void clearDio0Action();
578 
584  void setDio1Action(void (*func)(void));
585 
589  void clearDio1Action();
590 
603  int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
604 
610  int16_t startReceive();
611 
621  int16_t readData(uint8_t* data, size_t len) override;
622 
623  // configuration methods
624 
632  int16_t setFrequency(float freq);
633 
641  int16_t setBitRate(float br);
642 
650  int16_t setRxBandwidth(float rxBw);
651 
659  int16_t setFrequencyDeviation(float freqDev) override;
660 
670  int16_t setOutputPower(int8_t power, bool highPower = false);
671 
681  int16_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0);
682 
690  int16_t setPreambleLength(uint8_t preambleLen);
691 
699  int16_t setNodeAddress(uint8_t nodeAddr);
700 
708  int16_t setBroadcastAddress(uint8_t broadAddr);
709 
715  int16_t disableAddressFiltering();
716 
717  // measurement methods
718 
724  void setAmbientTemperature(int16_t tempAmbient);
725 
731  int16_t getTemperature();
732 
740  size_t getPacketLength(bool update = true) override;
741 
749  int16_t setOOK(bool enableOOK);
750 
758  int16_t setOokThresholdType(uint8_t type);
759 
767  int16_t fixedPacketLengthMode(uint8_t len = RF69_MAX_PACKET_LENGTH);
768 
776  int16_t variablePacketLengthMode(uint8_t maxLen = RF69_MAX_PACKET_LENGTH);
777 
785  int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0);
786 
792  int16_t disableSyncWordFiltering();
793 
801  int16_t setCrcFiltering(bool crcOn = true);
802 
810  int16_t setPromiscuousMode(bool promiscuous = true);
811 
820  int16_t setDataShaping(uint8_t sh) override;
821 
830  int16_t setEncoding(uint8_t encoding) override;
831 
839  int16_t setLnaTestBoost(bool value);
840 
846  float getRSSI();
847 
856  void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
857 
863  uint8_t random();
864 
870  int16_t getChipVersion();
871 
877  void setDirectAction(void (*func)(void));
878 
884  void readBit(RADIOLIB_PIN_TYPE pin);
885 
886 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
887  protected:
888 #endif
889  Module* _mod;
890 
891 #if !defined(RADIOLIB_GODMODE)
892  protected:
893 #endif
894 
895  float _freq = 0;
896  float _br = 0;
897  float _rxBw = 0;
898  bool _ook = false;
899  int16_t _tempOffset = 0;
900  int8_t _power = 0;
901 
902  size_t _packetLength = 0;
903  bool _packetLengthQueried = false;
904  uint8_t _packetLengthConfig = RF69_PACKET_FORMAT_VARIABLE;
905 
906  bool _promiscuous = false;
907 
908  uint8_t _syncWordLength = 2;
909 
910  int16_t config();
911  int16_t directMode();
912  int16_t setPacketMode(uint8_t mode, uint8_t len);
913 
914 #if !defined(RADIOLIB_GODMODE)
915  private:
916 #endif
917  int16_t setMode(uint8_t mode);
918  void clearIRQFlags();
919 };
920 
921 #endif
922 
923 #endif
RF69::setCrcFiltering
int16_t setCrcFiltering(bool crcOn=true)
Enable CRC filtering and generation.
Definition: RF69.cpp:715
RF69::setDio0Action
void setDio0Action(void(*func)(void))
Sets interrupt service routine to call when DIO0 activates.
Definition: RF69.cpp:269
RF69::clearDio1Action
void clearDio1Action()
Clears interrupt service routine to call when DIO1 activates.
Definition: RF69.cpp:285
PhysicalLayer::transmit
int16_t transmit(__FlashStringHelper *fstr, uint8_t addr=0)
Arduino Flash String transmit method.
Definition: PhysicalLayer.cpp:10
RF69::setBroadcastAddress
int16_t setBroadcastAddress(uint8_t broadAddr)
Sets broadcast address. Calling this method will also enable address filtering for node and broadcast...
Definition: RF69.cpp:634
RF69::receiveDirect
int16_t receiveDirect() override
Starts direct mode reception.
Definition: RF69.cpp:200
RF69::setRfSwitchPins
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn)
Some modules contain external RF switch controlled by two pins. This function gives RadioLib control ...
Definition: RF69.cpp:799
RF69::readData
int16_t readData(uint8_t *data, size_t len) override
Reads data received after calling startReceive method.
Definition: RF69.cpp:340
RF69::setPromiscuousMode
int16_t setPromiscuousMode(bool promiscuous=true)
Set modem in "sniff" mode: no packet filtering (e.g., no preamble, sync word, address,...
Definition: RF69.cpp:723
RF69::receive
int16_t receive(uint8_t *data, size_t len) override
Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalL...
Definition: RF69.cpp:139
RF69::clearDio0Action
void clearDio0Action()
Clears interrupt service routine to call when DIO0 activates.
Definition: RF69.cpp:273
RF69::getPacketLength
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition: RF69.cpp:677
RF69
Control class for RF69 module. Also serves as base class for SX1231.
Definition: RF69.h:440
RF69::setDio1Action
void setDio1Action(void(*func)(void))
Sets interrupt service routine to call when DIO1 activates.
Definition: RF69.cpp:277
RF69::startReceive
int16_t startReceive()
Interrupt-driven receive method. GDO0 will be activated when full packet is received.
Definition: RF69.cpp:241
RF69::setFrequency
int16_t setFrequency(float freq)
Sets carrier frequency. Allowed values are in bands 290.0 to 340.0 MHz, 431.0 to 510....
Definition: RF69.cpp:391
RF69::fixedPacketLengthMode
int16_t fixedPacketLengthMode(uint8_t len=RF69_MAX_PACKET_LENGTH)
Set modem in fixed packet length mode.
Definition: RF69.cpp:690
RF69::setNodeAddress
int16_t setNodeAddress(uint8_t nodeAddr)
Sets node address. Calling this method will also enable address filtering for node address only.
Definition: RF69.cpp:625
RF69::enableAES
int16_t enableAES()
Enables AES encryption.
Definition: RF69.cpp:233
RF69::setPreambleLength
int16_t setPreambleLength(uint8_t preambleLen)
Sets preamble length.
Definition: RF69.cpp:614
RF69::reset
void reset()
Reset method. Will reset the chip to the default state using RST pin.
Definition: RF69.cpp:102
RF69::transmit
int16_t transmit(uint8_t *data, size_t len, uint8_t addr=0) override
Blocking binary transmit method. Overloads for string-based transmissions are implemented in Physical...
Definition: RF69.cpp:110
RF69::setRxBandwidth
int16_t setRxBandwidth(float rxBw)
Sets receiver bandwidth. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12....
Definition: RF69.cpp:434
PhysicalLayer::readData
int16_t readData(String &str, size_t len=0)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:59
RF69::setBitRate
int16_t setBitRate(float br)
Sets bit rate. Allowed values range from 1.2 to 300.0 kbps.
Definition: RF69.cpp:413
RF69::disableAES
int16_t disableAES()
Disables AES encryption.
Definition: RF69.cpp:237
RF69::RF69
RF69(Module *module)
Default constructor.
Definition: RF69.cpp:4
RF69::setDataShaping
int16_t setDataShaping(uint8_t sh) override
Sets Gaussian filter bandwidth-time product that will be used for data shaping. Allowed values are RA...
Definition: RF69.cpp:749
RF69::setOOK
int16_t setOOK(bool enableOOK)
Enables/disables OOK modulation instead of FSK.
Definition: RF69.cpp:369
RF69::standby
int16_t standby() override
Sets the module to standby mode.
Definition: RF69.cpp:171
RF69::setLnaTestBoost
int16_t setLnaTestBoost(bool value)
Enable/disable LNA Boost mode (disabled by default).
Definition: RF69.cpp:787
RF69::getTemperature
int16_t getTemperature()
Measures temperature.
Definition: RF69.cpp:660
RF69::setFrequencyDeviation
int16_t setFrequencyDeviation(float freqDev) override
Sets frequency deviation.
Definition: RF69.cpp:529
RF69::disableAddressFiltering
int16_t disableAddressFiltering()
Disables address filtering. Calling this method will also erase previously set addresses.
Definition: RF69.cpp:643
RF69::setSyncWord
int16_t setSyncWord(uint8_t *syncWord, size_t len, uint8_t maxErrBits=0)
Sets sync word. Up to 8 bytes can be set as sync word.
Definition: RF69.cpp:591
RF69::readBit
void readBit(RADIOLIB_PIN_TYPE pin)
Function to read and process data bit in direct reception mode.
Definition: RF69.cpp:826
RF69::disableSyncWordFiltering
int16_t disableSyncWordFiltering()
Disable preamble and sync word filtering and generation.
Definition: RF69.cpp:703
RF69::getRSSI
float getRSSI()
Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
Definition: RF69.cpp:795
PhysicalLayer
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN....
Definition: PhysicalLayer.h:14
PhysicalLayer::receive
int16_t receive(String &str, size_t len=0)
Arduino String receive method.
Definition: PhysicalLayer.cpp:100
RF69::setEncoding
int16_t setEncoding(uint8_t encoding) override
Sets transmission encoding. Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER an...
Definition: RF69.cpp:769
RF69::setAESKey
void setAESKey(uint8_t *key)
Sets AES key.
Definition: RF69.cpp:229
RF69::setDirectAction
void setDirectAction(void(*func)(void))
Set interrupt service routine function to call when data bit is receveid in direct mode.
Definition: RF69.cpp:822
Module
Implements all common low-level SPI/UART/I2C methods to control the wireless module....
Definition: Module.h:17
RF69::transmitDirect
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition: RF69.cpp:179
RF69::setOutputPower
int16_t setOutputPower(int8_t power, bool highPower=false)
Sets output power. Allowed values range from -18 to 13 dBm for low power modules (RF69C/CW) or -2 to ...
Definition: RF69.cpp:553
RF69::packetMode
int16_t packetMode()
Stops direct mode. It is required to call this method to switch from direct transmissions to packet-b...
Definition: RF69.cpp:225
RF69::setAmbientTemperature
void setAmbientTemperature(int16_t tempAmbient)
Sets ambient temperature. Required to correct values from on-board temperature sensor.
Definition: RF69.cpp:656
RF69::setOokThresholdType
int16_t setOokThresholdType(uint8_t type)
Selects the type of threshold in the OOK data slicer.
Definition: RF69.cpp:384
RF69::sleep
int16_t sleep()
Sets the module to sleep mode.
Definition: RF69.cpp:163
RF69::getChipVersion
int16_t getChipVersion()
Read version SPI register. Should return RF69_CHIP_VERSION (0x24) if SX127x is connected and working.
Definition: RF69.cpp:830
RF69::enableSyncWordFiltering
int16_t enableSyncWordFiltering(uint8_t maxErrBits=0)
Enable sync word filtering and generation.
Definition: RF69.cpp:698
RF69::variablePacketLengthMode
int16_t variablePacketLengthMode(uint8_t maxLen=RF69_MAX_PACKET_LENGTH)
Set modem in variable packet length mode.
Definition: RF69.cpp:694
RF69::startTransmit
int16_t startTransmit(uint8_t *data, size_t len, uint8_t addr=0) override
Interrupt-driven binary transmit method. Overloads for string-based transmissions are implemented in ...
Definition: RF69.cpp:292
RF69::random
uint8_t random()
Get one truly random byte from RSSI noise.
Definition: RF69.cpp:803
RF69::begin
int16_t begin(float freq=434.0, float br=48.0, float freqDev=50.0, float rxBw=125.0, int8_t power=10, uint8_t preambleLen=16)
Initialization method.
Definition: RF69.cpp:8
PhysicalLayer::startTransmit
int16_t startTransmit(String &str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method,...
Definition: PhysicalLayer.cpp:51