15#include <RHSPIDriver.h>
19#define RH_RF95_NUM_INTERRUPTS 3
22#define RH_RF95_FIFO_SIZE 255
26#define RH_RF95_MAX_PAYLOAD_LEN RH_RF95_FIFO_SIZE
30#define RH_RF95_HEADER_LEN 4
35#ifndef RH_RF95_MAX_MESSAGE_LEN
36 #define RH_RF95_MAX_MESSAGE_LEN (RH_RF95_MAX_PAYLOAD_LEN - RH_RF95_HEADER_LEN)
40#define RH_RF95_FXOSC 32000000.0
43#define RH_RF95_FSTEP (RH_RF95_FXOSC / 524288)
47#define RH_RF95_REG_00_FIFO 0x00
48#define RH_RF95_REG_01_OP_MODE 0x01
49#define RH_RF95_REG_02_RESERVED 0x02
50#define RH_RF95_REG_03_RESERVED 0x03
51#define RH_RF95_REG_04_RESERVED 0x04
52#define RH_RF95_REG_05_RESERVED 0x05
53#define RH_RF95_REG_06_FRF_MSB 0x06
54#define RH_RF95_REG_07_FRF_MID 0x07
55#define RH_RF95_REG_08_FRF_LSB 0x08
56#define RH_RF95_REG_09_PA_CONFIG 0x09
57#define RH_RF95_REG_0A_PA_RAMP 0x0a
58#define RH_RF95_REG_0B_OCP 0x0b
59#define RH_RF95_REG_0C_LNA 0x0c
60#define RH_RF95_REG_0D_FIFO_ADDR_PTR 0x0d
61#define RH_RF95_REG_0E_FIFO_TX_BASE_ADDR 0x0e
62#define RH_RF95_REG_0F_FIFO_RX_BASE_ADDR 0x0f
63#define RH_RF95_REG_10_FIFO_RX_CURRENT_ADDR 0x10
64#define RH_RF95_REG_11_IRQ_FLAGS_MASK 0x11
65#define RH_RF95_REG_12_IRQ_FLAGS 0x12
66#define RH_RF95_REG_13_RX_NB_BYTES 0x13
67#define RH_RF95_REG_14_RX_HEADER_CNT_VALUE_MSB 0x14
68#define RH_RF95_REG_15_RX_HEADER_CNT_VALUE_LSB 0x15
69#define RH_RF95_REG_16_RX_PACKET_CNT_VALUE_MSB 0x16
70#define RH_RF95_REG_17_RX_PACKET_CNT_VALUE_LSB 0x17
71#define RH_RF95_REG_18_MODEM_STAT 0x18
72#define RH_RF95_REG_19_PKT_SNR_VALUE 0x19
73#define RH_RF95_REG_1A_PKT_RSSI_VALUE 0x1a
74#define RH_RF95_REG_1B_RSSI_VALUE 0x1b
75#define RH_RF95_REG_1C_HOP_CHANNEL 0x1c
76#define RH_RF95_REG_1D_MODEM_CONFIG1 0x1d
77#define RH_RF95_REG_1E_MODEM_CONFIG2 0x1e
78#define RH_RF95_REG_1F_SYMB_TIMEOUT_LSB 0x1f
79#define RH_RF95_REG_20_PREAMBLE_MSB 0x20
80#define RH_RF95_REG_21_PREAMBLE_LSB 0x21
81#define RH_RF95_REG_22_PAYLOAD_LENGTH 0x22
82#define RH_RF95_REG_23_MAX_PAYLOAD_LENGTH 0x23
83#define RH_RF95_REG_24_HOP_PERIOD 0x24
84#define RH_RF95_REG_25_FIFO_RX_BYTE_ADDR 0x25
85#define RH_RF95_REG_26_MODEM_CONFIG3 0x26
87#define RH_RF95_REG_27_PPM_CORRECTION 0x27
88#define RH_RF95_REG_28_FEI_MSB 0x28
89#define RH_RF95_REG_29_FEI_MID 0x29
90#define RH_RF95_REG_2A_FEI_LSB 0x2a
91#define RH_RF95_REG_2C_RSSI_WIDEBAND 0x2c
92#define RH_RF95_REG_31_DETECT_OPTIMIZE 0x31
93#define RH_RF95_REG_33_INVERT_IQ 0x33
94#define RH_RF95_REG_37_DETECTION_THRESHOLD 0x37
95#define RH_RF95_REG_39_SYNC_WORD 0x39
97#define RH_RF95_REG_40_DIO_MAPPING1 0x40
98#define RH_RF95_REG_41_DIO_MAPPING2 0x41
99#define RH_RF95_REG_42_VERSION 0x42
101#define RH_RF95_REG_4B_TCXO 0x4b
102#define RH_RF95_REG_4D_PA_DAC 0x4d
103#define RH_RF95_REG_5B_FORMER_TEMP 0x5b
104#define RH_RF95_REG_61_AGC_REF 0x61
105#define RH_RF95_REG_62_AGC_THRESH1 0x62
106#define RH_RF95_REG_63_AGC_THRESH2 0x63
107#define RH_RF95_REG_64_AGC_THRESH3 0x64
110#define RH_RF95_LONG_RANGE_MODE 0x80
111#define RH_RF95_ACCESS_SHARED_REG 0x40
112#define RH_RF95_LOW_FREQUENCY_MODE 0x08
113#define RH_RF95_MODE 0x07
114#define RH_RF95_MODE_SLEEP 0x00
115#define RH_RF95_MODE_STDBY 0x01
116#define RH_RF95_MODE_FSTX 0x02
117#define RH_RF95_MODE_TX 0x03
118#define RH_RF95_MODE_FSRX 0x04
119#define RH_RF95_MODE_RXCONTINUOUS 0x05
120#define RH_RF95_MODE_RXSINGLE 0x06
121#define RH_RF95_MODE_CAD 0x07
124#define RH_RF95_PA_SELECT 0x80
125#define RH_RF95_MAX_POWER 0x70
126#define RH_RF95_OUTPUT_POWER 0x0f
129#define RH_RF95_LOW_PN_TX_PLL_OFF 0x10
130#define RH_RF95_PA_RAMP 0x0f
131#define RH_RF95_PA_RAMP_3_4MS 0x00
132#define RH_RF95_PA_RAMP_2MS 0x01
133#define RH_RF95_PA_RAMP_1MS 0x02
134#define RH_RF95_PA_RAMP_500US 0x03
135#define RH_RF95_PA_RAMP_250US 0x04
136#define RH_RF95_PA_RAMP_125US 0x05
137#define RH_RF95_PA_RAMP_100US 0x06
138#define RH_RF95_PA_RAMP_62US 0x07
139#define RH_RF95_PA_RAMP_50US 0x08
140#define RH_RF95_PA_RAMP_40US 0x09
141#define RH_RF95_PA_RAMP_31US 0x0a
142#define RH_RF95_PA_RAMP_25US 0x0b
143#define RH_RF95_PA_RAMP_20US 0x0c
144#define RH_RF95_PA_RAMP_15US 0x0d
145#define RH_RF95_PA_RAMP_12US 0x0e
146#define RH_RF95_PA_RAMP_10US 0x0f
149#define RH_RF95_OCP_ON 0x20
150#define RH_RF95_OCP_TRIM 0x1f
153#define RH_RF95_LNA_GAIN 0xe0
154#define RH_RF95_LNA_GAIN_G1 0x20
155#define RH_RF95_LNA_GAIN_G2 0x40
156#define RH_RF95_LNA_GAIN_G3 0x60
157#define RH_RF95_LNA_GAIN_G4 0x80
158#define RH_RF95_LNA_GAIN_G5 0xa0
159#define RH_RF95_LNA_GAIN_G6 0xc0
160#define RH_RF95_LNA_BOOST_LF 0x18
161#define RH_RF95_LNA_BOOST_LF_DEFAULT 0x00
162#define RH_RF95_LNA_BOOST_HF 0x03
163#define RH_RF95_LNA_BOOST_HF_DEFAULT 0x00
164#define RH_RF95_LNA_BOOST_HF_150PC 0x03
167#define RH_RF95_RX_TIMEOUT_MASK 0x80
168#define RH_RF95_RX_DONE_MASK 0x40
169#define RH_RF95_PAYLOAD_CRC_ERROR_MASK 0x20
170#define RH_RF95_VALID_HEADER_MASK 0x10
171#define RH_RF95_TX_DONE_MASK 0x08
172#define RH_RF95_CAD_DONE_MASK 0x04
173#define RH_RF95_FHSS_CHANGE_CHANNEL_MASK 0x02
174#define RH_RF95_CAD_DETECTED_MASK 0x01
177#define RH_RF95_RX_TIMEOUT 0x80
178#define RH_RF95_RX_DONE 0x40
179#define RH_RF95_PAYLOAD_CRC_ERROR 0x20
180#define RH_RF95_VALID_HEADER 0x10
181#define RH_RF95_TX_DONE 0x08
182#define RH_RF95_CAD_DONE 0x04
183#define RH_RF95_FHSS_CHANGE_CHANNEL 0x02
184#define RH_RF95_CAD_DETECTED 0x01
187#define RH_RF95_RX_CODING_RATE 0xe0
188#define RH_RF95_MODEM_STATUS_CLEAR 0x10
189#define RH_RF95_MODEM_STATUS_HEADER_INFO_VALID 0x08
190#define RH_RF95_MODEM_STATUS_RX_ONGOING 0x04
191#define RH_RF95_MODEM_STATUS_SIGNAL_SYNCHRONIZED 0x02
192#define RH_RF95_MODEM_STATUS_SIGNAL_DETECTED 0x01
195#define RH_RF95_PLL_TIMEOUT 0x80
196#define RH_RF95_RX_PAYLOAD_CRC_IS_ON 0x40
197#define RH_RF95_FHSS_PRESENT_CHANNEL 0x3f
200#define RH_RF95_BW 0xf0
202#define RH_RF95_BW_7_8KHZ 0x00
203#define RH_RF95_BW_10_4KHZ 0x10
204#define RH_RF95_BW_15_6KHZ 0x20
205#define RH_RF95_BW_20_8KHZ 0x30
206#define RH_RF95_BW_31_25KHZ 0x40
207#define RH_RF95_BW_41_7KHZ 0x50
208#define RH_RF95_BW_62_5KHZ 0x60
209#define RH_RF95_BW_125KHZ 0x70
210#define RH_RF95_BW_250KHZ 0x80
211#define RH_RF95_BW_500KHZ 0x90
212#define RH_RF95_CODING_RATE 0x0e
213#define RH_RF95_CODING_RATE_4_5 0x02
214#define RH_RF95_CODING_RATE_4_6 0x04
215#define RH_RF95_CODING_RATE_4_7 0x06
216#define RH_RF95_CODING_RATE_4_8 0x08
217#define RH_RF95_IMPLICIT_HEADER_MODE_ON 0x01
220#define RH_RF95_SPREADING_FACTOR 0xf0
221#define RH_RF95_SPREADING_FACTOR_64CPS 0x60
222#define RH_RF95_SPREADING_FACTOR_128CPS 0x70
223#define RH_RF95_SPREADING_FACTOR_256CPS 0x80
224#define RH_RF95_SPREADING_FACTOR_512CPS 0x90
225#define RH_RF95_SPREADING_FACTOR_1024CPS 0xa0
226#define RH_RF95_SPREADING_FACTOR_2048CPS 0xb0
227#define RH_RF95_SPREADING_FACTOR_4096CPS 0xc0
228#define RH_RF95_TX_CONTINUOUS_MODE 0x08
230#define RH_RF95_PAYLOAD_CRC_ON 0x04
231#define RH_RF95_SYM_TIMEOUT_MSB 0x03
234#define RH_RF95_MOBILE_NODE 0x08
235#define RH_RF95_LOW_DATA_RATE_OPTIMIZE 0x08
236#define RH_RF95_AGC_AUTO_ON 0x04
239#define RH_RF95_TCXO_TCXO_INPUT_ON 0x10
242#define RH_RF95_PA_DAC_DISABLE 0x04
243#define RH_RF95_PA_DAC_ENABLE 0x07
632 RH_RF95(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2,
RHGenericSPI& spi = hardware_spi);
676 virtual bool recv(uint8_t* buf, uint8_t* len);
688 virtual bool send(
const uint8_t* data, uint8_t len);
741 void setTxPower(int8_t power,
bool useRFO =
false);
748 virtual bool sleep();
889 static RH_RF95* _deviceForInterrupt[];
892 static uint8_t _interruptCount;
895 uint8_t _interruptPin;
899 uint8_t _myInterruptIndex;
902 volatile uint8_t _bufLen;
905 uint8_t _buf[RH_RF95_MAX_PAYLOAD_LEN];
908 volatile bool _rxBufValid;
920 uint8_t _deviceVersion = 0x00;
RHMode
Defines different operating modes for the transport hardware.
Definition RHGenericDriver.h:49
Base class for SPI interfaces.
Definition RHGenericSPI.h:31
Base class for RadioHead drivers that use the SPI bus to communicate with its transport hardware.
Definition RHSPIDriver.h:39
Driver to send and receive unaddressed, unreliable datagrams via a LoRa capable radio transceiver.
Definition RH_RF95.h:573
void setSignalBandwidth(long sbw)
Definition RH_RF95.cpp:620
void validateRxBuf()
Examine the revceive buffer to determine whether the message is for this node.
Definition RH_RF95.cpp:280
int lastSNR()
Definition RH_RF95.cpp:582
virtual bool modeWillChange(RHMode)
Definition RH_RF95.h:872
void handleInterrupt()
Definition RH_RF95.cpp:158
void clearRxBuf()
Clear our local receive buffer.
Definition RH_RF95.cpp:311
void setModeIdle()
Definition RH_RF95.cpp:401
void setModeTx()
Definition RH_RF95.cpp:433
bool setupInterruptHandler()
Do whatever is necesary to establish the interrupt handler. Subclasses may have different needs.
Definition RH_RF95.cpp:99
virtual bool isChannelActive()
Definition RH_RF95.cpp:516
bool setFrequency(float centre)
Definition RH_RF95.cpp:389
virtual bool recv(uint8_t *buf, uint8_t *len)
Definition RH_RF95.cpp:319
void enableTCXO(bool on=true)
Definition RH_RF95.cpp:533
void setLowDatarate()
Definition RH_RF95.cpp:668
virtual bool available()
Definition RH_RF95.cpp:298
int frequencyError()
Definition RH_RF95.cpp:555
void setPayloadCRC(bool on)
Definition RH_RF95.cpp:701
void setModemRegisters(const ModemConfig *config)
Definition RH_RF95.cpp:489
virtual bool init()
Definition RH_RF95.cpp:42
virtual bool sleep()
Definition RH_RF95.cpp:411
uint8_t getDeviceVersion()
Definition RH_RF95.cpp:713
void setTxPower(int8_t power, bool useRFO=false)
Definition RH_RF95.cpp:444
ModemConfigChoice
Definition RH_RF95.h:605
@ Bw500Cr45Sf128
Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Fast+short range.
Definition RH_RF95.h:607
@ Bw125Cr48Sf4096
Bw = 125 kHz, Cr = 4/8, Sf = 4096chips/symbol, low data rate, CRC on. Slow+long range.
Definition RH_RF95.h:609
@ Bw125Cr45Sf128
Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on. Default medium range.
Definition RH_RF95.h:606
@ Bw125Cr45Sf2048
Bw = 125 kHz, Cr = 4/5, Sf = 2048chips/symbol, CRC on. Slow+long range.
Definition RH_RF95.h:610
@ Bw31_25Cr48Sf512
Bw = 31.25 kHz, Cr = 4/8, Sf = 512chips/symbol, CRC on. Slow+long range.
Definition RH_RF95.h:608
void setSpreadingFactor(uint8_t sf)
Definition RH_RF95.cpp:597
bool _useRFO
Definition RH_RF95.h:876
void setCodingRate4(uint8_t denominator)
Definition RH_RF95.cpp:651
void setModeRx()
Definition RH_RF95.cpp:422
virtual bool send(const uint8_t *data, uint8_t len)
Definition RH_RF95.cpp:338
void setPreambleLength(uint16_t bytes)
Definition RH_RF95.cpp:510
bool setModemConfig(ModemConfigChoice index)
Definition RH_RF95.cpp:498
bool printRegisters()
Definition RH_RF95.cpp:368
virtual uint8_t maxMessageLength()
Definition RH_RF95.cpp:384
Defines register values for a set of modem configuration registers.
Definition RH_RF95.h:583
uint8_t reg_1d
Value for register RH_RF95_REG_1D_MODEM_CONFIG1.
Definition RH_RF95.h:584
uint8_t reg_1e
Value for register RH_RF95_REG_1E_MODEM_CONFIG2.
Definition RH_RF95.h:585
uint8_t reg_26
Value for register RH_RF95_REG_26_MODEM_CONFIG3.
Definition RH_RF95.h:586