1 #if !defined(_RADIOLIB_SX128X_H) 2 #define _RADIOLIB_SX128X_H 4 #include "../../TypeDef.h" 6 #if !defined(RADIOLIB_EXCLUDE_SX128X) 8 #include "../../Module.h" 10 #include "../../protocols/PhysicalLayer/PhysicalLayer.h" 13 #define SX128X_FREQUENCY_STEP_SIZE 198.3642578 14 #define SX128X_MAX_PACKET_LENGTH 255 15 #define SX128X_CRYSTAL_FREQ 52.0 16 #define SX128X_DIV_EXPONENT 18 19 #define SX128X_CMD_NOP 0x00 20 #define SX128X_CMD_GET_STATUS 0xC0 21 #define SX128X_CMD_WRITE_REGISTER 0x18 22 #define SX128X_CMD_READ_REGISTER 0x19 23 #define SX128X_CMD_WRITE_BUFFER 0x1A 24 #define SX128X_CMD_READ_BUFFER 0x1B 25 #define SX128X_CMD_SET_SLEEP 0x84 26 #define SX128X_CMD_SET_STANDBY 0x80 27 #define SX128X_CMD_SET_FS 0xC1 28 #define SX128X_CMD_SET_TX 0x83 29 #define SX128X_CMD_SET_RX 0x82 30 #define SX128X_CMD_SET_RX_DUTY_CYCLE 0x94 31 #define SX128X_CMD_SET_CAD 0xC5 32 #define SX128X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1 33 #define SX128X_CMD_SET_TX_CONTINUOUS_PREAMBLE 0xD2 34 #define SX128X_CMD_SET_PACKET_TYPE 0x8A 35 #define SX128X_CMD_GET_PACKET_TYPE 0x03 36 #define SX128X_CMD_SET_RF_FREQUENCY 0x86 37 #define SX128X_CMD_SET_TX_PARAMS 0x8E 38 #define SX128X_CMD_SET_CAD_PARAMS 0x88 39 #define SX128X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F 40 #define SX128X_CMD_SET_MODULATION_PARAMS 0x8B 41 #define SX128X_CMD_SET_PACKET_PARAMS 0x8C 42 #define SX128X_CMD_GET_RX_BUFFER_STATUS 0x17 43 #define SX128X_CMD_GET_PACKET_STATUS 0x1D 44 #define SX128X_CMD_GET_RSSI_INST 0x1F 45 #define SX128X_CMD_SET_DIO_IRQ_PARAMS 0x8D 46 #define SX128X_CMD_GET_IRQ_STATUS 0x15 47 #define SX128X_CMD_CLEAR_IRQ_STATUS 0x97 48 #define SX128X_CMD_SET_REGULATOR_MODE 0x96 49 #define SX128X_CMD_SET_SAVE_CONTEXT 0xD5 50 #define SX128X_CMD_SET_AUTO_TX 0x98 51 #define SX128X_CMD_SET_AUTO_FS 0x9E 52 #define SX128X_CMD_SET_PERF_COUNTER_MODE 0x9C 53 #define SX128X_CMD_SET_LONG_PREAMBLE 0x9B 54 #define SX128X_CMD_SET_UART_SPEED 0x9D 55 #define SX128X_CMD_SET_RANGING_ROLE 0xA3 56 #define SX128X_CMD_SET_ADVANCED_RANGING 0x9A 59 #define SX128X_REG_SYNC_WORD_1_BYTE_4 0x09CE 60 #define SX128X_REG_SYNC_WORD_1_BYTE_3 0x09CF 61 #define SX128X_REG_SYNC_WORD_1_BYTE_2 0x09D0 62 #define SX128X_REG_SYNC_WORD_1_BYTE_1 0x09D1 63 #define SX128X_REG_SYNC_WORD_1_BYTE_0 0x09D2 64 #define SX128X_REG_SYNC_WORD_2_BYTE_4 0x09D3 65 #define SX128X_REG_SYNC_WORD_2_BYTE_3 0x09D4 66 #define SX128X_REG_SYNC_WORD_2_BYTE_2 0x09D5 67 #define SX128X_REG_SYNC_WORD_2_BYTE_1 0x09D6 68 #define SX128X_REG_SYNC_WORD_2_BYTE_0 0x09D7 69 #define SX128X_REG_SYNC_WORD_3_BYTE_4 0x09D8 70 #define SX128X_REG_SYNC_WORD_3_BYTE_3 0x09D9 71 #define SX128X_REG_SYNC_WORD_3_BYTE_2 0x09DA 72 #define SX128X_REG_SYNC_WORD_3_BYTE_1 0x09DB 73 #define SX128X_REG_SYNC_WORD_3_BYTE_0 0x09DC 74 #define SX128X_REG_CRC_INITIAL_MSB 0x09C8 75 #define SX128X_REG_CRC_INITIAL_LSB 0x09C9 76 #define SX128X_REG_CRC_POLYNOMIAL_MSB 0x09C6 77 #define SX128X_REG_CRC_POLYNOMIAL_LSB 0x09C7 78 #define SX128X_REG_ACCESS_ADDRESS_BYTE_3 (SX128X_REG_SYNC_WORD_1_BYTE_3) 79 #define SX128X_REG_ACCESS_ADDRESS_BYTE_2 (SX128X_REG_SYNC_WORD_1_BYTE_2) 80 #define SX128X_REG_ACCESS_ADDRESS_BYTE_1 (SX128X_REG_SYNC_WORD_1_BYTE_1) 81 #define SX128X_REG_ACCESS_ADDRESS_BYTE_0 (SX128X_REG_SYNC_WORD_1_BYTE_0) 82 #define SX128X_REG_BLE_CRC_INITIAL_MSB 0x09C7 83 #define SX128X_REG_BLE_CRC_INITIAL_MID (SX128X_REG_CRC_INITIAL_MSB) 84 #define SX128X_REG_BLE_CRC_INITIAL_LSB (SX128X_REG_CRC_INITIAL_LSB) 85 #define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3 0x0916 86 #define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_2 0x0917 87 #define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_1 0x0918 88 #define SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_0 0x0919 89 #define SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH 0x0931 90 #define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_3 0x0912 91 #define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_2 0x0913 92 #define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_1 0x0914 93 #define SX128X_REG_MASTER_RANGING_ADDRESS_BYTE_0 0x0915 94 #define SX128X_REG_RANGING_CALIBRATION_MSB 0x092C 95 #define SX128X_REG_RANGING_CALIBRATION_LSB 0x092D 96 #define SX128X_REG_RANGING_RESULT_MSB 0x0961 97 #define SX128X_REG_RANGING_RESULT_MID 0x0962 98 #define SX128X_REG_RANGING_RESULT_LSB 0x0963 99 #define SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1 0x089F 100 #define SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2 0x0895 101 #define SX128X_REG_MANUAL_GAIN_SETTING 0x089E 102 #define SX128X_REG_GAIN_MODE 0x0891 103 #define SX128X_REG_LORA_FIXED_PAYLOAD_LENGTH 0x0901 104 #define SX128X_REG_LORA_SF_CONFIG 0x0925 105 #define SX128X_REG_FEI_MSB 0x0954 106 #define SX128X_REG_FEI_MID 0x0955 107 #define SX128X_REG_FEI_LSB 0x0956 108 #define SX128X_REG_RANGING_FILTER_WINDOW_SIZE 0x091E 109 #define SX128X_REG_RANGING_FILTER_RSSI_OFFSET 0x0953 110 #define SX128X_REG_RANGING_FILTER_RESET 0x0923 111 #define SX128X_REG_RANGING_LORA_CLOCK_ENABLE 0x097F 112 #define SX128X_REG_RANGING_TYPE 0x0924 113 #define SX128X_REG_RANGING_ADDRESS_SWITCH 0x0927 114 #define SX128X_REG_RANGING_ADDRESS_MSB 0x095F 115 #define SX128X_REG_RANGING_ADDRESS_LSB 0x0960 120 #define SX128X_STATUS_MODE_STDBY_RC 0b01000000 // 7 5 current chip mode: STDBY_RC 121 #define SX128X_STATUS_MODE_STDBY_XOSC 0b01100000 // 7 5 STDBY_XOSC 122 #define SX128X_STATUS_MODE_FS 0b10000000 // 7 5 FS 123 #define SX128X_STATUS_MODE_RX 0b10100000 // 7 5 Rx 124 #define SX128X_STATUS_MODE_TX 0b11000000 // 7 5 Tx 125 #define SX128X_STATUS_CMD_PROCESSED 0b00000100 // 4 2 command status: processing OK 126 #define SX128X_STATUS_DATA_AVAILABLE 0b00001000 // 4 2 data available 127 #define SX128X_STATUS_CMD_TIMEOUT 0b00001100 // 4 2 timeout 128 #define SX128X_STATUS_CMD_ERROR 0b00010000 // 4 2 processing error 129 #define SX128X_STATUS_CMD_FAILED 0b00010100 // 4 2 failed to execute 130 #define SX128X_STATUS_TX_DONE 0b00011000 // 4 2 transmission finished 131 #define SX128X_STATUS_BUSY 0b00000001 // 0 0 chip busy 132 #define SX128X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed 135 #define SX128X_SLEEP_DATA_BUFFER_FLUSH 0b00000000 // 1 1 data buffer behavior in sleep mode: flush 136 #define SX128X_SLEEP_DATA_BUFFER_RETAIN 0b00000010 // 1 1 retain 137 #define SX128X_SLEEP_DATA_RAM_FLUSH 0b00000000 // 0 0 data RAM (configuration) behavior in sleep mode: flush 138 #define SX128X_SLEEP_DATA_RAM_RETAIN 0b00000001 // 0 0 retain 141 #define SX128X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator 142 #define SX128X_STANDBY_XOSC 0x01 // 7 0 52 MHz crystal oscillator 145 #define SX128X_PERIOD_BASE_15_625_US 0x00 // 7 0 time period step: 15.625 us 146 #define SX128X_PERIOD_BASE_62_5_US 0x01 // 7 0 62.5 us 147 #define SX128X_PERIOD_BASE_1_MS 0x02 // 7 0 1 ms 148 #define SX128X_PERIOD_BASE_4_MS 0x03 // 7 0 4 ms 151 #define SX128X_TX_TIMEOUT_NONE 0x0000 // 15 0 Tx timeout duration: no timeout (Tx single mode) 154 #define SX128X_RX_TIMEOUT_NONE 0x0000 // 15 0 Rx timeout duration: no timeout (Rx single mode) 155 #define SX128X_RX_TIMEOUT_INF 0xFFFF // 15 0 infinite (Rx continuous mode) 158 #define SX128X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: (G)FSK 159 #define SX128X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa 160 #define SX128X_PACKET_TYPE_RANGING 0x02 // 7 0 ranging engine 161 #define SX128X_PACKET_TYPE_FLRC 0x03 // 7 0 FLRC 162 #define SX128X_PACKET_TYPE_BLE 0x04 // 7 0 BLE 165 #define SX128X_PA_RAMP_02_US 0x00 // 7 0 PA ramp time: 2 us 166 #define SX128X_PA_RAMP_04_US 0x20 // 7 0 4 us 167 #define SX128X_PA_RAMP_06_US 0x40 // 7 0 6 us 168 #define SX128X_PA_RAMP_08_US 0x60 // 7 0 8 us 169 #define SX128X_PA_RAMP_10_US 0x80 // 7 0 10 us 170 #define SX128X_PA_RAMP_12_US 0xA0 // 7 0 12 us 171 #define SX128X_PA_RAMP_16_US 0xC0 // 7 0 16 us 172 #define SX128X_PA_RAMP_20_US 0xE0 // 7 0 20 us 175 #define SX128X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1 176 #define SX128X_CAD_ON_2_SYMB 0x20 // 7 0 2 177 #define SX128X_CAD_ON_4_SYMB 0x40 // 7 0 4 178 #define SX128X_CAD_ON_8_SYMB 0x60 // 7 0 8 179 #define SX128X_CAD_ON_16_SYMB 0x80 // 7 0 16 182 #define SX128X_BLE_GFSK_BR_2_000_BW_2_4 0x04 // 7 0 GFSK/BLE bit rate and bandwidth setting: 2.0 Mbps 2.4 MHz 183 #define SX128X_BLE_GFSK_BR_1_600_BW_2_4 0x28 // 7 0 1.6 Mbps 2.4 MHz 184 #define SX128X_BLE_GFSK_BR_1_000_BW_2_4 0x4C // 7 0 1.0 Mbps 2.4 MHz 185 #define SX128X_BLE_GFSK_BR_1_000_BW_1_2 0x45 // 7 0 1.0 Mbps 1.2 MHz 186 #define SX128X_BLE_GFSK_BR_0_800_BW_2_4 0x70 // 7 0 0.8 Mbps 2.4 MHz 187 #define SX128X_BLE_GFSK_BR_0_800_BW_1_2 0x69 // 7 0 0.8 Mbps 1.2 MHz 188 #define SX128X_BLE_GFSK_BR_0_500_BW_1_2 0x8D // 7 0 0.5 Mbps 1.2 MHz 189 #define SX128X_BLE_GFSK_BR_0_500_BW_0_6 0x86 // 7 0 0.5 Mbps 0.6 MHz 190 #define SX128X_BLE_GFSK_BR_0_400_BW_1_2 0xB1 // 7 0 0.4 Mbps 1.2 MHz 191 #define SX128X_BLE_GFSK_BR_0_400_BW_0_6 0xAA // 7 0 0.4 Mbps 0.6 MHz 192 #define SX128X_BLE_GFSK_BR_0_250_BW_0_6 0xCE // 7 0 0.25 Mbps 0.6 MHz 193 #define SX128X_BLE_GFSK_BR_0_250_BW_0_3 0xC7 // 7 0 0.25 Mbps 0.3 MHz 194 #define SX128X_BLE_GFSK_BR_0_125_BW_0_3 0xEF // 7 0 0.125 Mbps 0.3 MHz 195 #define SX128X_BLE_GFSK_MOD_IND_0_35 0x00 // 7 0 GFSK/BLE modulation index: 0.35 196 #define SX128X_BLE_GFSK_MOD_IND_0_50 0x01 // 7 0 0.50 197 #define SX128X_BLE_GFSK_MOD_IND_0_75 0x02 // 7 0 0.75 198 #define SX128X_BLE_GFSK_MOD_IND_1_00 0x03 // 7 0 1.00 199 #define SX128X_BLE_GFSK_MOD_IND_1_25 0x04 // 7 0 1.25 200 #define SX128X_BLE_GFSK_MOD_IND_1_50 0x05 // 7 0 1.50 201 #define SX128X_BLE_GFSK_MOD_IND_1_75 0x06 // 7 0 1.75 202 #define SX128X_BLE_GFSK_MOD_IND_2_00 0x07 // 7 0 2.00 203 #define SX128X_BLE_GFSK_MOD_IND_2_25 0x08 // 7 0 2.25 204 #define SX128X_BLE_GFSK_MOD_IND_2_50 0x09 // 7 0 2.50 205 #define SX128X_BLE_GFSK_MOD_IND_2_75 0x0A // 7 0 2.75 206 #define SX128X_BLE_GFSK_MOD_IND_3_00 0x0B // 7 0 3.00 207 #define SX128X_BLE_GFSK_MOD_IND_3_25 0x0C // 7 0 3.25 208 #define SX128X_BLE_GFSK_MOD_IND_3_50 0x0D // 7 0 3.50 209 #define SX128X_BLE_GFSK_MOD_IND_3_75 0x0E // 7 0 3.75 210 #define SX128X_BLE_GFSK_MOD_IND_4_00 0x0F // 7 0 4.00 211 #define SX128X_BLE_GFSK_BT_OFF 0x00 // 7 0 GFSK Gaussian filter BT product: filter disabled 212 #define SX128X_BLE_GFSK_BT_1_0 0x10 // 7 0 1.0 213 #define SX128X_BLE_GFSK_BT_0_5 0x20 // 7 0 0.5 214 #define SX128X_FLRC_BR_1_300_BW_1_2 0x45 // 7 0 FLRC bit rate and bandwidth setting: 1.3 Mbps 1.2 MHz 215 #define SX128X_FLRC_BR_1_000_BW_1_2 0x69 // 7 0 1.04 Mbps 1.2 MHz 216 #define SX128X_FLRC_BR_0_650_BW_0_6 0x86 // 7 0 0.65 Mbps 0.6 MHz 217 #define SX128X_FLRC_BR_0_520_BW_0_6 0xAA // 7 0 0.52 Mbps 0.6 MHz 218 #define SX128X_FLRC_BR_0_325_BW_0_3 0xC7 // 7 0 0.325 Mbps 0.3 MHz 219 #define SX128X_FLRC_BR_0_260_BW_0_3 0xEB // 7 0 0.260 Mbps 0.3 MHz 220 #define SX128X_FLRC_CR_1_2 0x00 // 7 0 FLRC coding rate: 1/2 221 #define SX128X_FLRC_CR_3_4 0x02 // 7 0 3/4 222 #define SX128X_FLRC_CR_1_0 0x04 // 7 0 1/1 223 #define SX128X_FLRC_BT_OFF 0x00 // 7 0 FLRC Gaussian filter BT product: filter disabled 224 #define SX128X_FLRC_BT_1_0 0x10 // 7 0 1.0 225 #define SX128X_FLRC_BT_0_5 0x20 // 7 0 0.5 226 #define SX128X_LORA_SF_5 0x50 // 7 0 LoRa spreading factor: 5 227 #define SX128X_LORA_SF_6 0x60 // 7 0 6 228 #define SX128X_LORA_SF_7 0x70 // 7 0 7 229 #define SX128X_LORA_SF_8 0x80 // 7 0 8 230 #define SX128X_LORA_SF_9 0x90 // 7 0 9 231 #define SX128X_LORA_SF_10 0xA0 // 7 0 10 232 #define SX128X_LORA_SF_11 0xB0 // 7 0 11 233 #define SX128X_LORA_SF_12 0xC0 // 7 0 12 234 #define SX128X_LORA_BW_1625_00 0x0A // 7 0 LoRa bandwidth: 1625.0 kHz 235 #define SX128X_LORA_BW_812_50 0x18 // 7 0 812.5 kHz 236 #define SX128X_LORA_BW_406_25 0x26 // 7 0 406.25 kHz 237 #define SX128X_LORA_BW_203_125 0x34 // 7 0 203.125 kHz 238 #define SX128X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5 239 #define SX128X_LORA_CR_4_6 0x02 // 7 0 4/6 240 #define SX128X_LORA_CR_4_7 0x03 // 7 0 4/7 241 #define SX128X_LORA_CR_4_8 0x04 // 7 0 4/8 242 #define SX128X_LORA_CR_4_5_LI 0x05 // 7 0 4/5, long interleaving 243 #define SX128X_LORA_CR_4_6_LI 0x06 // 7 0 4/6, long interleaving 244 #define SX128X_LORA_CR_4_7_LI 0x07 // 7 0 4/7, long interleaving 247 #define SX128X_GFSK_FLRC_SYNC_WORD_OFF 0x00 // 7 0 GFSK/FLRC sync word used: none 248 #define SX128X_GFSK_FLRC_SYNC_WORD_1 0x10 // 7 0 sync word 1 249 #define SX128X_GFSK_FLRC_SYNC_WORD_2 0x20 // 7 0 sync word 2 250 #define SX128X_GFSK_FLRC_SYNC_WORD_1_2 0x30 // 7 0 sync words 1 and 2 251 #define SX128X_GFSK_FLRC_SYNC_WORD_3 0x40 // 7 0 sync word 3 252 #define SX128X_GFSK_FLRC_SYNC_WORD_1_3 0x50 // 7 0 sync words 1 and 3 253 #define SX128X_GFSK_FLRC_SYNC_WORD_2_3 0x60 // 7 0 sync words 2 and 3 254 #define SX128X_GFSK_FLRC_SYNC_WORD_1_2_3 0x70 // 7 0 sync words 1, 2 and 3 255 #define SX128X_GFSK_FLRC_PACKET_FIXED 0x00 // 7 0 GFSK/FLRC packet length mode: fixed 256 #define SX128X_GFSK_FLRC_PACKET_VARIABLE 0x20 // 7 0 variable 257 #define SX128X_GFSK_FLRC_CRC_OFF 0x00 // 7 0 GFSK/FLRC packet CRC: none 258 #define SX128X_GFSK_FLRC_CRC_1_BYTE 0x10 // 7 0 1 byte 259 #define SX128X_GFSK_FLRC_CRC_2_BYTE 0x20 // 7 0 2 bytes 260 #define SX128X_GFSK_FLRC_CRC_3_BYTE 0x30 // 7 0 3 bytes (FLRC only) 261 #define SX128X_GFSK_BLE_WHITENING_ON 0x00 // 7 0 GFSK/BLE whitening: enabled 262 #define SX128X_GFSK_BLE_WHITENING_OFF 0x08 // 7 0 disabled 263 #define SX128X_BLE_PAYLOAD_LENGTH_MAX_31 0x00 // 7 0 BLE maximum payload length: 31 bytes 264 #define SX128X_BLE_PAYLOAD_LENGTH_MAX_37 0x20 // 7 0 37 bytes 265 #define SX128X_BLE_PAYLOAD_LENGTH_TEST 0x40 // 7 0 63 bytes (test mode) 266 #define SX128X_BLE_PAYLOAD_LENGTH_MAX_255 0x80 // 7 0 255 bytes (Bluetooth 4.2 and above) 267 #define SX128X_BLE_CRC_OFF 0x00 // 7 0 BLE packet CRC: none 268 #define SX128X_BLE_CRC_3_BYTE 0x10 // 7 0 3 byte 269 #define SX128X_BLE_PRBS_9 0x00 // 7 0 BLE test payload contents: PRNG sequence using x^9 + x^5 + x 270 #define SX128X_BLE_EYELONG 0x04 // 7 0 repeated 0xF0 271 #define SX128X_BLE_EYESHORT 0x08 // 7 0 repeated 0xAA 272 #define SX128X_BLE_PRBS_15 0x0C // 7 0 PRNG sequence using x^15 + x^14 + x^13 + x^12 + x^2 + x + 1 273 #define SX128X_BLE_ALL_1 0x10 // 7 0 repeated 0xFF 274 #define SX128X_BLE_ALL_0 0x14 // 7 0 repeated 0x00 275 #define SX128X_BLE_EYELONG_INV 0x18 // 7 0 repeated 0x0F 276 #define SX128X_BLE_EYESHORT_INV 0x1C // 7 0 repeated 0x55 277 #define SX128X_FLRC_SYNC_WORD_OFF 0x00 // 7 0 FLRC sync word: disabled 278 #define SX128X_FLRC_SYNC_WORD_ON 0x04 // 7 0 enabled 279 #define SX128X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit 280 #define SX128X_LORA_HEADER_IMPLICIT 0x80 // 7 0 implicit 281 #define SX128X_LORA_CRC_OFF 0x00 // 7 0 LoRa packet CRC: disabled 282 #define SX128X_LORA_CRC_ON 0x20 // 7 0 enabled 283 #define SX128X_LORA_IQ_STANDARD 0x40 // 7 0 LoRa IQ: standard 284 #define SX128X_LORA_IQ_INVERTED 0x00 // 7 0 inverted 287 #define SX128X_PACKET_STATUS_SYNC_ERROR 0b01000000 // 6 6 packet status errors byte: sync word error 288 #define SX128X_PACKET_STATUS_LENGTH_ERROR 0b00100000 // 5 5 packet length error 289 #define SX128X_PACKET_STATUS_CRC_ERROR 0b00010000 // 4 4 CRC error 290 #define SX128X_PACKET_STATUS_ABORT_ERROR 0b00001000 // 3 3 packet reception aborted 291 #define SX128X_PACKET_STATUS_HEADER_RECEIVED 0b00000100 // 2 2 header received 292 #define SX128X_PACKET_STATUS_PACKET_RECEIVED 0b00000010 // 1 1 packet received 293 #define SX128X_PACKET_STATUS_PACKET_CTRL_BUSY 0b00000001 // 0 0 packet controller is busy 294 #define SX128X_PACKET_STATUS_RX_PID 0b11000000 // 7 6 packet status status byte: PID field of the received packet 295 #define SX128X_PACKET_STATUS_NO_ACK 0b00100000 // 5 5 NO_ACK field of the received packet 296 #define SX128X_PACKET_STATUS_RX_PID_ERROR 0b00010000 // 4 4 PID field error 297 #define SX128X_PACKET_STATUS_PACKET_SENT 0b00000001 // 0 0 packet sent 298 #define SX128X_PACKET_STATUS_SYNC_DET_ERROR 0b00000000 // 2 0 packet status sync byte: sync word detection error 299 #define SX128X_PACKET_STATUS_SYNC_DET_1 0b00000001 // 2 0 detected sync word 1 300 #define SX128X_PACKET_STATUS_SYNC_DET_2 0b00000010 // 2 0 detected sync word 2 301 #define SX128X_PACKET_STATUS_SYNC_DET_3 0b00000100 // 2 0 detected sync word 3 304 #define SX128X_IRQ_PREAMBLE_DETECTED 0x8000 // 15 15 interrupt source: preamble detected 305 #define SX128X_IRQ_ADVANCED_RANGING_DONE 0x8000 // 15 15 advanced ranging done 306 #define SX128X_IRQ_RX_TX_TIMEOUT 0x4000 // 14 14 Rx or Tx timeout 307 #define SX128X_IRQ_CAD_DETECTED 0x2000 // 13 13 channel activity detected 308 #define SX128X_IRQ_CAD_DONE 0x1000 // 12 12 CAD finished 309 #define SX128X_IRQ_RANGING_SLAVE_REQ_VALID 0x0800 // 11 11 ranging request valid (slave) 310 #define SX128X_IRQ_RANGING_MASTER_TIMEOUT 0x0400 // 10 10 ranging timeout (master) 311 #define SX128X_IRQ_RANGING_MASTER_RES_VALID 0x0200 // 9 9 ranging result valid (master) 312 #define SX128X_IRQ_RANGING_SLAVE_REQ_DISCARD 0x0100 // 8 8 ranging result valid (master) 313 #define SX128X_IRQ_RANGING_SLAVE_RESP_DONE 0x0080 // 7 7 ranging response complete (slave) 314 #define SX128X_IRQ_CRC_ERROR 0x0040 // 6 6 CRC error 315 #define SX128X_IRQ_HEADER_ERROR 0x0020 // 5 5 header error 316 #define SX128X_IRQ_HEADER_VALID 0x0010 // 4 4 header valid 317 #define SX128X_IRQ_SYNC_WORD_ERROR 0x0008 // 3 3 sync word error 318 #define SX128X_IRQ_SYNC_WORD_VALID 0x0004 // 2 2 sync word valid 319 #define SX128X_IRQ_RX_DONE 0x0002 // 1 1 Rx done 320 #define SX128X_IRQ_TX_DONE 0x0001 // 0 0 Tx done 321 #define SX128X_IRQ_NONE 0x0000 // 15 0 none 322 #define SX128X_IRQ_ALL 0xFFFF // 15 0 all 325 #define SX128X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default) 326 #define SX128X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC 329 #define SX128X_RANGING_ROLE_MASTER 0x01 // 7 0 ranging role: master 330 #define SX128X_RANGING_ROLE_SLAVE 0x00 // 7 0 slave 373 int16_t
begin(
float freq = 2400.0,
float bw = 812.5, uint8_t sf = 9, uint8_t cr = 7, int8_t power = 10, uint16_t preambleLength = 12);
390 int16_t
beginGFSK(
float freq = 2400.0, uint16_t br = 800,
float freqDev = 400.0, int8_t power = 10, uint16_t preambleLength = 16);
407 int16_t
beginBLE(
float freq = 2400.0, uint16_t br = 800,
float freqDev = 400.0, int8_t power = 10, uint8_t dataShaping =
RADIOLIB_SHAPING_0_5);
426 int16_t
beginFLRC(
float freq = 2400.0, uint16_t br = 650, uint8_t cr = 3, int8_t power = 10, uint16_t preambleLength = 16, uint8_t dataShaping =
RADIOLIB_SHAPING_0_5);
436 int16_t
reset(
bool verify =
true);
450 int16_t
transmit(uint8_t* data,
size_t len, uint8_t addr = 0)
override;
462 int16_t
receive(uint8_t* data,
size_t len)
override;
495 int16_t
sleep(
bool retainConfig =
true);
539 int16_t
startTransmit(uint8_t* data,
size_t len, uint8_t addr = 0)
override;
548 int16_t
startReceive(uint16_t timeout = SX128X_RX_TIMEOUT_INF);
559 int16_t
readData(uint8_t* data,
size_t len)
override;
599 int16_t
setCodingRate(uint8_t cr,
bool longInterleaving =
false);
656 int16_t
setSyncWord(uint8_t* syncWord, uint8_t len);
669 int16_t
setCRC(uint8_t len, uint32_t initial = 0x1D0F, uint16_t polynomial = 0x1021);
763 #ifndef RADIOLIB_GODMODE 770 uint8_t _bw = 0, _sf = 0, _cr = 0;
771 uint8_t _preambleLengthLoRa = 0, _headerType = 0, _payloadLen = 0, _crcLoRa = 0;
775 int16_t writeRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
776 int16_t readRegister(uint16_t addr, uint8_t* data, uint8_t numBytes);
777 int16_t writeBuffer(uint8_t* data, uint8_t numBytes, uint8_t offset = 0x00);
778 int16_t readBuffer(uint8_t* data, uint8_t numBytes);
779 int16_t setTx(uint16_t periodBaseCount = SX128X_TX_TIMEOUT_NONE, uint8_t periodBase = SX128X_PERIOD_BASE_15_625_US);
780 int16_t setRx(uint16_t periodBaseCount, uint8_t periodBase = SX128X_PERIOD_BASE_15_625_US);
782 uint8_t getPacketType();
783 int16_t setRfFrequency(uint32_t frf);
784 int16_t setTxParams(uint8_t power, uint8_t rampTime = SX128X_PA_RAMP_10_US);
785 int16_t setBufferBaseAddress(uint8_t txBaseAddress = 0x00, uint8_t rxBaseAddress = 0x00);
786 int16_t setModulationParams(uint8_t modParam1, uint8_t modParam2, uint8_t modParam3);
787 int16_t setPacketParamsGFSK(uint8_t preambleLen, uint8_t syncWordLen, uint8_t syncWordMatch, uint8_t crcLen, uint8_t whitening, uint8_t payloadLen = 0xFF, uint8_t headerType = SX128X_GFSK_FLRC_PACKET_VARIABLE);
788 int16_t setPacketParamsBLE(uint8_t connState, uint8_t crcLen, uint8_t bleTestPayload, uint8_t whitening);
789 int16_t setPacketParamsLoRa(uint8_t preambleLen, uint8_t headerType, uint8_t payloadLen, uint8_t crc, uint8_t invertIQ = SX128X_LORA_IQ_STANDARD);
790 int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = SX128X_IRQ_NONE, uint16_t dio3Mask = SX128X_IRQ_NONE);
791 uint16_t getIrqStatus();
792 int16_t clearIrqStatus(uint16_t clearIrqParams = SX128X_IRQ_ALL);
793 int16_t setRangingRole(uint8_t role);
794 int16_t setPacketType(uint8_t type);
796 int16_t setHeaderType(uint8_t headerType,
size_t len = 0xFF);
798 #ifndef RADIOLIB_GODMODE 805 float _modIndexReal = 0;
806 uint16_t _brKbps = 0;
807 uint8_t _br = 0, _modIndex = 0, _shaping = 0;
808 uint8_t _preambleLengthGFSK = 0, _syncWordLen = 0, _syncWordMatch = 0, _crcGFSK = 0, _whitening = 0;
814 uint8_t _connectionState = 0, _crcBLE = 0, _bleTestPayload = 0;
816 int16_t config(uint8_t modem);
819 int16_t SPIwriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes,
bool waitForBusy =
true);
820 int16_t SPIwriteCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes,
bool waitForBusy =
true);
821 int16_t SPIreadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes,
bool waitForBusy =
true);
822 int16_t SPIreadCommand(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, uint8_t numBytes,
bool waitForBusy =
true);
823 int16_t SPItransfer(uint8_t* cmd, uint8_t cmdLen,
bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes,
bool waitForBusy, uint32_t timeout = 5000);
int16_t explicitHeader()
Set explicit header mode for future reception/transmission.
Definition: SX128x.cpp:1123
int16_t setAccessAddress(uint32_t addr)
Sets BLE access address.
Definition: SX128x.cpp:993
int16_t receive(uint8_t *data, size_t len) override
Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalL...
Definition: SX128x.cpp:312
int16_t standby() override
Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator)...
Definition: SX128x.cpp:434
void clearDio1Action()
Clears interrupt service routine to call when DIO1 activates.
Definition: SX128x.cpp:450
int16_t startTransmit(String &str, uint8_t addr=0)
Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.
Definition: PhysicalLayer.cpp:49
#define RADIOLIB_SHAPING_0_5
Gaussin shaping filter, BT = 0.5.
Definition: TypeDef.h:110
int16_t sleep(bool retainConfig=true)
Sets the module to sleep mode.
Definition: SX128x.cpp:418
int16_t implicitHeader(size_t len)
Set implicit header mode for future reception/transmission.
Definition: SX128x.cpp:1119
int16_t setEncoding(uint8_t encoding) override
Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility. ...
Definition: SX128x.cpp:1127
int16_t reset(bool verify=true)
Reset method. Will reset the chip to the default state using RST pin.
Definition: SX128x.cpp:231
int16_t setSyncWord(uint8_t *syncWord, uint8_t len)
Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long.
Definition: SX128x.cpp:861
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: SX128x.cpp:264
float getSNR()
Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging mode...
Definition: SX128x.cpp:1028
int16_t setBitRate(uint16_t br)
Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for ...
Definition: SX128x.cpp:741
uint32_t getTimeOnAir(size_t len)
Get expected time-on-air for a given size of payload.
Definition: SX128x.cpp:1055
int16_t beginGFSK(float freq=2400.0, uint16_t br=800, float freqDev=400.0, int8_t power=10, uint16_t preambleLength=16)
Initialization method for GFSK modem.
Definition: SX128x.cpp:60
size_t getPacketLength(bool update=true) override
Query modem for the packet length of received payload.
Definition: SX128x.cpp:1048
int16_t setSpreadingFactor(uint8_t sf)
Sets LoRa spreading factor. Allowed values range from 5 to 12.
Definition: SX128x.cpp:625
int16_t setWhitening(bool enabled)
Sets whitening parameters, not available for LoRa or FLRC modem.
Definition: SX128x.cpp:973
uint8_t random()
Dummy random method, to ensure PhysicalLayer compatibility.
Definition: SX128x.cpp:1135
int16_t setBandwidth(float bw)
Sets LoRa bandwidth. Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz.
Definition: SX128x.cpp:595
int16_t setCRC(uint8_t len, uint32_t initial=0x1D0F, uint16_t polynomial=0x1021)
Sets CRC configuration.
Definition: SX128x.cpp:909
int16_t receiveDirect() override
Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does...
Definition: SX128x.cpp:365
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: SX128x.cpp:1131
void setDio1Action(void(*func)(void))
Sets interrupt service routine to call when DIO1 activates.
Definition: SX128x.cpp:446
Implements all common low-level SPI/UART/I2C methods to control the wireless module. Every module class contains one private instance of this class.
Definition: Module.h:17
int16_t transmit(__FlashStringHelper *fstr, uint8_t addr=0)
Arduino Flash String transmit method.
Definition: PhysicalLayer.cpp:8
Base class for SX128x series. All derived classes for SX128x (e.g. SX1280 or SX1281) inherit from thi...
Definition: SX128x.h:339
int16_t receive(String &str, size_t len=0)
Arduino String receive method.
Definition: PhysicalLayer.cpp:98
int16_t setFrequency(float freq)
Sets carrier frequency. Allowed values are in range from 2400.0 to 2500.0 MHz.
Definition: SX128x.cpp:587
int16_t beginBLE(float freq=2400.0, uint16_t br=800, float freqDev=400.0, int8_t power=10, uint8_t dataShaping=RADIOLIB_SHAPING_0_5)
Initialization method for BLE modem.
Definition: SX128x.cpp:123
int16_t readData(uint8_t *data, size_t len) override
Reads data received after calling startReceive method.
Definition: SX128x.cpp:551
Provides common interface for protocols that run on LoRa/FSK modules, such as RTTY or LoRaWAN...
Definition: PhysicalLayer.h:13
int16_t scanChannel()
Performs scan for LoRa transmission in the current channel. Detects both preamble and payload...
Definition: SX128x.cpp:373
SX128x(Module *mod)
Default constructor.
Definition: SX128x.cpp:4
float getRSSI()
Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
Definition: SX128x.cpp:1004
int16_t setPreambleLength(uint32_t preambleLength)
Sets preamble length for currently active modem. Allowed values range from 1 to 65535.
Definition: SX128x.cpp:693
int16_t setCodingRate(uint8_t cr, bool longInterleaving=false)
Sets LoRa coding rate denominator. Allowed values range from 5 to 8.
Definition: SX128x.cpp:659
int16_t beginFLRC(float freq=2400.0, uint16_t br=650, uint8_t cr=3, int8_t power=10, uint16_t preambleLength=16, uint8_t dataShaping=RADIOLIB_SHAPING_0_5)
Initialization method for FLRC modem.
Definition: SX128x.cpp:172
int16_t begin(float freq=2400.0, float bw=812.5, uint8_t sf=9, uint8_t cr=7, int8_t power=10, uint16_t preambleLength=12)
Initialization method for LoRa modem.
Definition: SX128x.cpp:8
int16_t startReceive(uint16_t timeout=SX128X_RX_TIMEOUT_INF)
Interrupt-driven receive method. DIO1 will be activated when full packet is received.
Definition: SX128x.cpp:518
int16_t setDataShaping(uint8_t sh) override
Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPI...
Definition: SX128x.cpp:831
int16_t setFrequencyDeviation(float freqDev) override
Sets FSK frequency deviation. Allowed values range from 0.0 to 3200.0 kHz.
Definition: SX128x.cpp:798
int16_t transmitDirect(uint32_t frf=0) override
Starts direct mode transmission.
Definition: SX128x.cpp:350
int16_t setOutputPower(int8_t power)
Sets output power. Allowed values are in range from -18 to 13 dBm.
Definition: SX128x.cpp:687
int16_t readData(String &str, size_t len=0)
Reads data that was received after calling startReceive method.
Definition: PhysicalLayer.cpp:57
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: SX128x.cpp:454