15 #include <RHSPIDriver.h>
19 #define RH_LORA_NUM_INTERRUPTS 3
22 #define RH_LORA_FIFO_SIZE 255
26 #define RH_LORA_MAX_PAYLOAD_LEN RH_LORA_FIFO_SIZE
30 #define RH_LORA_HEADER_LEN 4
35 #ifndef RH_LORA_MAX_MESSAGE_LEN
36 #define RH_LORA_MAX_MESSAGE_LEN (RH_LORA_MAX_PAYLOAD_LEN - RH_LORA_HEADER_LEN)
40 #define RH_LORA_FXOSC 32000000.0
43 #define RH_LORA_FSTEP (RH_LORA_FXOSC / 524288)
47 #define RH_LORA_REG_00_FIFO 0x00
48 #define RH_LORA_REG_01_OP_MODE 0x01
49 #define RH_LORA_REG_02_RESERVED 0x02
50 #define RH_LORA_REG_03_RESERVED 0x03
51 #define RH_LORA_REG_04_RESERVED 0x04
52 #define RH_LORA_REG_05_RESERVED 0x05
53 #define RH_LORA_REG_06_FRF_MSB 0x06
54 #define RH_LORA_REG_07_FRF_MID 0x07
55 #define RH_LORA_REG_08_FRF_LSB 0x08
56 #define RH_LORA_REG_09_PA_CONFIG 0x09
57 #define RH_LORA_REG_0A_PA_RAMP 0x0a
58 #define RH_LORA_REG_0B_OCP 0x0b
59 #define RH_LORA_REG_0C_LNA 0x0c
60 #define RH_LORA_REG_0D_FIFO_ADDR_PTR 0x0d
61 #define RH_LORA_REG_0E_FIFO_TX_BASE_ADDR 0x0e
62 #define RH_LORA_REG_0F_FIFO_RX_BASE_ADDR 0x0f
63 #define RH_LORA_REG_10_FIFO_RX_CURRENT_ADDR 0x10
64 #define RH_LORA_REG_11_IRQ_FLAGS_MASK 0x11
65 #define RH_LORA_REG_12_IRQ_FLAGS 0x12
66 #define RH_LORA_REG_13_RX_NB_BYTES 0x13
67 #define RH_LORA_REG_14_RX_HEADER_CNT_VALUE_MSB 0x14
68 #define RH_LORA_REG_15_RX_HEADER_CNT_VALUE_LSB 0x15
69 #define RH_LORA_REG_16_RX_PACKET_CNT_VALUE_MSB 0x16
70 #define RH_LORA_REG_17_RX_PACKET_CNT_VALUE_LSB 0x17
71 #define RH_LORA_REG_18_MODEM_STAT 0x18
72 #define RH_LORA_REG_19_PKT_SNR_VALUE 0x19
73 #define RH_LORA_REG_1A_PKT_RSSI_VALUE 0x1a
74 #define RH_LORA_REG_1B_RSSI_VALUE 0x1b
75 #define RH_LORA_REG_1C_HOP_CHANNEL 0x1c
76 #define RH_LORA_REG_1D_MODEM_CONFIG1 0x1d
77 #define RH_LORA_REG_1E_MODEM_CONFIG2 0x1e
78 #define RH_LORA_REG_1F_SYMB_TIMEOUT_LSB 0x1f
79 #define RH_LORA_REG_20_PREAMBLE_MSB 0x20
80 #define RH_LORA_REG_21_PREAMBLE_LSB 0x21
81 #define RH_LORA_REG_22_PAYLOAD_LENGTH 0x22
82 #define RH_LORA_REG_23_MAX_PAYLOAD_LENGTH 0x23
83 #define RH_LORA_REG_24_HOP_PERIOD 0x24
84 #define RH_LORA_REG_25_FIFO_RX_BYTE_ADDR 0x25
85 #define RH_LORA_REG_26_MODEM_CONFIG3 0x26
87 #define RH_LORA_REG_40_DIO_MAPPING1 0x40
88 #define RH_LORA_REG_41_DIO_MAPPING2 0x41
89 #define RH_LORA_REG_42_VERSION 0x42
92 #define RH_LORA_LONG_RANGE_MODE 0x80
93 #define RH_LORA_ACCESS_SHARED_REG 0x40
94 #define RH_LORA_MODE 0x07
95 #define RH_LORA_MODE_SLEEP 0x00
96 #define RH_LORA_MODE_STDBY 0x01
97 #define RH_LORA_MODE_FSTX 0x02
98 #define RH_LORA_MODE_TX 0x03
99 #define RH_LORA_MODE_FSRX 0x04
100 #define RH_LORA_MODE_RXCONTINUOUS 0x05
101 #define RH_LORA_MODE_RXSINGLE 0x06
102 #define RH_LORA_MODE_CAD 0x07
105 #define RH_LORA_PA_SELECT 0x80
106 #define RH_LORA_OUTPUT_POWER 0x0f
109 #define RH_LORA_LOW_PN_TX_PLL_OFF 0x10
110 #define RH_LORA_PA_RAMP 0x0f
111 #define RH_LORA_PA_RAMP_3_4MS 0x00
112 #define RH_LORA_PA_RAMP_2MS 0x01
113 #define RH_LORA_PA_RAMP_1MS 0x02
114 #define RH_LORA_PA_RAMP_500US 0x03
115 #define RH_LORA_PA_RAMP_250US 0x0
116 #define RH_LORA_PA_RAMP_125US 0x05
117 #define RH_LORA_PA_RAMP_100US 0x06
118 #define RH_LORA_PA_RAMP_62US 0x07
119 #define RH_LORA_PA_RAMP_50US 0x08
120 #define RH_LORA_PA_RAMP_40US 0x09
121 #define RH_LORA_PA_RAMP_31US 0x0a
122 #define RH_LORA_PA_RAMP_25US 0x0b
123 #define RH_LORA_PA_RAMP_20US 0x0c
124 #define RH_LORA_PA_RAMP_15US 0x0d
125 #define RH_LORA_PA_RAMP_12US 0x0e
126 #define RH_LORA_PA_RAMP_10US 0x0f
129 #define RH_LORA_OCP_ON 0x20
130 #define RH_LORA_OCP_TRIM 0x1f
133 #define RH_LORA_LNA_GAIN 0xe0
134 #define RH_LORA_LNA_BOOST 0x03
135 #define RH_LORA_LNA_BOOST_DEFAULT 0x00
136 #define RH_LORA_LNA_BOOST_150PC 0x11
139 #define RH_LORA_RX_TIMEOUT_MASK 0x80
140 #define RH_LORA_RX_DONE_MASK 0x40
141 #define RH_LORA_PAYLOAD_CRC_ERROR_MASK 0x20
142 #define RH_LORA_VALID_HEADER_MASK 0x10
143 #define RH_LORA_TX_DONE_MASK 0x08
144 #define RH_LORA_CAD_DONE_MASK 0x04
145 #define RH_LORA_FHSS_CHANGE_CHANNEL_MASK 0x02
146 #define RH_LORA_CAD_DETECTED_MASK 0x01
149 #define RH_LORA_RX_TIMEOUT 0x80
150 #define RH_LORA_RX_DONE 0x40
151 #define RH_LORA_PAYLOAD_CRC_ERROR 0x20
152 #define RH_LORA_VALID_HEADER 0x10
153 #define RH_LORA_TX_DONE 0x08
154 #define RH_LORA_CAD_DONE 0x04
155 #define RH_LORA_FHSS_CHANGE_CHANNEL 0x02
156 #define RH_LORA_CAD_DETECTED 0x01
159 #define RH_LORA_RX_CODING_RATE 0xe0
160 #define RH_LORA_MODEM_STATUS_CLEAR 0x10
161 #define RH_LORA_MODEM_STATUS_HEADER_INFO_VALID 0x08
162 #define RH_LORA_MODEM_STATUS_RX_ONGOING 0x04
163 #define RH_LORA_MODEM_STATUS_SIGNAL_SYNCHRONIZED 0x02
164 #define RH_LORA_MODEM_STATUS_SIGNAL_DETECTED 0x01
167 #define RH_LORA_PLL_TIMEOUT 0x80
168 #define RH_LORA_RX_PAYLOAD_CRC_ON 0x40
169 #define RH_LORA_FHSS_PRESENT_CHANNEL 0x3f
172 #define RH_LORA_BW 0xc0
173 #define RH_LORA_BW_125KHZ 0x00
174 #define RH_LORA_BW_250KHZ 0x40
175 #define RH_LORA_BW_500KHZ 0x80
176 #define RH_LORA_BW_RESERVED 0xc0
177 #define RH_LORA_CODING_RATE 0x38
178 #define RH_LORA_CODING_RATE_4_5 0x00
179 #define RH_LORA_CODING_RATE_4_6 0x08
180 #define RH_LORA_CODING_RATE_4_7 0x10
181 #define RH_LORA_CODING_RATE_4_8 0x18
182 #define RH_LORA_IMPLICIT_HEADER_MODE_ON 0x04
183 #define RH_LORA_RX_PAYLOAD_CRC_ON 0x02
184 #define RH_LORA_LOW_DATA_RATE_OPTIMIZE 0x01
187 #define RH_LORA_SPREADING_FACTOR 0xf0
188 #define RH_LORA_SPREADING_FACTOR_64CPS 0x60
189 #define RH_LORA_SPREADING_FACTOR_128CPS 0x70
190 #define RH_LORA_SPREADING_FACTOR_256CPS 0x80
191 #define RH_LORA_SPREADING_FACTOR_512CPS 0x90
192 #define RH_LORA_SPREADING_FACTOR_1024CPS 0xa0
193 #define RH_LORA_SPREADING_FACTOR_2048CPS 0xb0
194 #define RH_LORA_SPREADING_FACTOR_4096CPS 0xc0
195 #define RH_LORA_TX_CONTINUOUS_MOE 0x08
196 #define RH_LORA_AGC_AUTO_ON 0x04
197 #define RH_LORA_SYM_TIMEOUT_MSB 0x03
414 RH_LORA(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2,
RHGenericSPI& spi = hardware_spi);
455 virtual bool recv(uint8_t* buf, uint8_t* len);
463 virtual bool send(
const uint8_t* data, uint8_t len);
527 static RH_LORA* _deviceForInterrupt[];
530 static uint8_t _interruptCount;
533 uint8_t _interruptPin;
536 volatile uint8_t _bufLen;
539 uint8_t _buf[RH_LORA_MAX_PAYLOAD_LEN];
542 volatile bool _rxBufValid;
Defines register values for a set of modem configuration registers.
Definition: RH_LORA.h:376
virtual uint8_t maxMessageLength()
Definition: RH_LORA.cpp:245
Bw = 500 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on.
Definition: RH_LORA.h:394
Base class for SPI interfaces.
Definition: RHGenericSPI.h:30
virtual bool available()
Definition: RH_LORA.cpp:176
virtual bool send(const uint8_t *data, uint8_t len)
Definition: RH_LORA.cpp:207
void setModeRx()
Definition: RH_LORA.cpp:270
bool printRegisters()
Definition: RH_LORA.cpp:231
void setModemRegisters(const ModemConfig *config)
Definition: RH_LORA.cpp:306
Driver to send and receive unaddressed, unreliable datagrams via a LoRa capable radio transceiver...
Definition: RH_LORA.h:366
void setModeTx()
Definition: RH_LORA.cpp:280
void validateRxBuf()
Examine the revceive buffer to determine whether the message is for this node.
Definition: RH_LORA.cpp:158
RH_LORA(uint8_t slaveSelectPin=SS, uint8_t interruptPin=2, RHGenericSPI &spi=hardware_spi)
Definition: RH_LORA.cpp:23
Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on.
Definition: RH_LORA.h:393
bool setFrequency(float centre)
Definition: RH_LORA.cpp:250
void setModeIdle()
Definition: RH_LORA.cpp:261
bool setModemConfig(ModemConfigChoice index)
Definition: RH_LORA.cpp:315
virtual bool init()
Definition: RH_LORA.cpp:31
virtual bool recv(uint8_t *buf, uint8_t *len)
Definition: RH_LORA.cpp:190
ModemConfigChoice
Definition: RH_LORA.h:391
void setTxPower(int8_t power)
Definition: RH_LORA.cpp:290
uint8_t reg_26
Value for register RH_LORA_REG_26_MODEM_CONFIG3.
Definition: RH_LORA.h:380
uint8_t reg_1d
Value for register RH_LORA_REG_1D_MODEM_CONFIG1.
Definition: RH_LORA.h:378
uint8_t reg_1e
Value for register RH_LORA_REG_1E_MODEM_CONFIG2.
Definition: RH_LORA.h:379
void handleInterrupt()
Definition: RH_LORA.cpp:102
void clearRxBuf()
Clear our local receive buffer.
Definition: RH_LORA.cpp:182
Base class for a RadioHead drivers that use the SPI bus to communicate with its transport hardware...
Definition: RHSPIDriver.h:38
void setPreambleLength(uint16_t bytes)
Definition: RH_LORA.cpp:327