sx126x

package
v0.0.0-...-2e22e3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2024 License: BSD-3-Clause Imports: 5 Imported by: 0

README

SX126x LoRa Radio

The Semtech SX126x family of sub-Ghz radio transceivers come in a number of different formats.

SX126x radios have a wide continuous frequency coverage from 150 MHz to 960 MHz.

SX1261 can transmit up to +15 dBm and the SX1262 can transmit up to +22 dBm

Some development boards are specific to a particular frequency range, so for example you need a different variation of that board for EU868 vs. for AU915.

LAMBDA62 RF module

Cost effective radio module featuring the Semtech SX1262.

STM32 STM32WLE5JC

ST Micro STM32WLE5/E4xx is 32-bit ARM Cortex M4 processor with Semtech SX126x processor on a single die.

https://www.st.com/en/microcontrollers-microprocessors/stm32wle5jc.html

Several boards have been made using this processor.

Wio-E5 mini

https://www.seeedstudio.com/LoRa-E5-mini-STM32WLE5JC-p-4869.html

Wio-E5 mini is a compacted-sized dev board suitable for the rapid testing and building of small-size LoRa device and application prototyping. Wio-E5 mini is embedded with and leads out full GPIOs of Wio-E5 STM32WLE5JC

Documentation

Index

Constants

View Source
const (
	// SX126X physical layer properties
	SX126X_FREQUENCY_STEP_SIZE = 0.9536743164
	SX126X_MAX_PACKET_LENGTH   = 255
	SX126X_CRYSTAL_FREQ        = 32.0
	SX126X_DIV_EXPONENT        = 25

	// SX126X SPI commands
	// operational modes commands
	SX126X_CMD_NOP                      = 0x00
	SX126X_CMD_SET_SLEEP                = 0x84
	SX126X_CMD_SET_STANDBY              = 0x80
	SX126X_CMD_SET_FS                   = 0xC1
	SX126X_CMD_SET_TX                   = 0x83
	SX126X_CMD_SET_RX                   = 0x82
	SX126X_CMD_STOP_TIMER_ON_PREAMBLE   = 0x9F
	SX126X_CMD_SET_RX_DUTY_CYCLE        = 0x94
	SX126X_CMD_SET_CAD                  = 0xC5
	SX126X_CMD_SET_TX_CONTINUOUS_WAVE   = 0xD1
	SX126X_CMD_SET_TX_INFINITE_PREAMBLE = 0xD2
	SX126X_CMD_SET_REGULATOR_MODE       = 0x96
	SX126X_CMD_CALIBRATE                = 0x89
	SX126X_CMD_CALIBRATE_IMAGE          = 0x98
	SX126X_CMD_SET_PA_CONFIG            = 0x95
	SX126X_CMD_SET_RX_TX_FALLBACK_MODE  = 0x93

	// register and buffer access commands
	SX126X_CMD_WRITE_REGISTER = 0x0D
	SX126X_CMD_READ_REGISTER  = 0x1D
	SX126X_CMD_WRITE_BUFFER   = 0x0E
	SX126X_CMD_READ_BUFFER    = 0x1E

	// DIO and IRQ control
	SX126X_CMD_SET_DIO_IRQ_PARAMS         = 0x08
	SX126X_CMD_GET_IRQ_STATUS             = 0x12
	SX126X_CMD_CLEAR_IRQ_STATUS           = 0x02
	SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL = 0x9D
	SX126X_CMD_SET_DIO3_AS_TCXO_CTRL      = 0x97

	// RF, modulation and packet commands
	SX126X_CMD_SET_RF_FREQUENCY          = 0x86
	SX126X_CMD_SET_PACKET_TYPE           = 0x8A
	SX126X_CMD_GET_PACKET_TYPE           = 0x11
	SX126X_CMD_SET_TX_PARAMS             = 0x8E
	SX126X_CMD_SET_MODULATION_PARAMS     = 0x8B
	SX126X_CMD_SET_PACKET_PARAMS         = 0x8C
	SX126X_CMD_SET_CAD_PARAMS            = 0x88
	SX126X_CMD_SET_BUFFER_BASE_ADDRESS   = 0x8F
	SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT = 0x0A

	// status commands
	SX126X_CMD_GET_STATUS           = 0xC0
	SX126X_CMD_GET_RSSI_INST        = 0x15
	SX126X_CMD_GET_RX_BUFFER_STATUS = 0x13
	SX126X_CMD_GET_PACKET_STATUS    = 0x14
	SX126X_CMD_GET_DEVICE_ERRORS    = 0x17
	SX126X_CMD_CLEAR_DEVICE_ERRORS  = 0x07
	SX126X_CMD_GET_STATS            = 0x10
	SX126X_CMD_RESET_STATS          = 0x00

	// SX126X register map
	SX126X_REG_WHITENING_INITIAL_MSB = 0x06B8
	SX126X_REG_WHITENING_INITIAL_LSB = 0x06B9
	SX126X_REG_CRC_INITIAL_MSB       = 0x06BC
	SX126X_REG_CRC_INITIAL_LSB       = 0x06BD
	SX126X_REG_CRC_POLYNOMIAL_MSB    = 0x06BE
	SX126X_REG_CRC_POLYNOMIAL_LSB    = 0x06BF
	SX126X_REG_SYNC_WORD_0           = 0x06C0
	SX126X_REG_SYNC_WORD_1           = 0x06C1
	SX126X_REG_SYNC_WORD_2           = 0x06C2
	SX126X_REG_SYNC_WORD_3           = 0x06C3
	SX126X_REG_SYNC_WORD_4           = 0x06C4
	SX126X_REG_SYNC_WORD_5           = 0x06C5
	SX126X_REG_SYNC_WORD_6           = 0x06C6
	SX126X_REG_SYNC_WORD_7           = 0x06C7
	SX126X_REG_NODE_ADDRESS          = 0x06CD
	SX126X_REG_BROADCAST_ADDRESS     = 0x06CE
	SX126X_REG_LORA_SYNC_WORD_MSB    = 0x0740
	SX126X_REG_LORA_SYNC_WORD_LSB    = 0x0741
	SX126X_REG_RANDOM_NUMBER_0       = 0x0819
	SX126X_REG_RANDOM_NUMBER_1       = 0x081A
	SX126X_REG_RANDOM_NUMBER_2       = 0x081B
	SX126X_REG_RANDOM_NUMBER_3       = 0x081C
	SX126X_REG_RX_GAIN               = 0x08AC
	SX126X_REG_OCP_CONFIGURATION     = 0x08E7
	SX126X_REG_XTA_TRIM              = 0x0911
	SX126X_REG_XTB_TRIM              = 0x0912

	// undocumented registers
	SX126X_REG_SENSITIVITY_CONFIG  = 0x0889 // SX1268 datasheet v1.1, section 15.1
	SX126X_REG_TX_CLAMP_CONFIG     = 0x08D8 // SX1268 datasheet v1.1, section 15.2
	SX126X_REG_RTC_STOP            = 0x0920 // SX1268 datasheet v1.1, section 15.3
	SX126X_REG_RTC_EVENT           = 0x0944 // SX1268 datasheet v1.1, section 15.3
	SX126X_REG_IQ_CONFIG           = 0x0736 // SX1268 datasheet v1.1, section 15.4
	SX126X_REG_RX_GAIN_RETENTION_0 = 0x029F // SX1268 datasheet v1.1, section 9.6
	SX126X_REG_RX_GAIN_RETENTION_1 = 0x02A0 // SX1268 datasheet v1.1, section 9.6
	SX126X_REG_RX_GAIN_RETENTION_2 = 0x02A1 // SX1268 datasheet v1.1, section 9.6

	// SX126X SPI command variables
	//SX126X_CMD_SET_SLEEP                                                MSB   LSB   DESCRIPTION
	SX126X_SLEEP_START_COLD = 0b00000000 //  2     2     sleep mode: cold start, configuration is lost (default)
	SX126X_SLEEP_START_WARM = 0b00000100 //  2     2                 warm start, configuration is retained
	SX126X_SLEEP_RTC_OFF    = 0b00000000 //  0     0     wake on RTC timeout: disabled
	SX126X_SLEEP_RTC_ON     = 0b00000001 //  0     0                          enabled

	//SX126X_CMD_SET_STANDBY
	SX126X_STANDBY_RC   = 0x00 //  7     0     standby mode: 13 MHz RC oscillator
	SX126X_STANDBY_XOSC = 0x01 //  7     0                   32 MHz crystal oscillator

	//SX126X_CMD_SET_RX
	SX126X_RX_TIMEOUT_NONE = 0x000000 //  23    0     Rx timeout duration: no timeout (Rx single mode)
	SX126X_RX_TIMEOUT_INF  = 0xFFFFFF //  23    0                          infinite (Rx continuous mode)

	//SX126X_CMD_SET_TX
	SX126X_TX_TIMEOUT_NONE = 0x000000 //  23    0     Tx timeout duration: no timeout (Tx single mode)

	//SX126X_CMD_STOP_TIMER_ON_PREAMBLE
	SX126X_STOP_ON_PREAMBLE_OFF = 0x00 //  7     0     stop timer on: sync word or header (default)
	SX126X_STOP_ON_PREAMBLE_ON  = 0x01 //  7     0                    preamble detection

	//SX126X_CMD_SET_REGULATOR_MODE
	SX126X_REGULATOR_LDO   = 0x00 //  7     0     set regulator mode: LDO (default)
	SX126X_REGULATOR_DC_DC = 0x01 //  7     0                         DC-DC

	//SX126X_CMD_CALIBRATE
	SX126X_CALIBRATE_IMAGE_OFF      = 0b00000000 //  6     6     image calibration: disabled
	SX126X_CALIBRATE_IMAGE_ON       = 0b01000000 //  6     6                        enabled
	SX126X_CALIBRATE_ADC_BULK_P_OFF = 0b00000000 //  5     5     ADC bulk P calibration: disabled
	SX126X_CALIBRATE_ADC_BULK_P_ON  = 0b00100000 //  5     5                             enabled
	SX126X_CALIBRATE_ADC_BULK_N_OFF = 0b00000000 //  4     4     ADC bulk N calibration: disabled
	SX126X_CALIBRATE_ADC_BULK_N_ON  = 0b00010000 //  4     4                             enabled
	SX126X_CALIBRATE_ADC_PULSE_OFF  = 0b00000000 //  3     3     ADC pulse calibration: disabled
	SX126X_CALIBRATE_ADC_PULSE_ON   = 0b00001000 //  3     3                            enabled
	SX126X_CALIBRATE_PLL_OFF        = 0b00000000 //  2     2     PLL calibration: disabled
	SX126X_CALIBRATE_PLL_ON         = 0b00000100 //  2     2                      enabled
	SX126X_CALIBRATE_RC13M_OFF      = 0b00000000 //  1     1     13 MHz RC osc. calibration: disabled
	SX126X_CALIBRATE_RC13M_ON       = 0b00000010 //  1     1                                 enabled
	SX126X_CALIBRATE_RC64K_OFF      = 0b00000000 //  0     0     64 kHz RC osc. calibration: disabled
	SX126X_CALIBRATE_RC64K_ON       = 0b00000001 //  0     0                                 enabled
	SX126X_CALIBRATE_ALL            = 0b01111111 //  6     0     calibrate all blocks

	//SX126X_CMD_CALIBRATE_IMAGE
	SX126X_CAL_IMG_430_MHZ_1 = 0x6B
	SX126X_CAL_IMG_430_MHZ_2 = 0x6F
	SX126X_CAL_IMG_470_MHZ_1 = 0x75
	SX126X_CAL_IMG_470_MHZ_2 = 0x81
	SX126X_CAL_IMG_779_MHZ_1 = 0xC1
	SX126X_CAL_IMG_779_MHZ_2 = 0xC5
	SX126X_CAL_IMG_863_MHZ_1 = 0xD7
	SX126X_CAL_IMG_863_MHZ_2 = 0xDB
	SX126X_CAL_IMG_902_MHZ_1 = 0xE1
	SX126X_CAL_IMG_902_MHZ_2 = 0xE9

	//SX126X_CMD_SET_PA_CONFIG
	SX126X_PA_CONFIG_HP_MAX   = 0x07
	SX126X_PA_CONFIG_PA_LUT   = 0x01
	SX126X_PA_CONFIG_SX1262_8 = 0x00

	//SX126X_CMD_SET_RX_TX_FALLBACK_MODE
	SX126X_RX_TX_FALLBACK_MODE_FS         = 0x40 //  7     0     after Rx/Tx go to: FS mode
	SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC = 0x30 //  7     0                        standby with crystal oscillator
	SX126X_RX_TX_FALLBACK_MODE_STDBY_RC   = 0x20 //  7     0                        standby with RC oscillator (default)

	//SX126X_CMD_SET_DIO_IRQ_PARAMS
	SX126X_IRQ_TIMEOUT           = 0b1000000000 //  9     9     Rx or Tx timeout
	SX126X_IRQ_CAD_DETECTED      = 0b0100000000 //  8     8     channel activity detected
	SX126X_IRQ_CAD_DONE          = 0b0010000000 //  7     7     channel activity detection finished
	SX126X_IRQ_CRC_ERR           = 0b0001000000 //  6     6     wrong CRC received
	SX126X_IRQ_HEADER_ERR        = 0b0000100000 //  5     5     LoRa header CRC error
	SX126X_IRQ_HEADER_VALID      = 0b0000010000 //  4     4     valid LoRa header received
	SX126X_IRQ_SYNC_WORD_VALID   = 0b0000001000 //  3     3     valid sync word detected
	SX126X_IRQ_PREAMBLE_DETECTED = 0b0000000100 //  2     2     preamble detected
	SX126X_IRQ_RX_DONE           = 0b0000000010 //  1     1     packet received
	SX126X_IRQ_TX_DONE           = 0b0000000001 //  0     0     packet transmission completed
	SX126X_IRQ_ALL               = 0b1111111111 //  9     0     all interrupts
	SX126X_IRQ_NONE              = 0b0000000000 //  9     0     no interrupts

	//SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL
	SX126X_DIO2_AS_IRQ       = 0x00 //  7     0     DIO2 configuration: IRQ
	SX126X_DIO2_AS_RF_SWITCH = 0x01 //  7     0                         RF switch control

	//SX126X_CMD_SET_DIO3_AS_TCXO_CTRL
	SX126X_DIO3_OUTPUT_1_6 = 0x00 //  7     0     DIO3 voltage output for TCXO: 1.6 V
	SX126X_DIO3_OUTPUT_1_7 = 0x01 //  7     0                                   1.7 V
	SX126X_DIO3_OUTPUT_1_8 = 0x02 //  7     0                                   1.8 V
	SX126X_DIO3_OUTPUT_2_2 = 0x03 //  7     0                                   2.2 V
	SX126X_DIO3_OUTPUT_2_4 = 0x04 //  7     0                                   2.4 V
	SX126X_DIO3_OUTPUT_2_7 = 0x05 //  7     0                                   2.7 V
	SX126X_DIO3_OUTPUT_3_0 = 0x06 //  7     0                                   3.0 V
	SX126X_DIO3_OUTPUT_3_3 = 0x07 //  7     0                                   3.3 V

	//SX126X_CMD_SET_PACKET_TYPE
	SX126X_PACKET_TYPE_GFSK = 0x00 //  7     0     packet type: GFSK
	SX126X_PACKET_TYPE_LORA = 0x01 //  7     0                  LoRa

	//SX126X_CMD_SET_TX_PARAMS
	SX126X_PA_RAMP_10U   = 0x00 //  7     0     ramp time: 10 us
	SX126X_PA_RAMP_20U   = 0x01 //  7     0                20 us
	SX126X_PA_RAMP_40U   = 0x02 //  7     0                40 us
	SX126X_PA_RAMP_80U   = 0x03 //  7     0                80 us
	SX126X_PA_RAMP_200U  = 0x04 //  7     0                200 us
	SX126X_PA_RAMP_800U  = 0x05 //  7     0                800 us
	SX126X_PA_RAMP_1700U = 0x06 //  7     0                1700 us
	SX126X_PA_RAMP_3400U = 0x07 //  7     0                3400 us

	//SX126X_CMD_SET_MODULATION_PARAMS
	SX126X_GFSK_FILTER_NONE      = 0x00 //  7     0     GFSK filter: none
	SX126X_GFSK_FILTER_GAUSS_0_3 = 0x08 //  7     0                  Gaussian, BT = 0.3
	SX126X_GFSK_FILTER_GAUSS_0_5 = 0x09 //  7     0                  Gaussian, BT = 0.5
	SX126X_GFSK_FILTER_GAUSS_0_7 = 0x0A //  7     0                  Gaussian, BT = 0.7
	SX126X_GFSK_FILTER_GAUSS_1   = 0x0B //  7     0                  Gaussian, BT = 1
	SX126X_GFSK_RX_BW_4_8        = 0x1F //  7     0     GFSK Rx bandwidth: 4.8 kHz
	SX126X_GFSK_RX_BW_5_8        = 0x17 //  7     0                        5.8 kHz
	SX126X_GFSK_RX_BW_7_3        = 0x0F //  7     0                        7.3 kHz
	SX126X_GFSK_RX_BW_9_7        = 0x1E //  7     0                        9.7 kHz
	SX126X_GFSK_RX_BW_11_7       = 0x16 //  7     0                        11.7 kHz
	SX126X_GFSK_RX_BW_14_6       = 0x0E //  7     0                        14.6 kHz
	SX126X_GFSK_RX_BW_19_5       = 0x1D //  7     0                        19.5 kHz
	SX126X_GFSK_RX_BW_23_4       = 0x15 //  7     0                        23.4 kHz
	SX126X_GFSK_RX_BW_29_3       = 0x0D //  7     0                        29.3 kHz
	SX126X_GFSK_RX_BW_39_0       = 0x1C //  7     0                        39.0 kHz
	SX126X_GFSK_RX_BW_46_9       = 0x14 //  7     0                        46.9 kHz
	SX126X_GFSK_RX_BW_58_6       = 0x0C //  7     0                        58.6 kHz
	SX126X_GFSK_RX_BW_78_2       = 0x1B //  7     0                        78.2 kHz
	SX126X_GFSK_RX_BW_93_8       = 0x13 //  7     0                        93.8 kHz
	SX126X_GFSK_RX_BW_117_3      = 0x0B //  7     0                        117.3 kHz
	SX126X_GFSK_RX_BW_156_2      = 0x1A //  7     0                        156.2 kHz
	SX126X_GFSK_RX_BW_187_2      = 0x12 //  7     0                        187.2 kHz
	SX126X_GFSK_RX_BW_234_3      = 0x0A //  7     0                        234.3 kHz
	SX126X_GFSK_RX_BW_312_0      = 0x19 //  7     0                        312.0 kHz
	SX126X_GFSK_RX_BW_373_6      = 0x11 //  7     0                        373.6 kHz
	SX126X_GFSK_RX_BW_467_0      = 0x09 //  7     0                        467.0 kHz
	SX126X_LORA_BW_7_8           = 0x00 //  7     0     LoRa bandwidth: 7.8 kHz
	SX126X_LORA_BW_10_4          = 0x08 //  7     0                     10.4 kHz
	SX126X_LORA_BW_15_6          = 0x01 //  7     0                     15.6 kHz
	SX126X_LORA_BW_20_8          = 0x09 //  7     0                     20.8 kHz
	SX126X_LORA_BW_31_25         = 0x02 //  7     0                     31.25 kHz
	SX126X_LORA_BW_41_7          = 0x0A //  7     0                     41.7 kHz
	SX126X_LORA_BW_62_5          = 0x03 //  7     0                     62.5 kHz
	SX126X_LORA_BW_125_0         = 0x04 //  7     0                     125.0 kHz
	SX126X_LORA_BW_250_0         = 0x05 //  7     0                     250.0 kHz
	SX126X_LORA_BW_500_0         = 0x06 //  7     0                     500.0 kHz

	//SX126X_CMD_SET_PACKET_PARAMS
	SX126X_GFSK_PREAMBLE_DETECT_OFF         = 0x00 //  7     0     GFSK minimum preamble length before reception starts: detector disabled
	SX126X_GFSK_PREAMBLE_DETECT_8           = 0x04 //  7     0                                                           8 bits
	SX126X_GFSK_PREAMBLE_DETECT_16          = 0x05 //  7     0                                                           16 bits
	SX126X_GFSK_PREAMBLE_DETECT_24          = 0x06 //  7     0                                                           24 bits
	SX126X_GFSK_PREAMBLE_DETECT_32          = 0x07 //  7     0                                                           32 bits
	SX126X_GFSK_ADDRESS_FILT_OFF            = 0x00 //  7     0     GFSK address filtering: disabled
	SX126X_GFSK_ADDRESS_FILT_NODE           = 0x01 //  7     0                             node only
	SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST = 0x02 //  7     0                             node and broadcast
	SX126X_GFSK_PACKET_FIXED                = 0x00 //  7     0     GFSK packet type: fixed (payload length known in advance to both sides)
	SX126X_GFSK_PACKET_VARIABLE             = 0x01 //  7     0                       variable (payload length added to packet)
	SX126X_GFSK_CRC_OFF                     = 0x01 //  7     0     GFSK packet CRC: disabled
	SX126X_GFSK_CRC_1_BYTE                  = 0x00 //  7     0                      1 byte
	SX126X_GFSK_CRC_2_BYTE                  = 0x02 //  7     0                      2 byte
	SX126X_GFSK_CRC_1_BYTE_INV              = 0x04 //  7     0                      1 byte, inverted
	SX126X_GFSK_CRC_2_BYTE_INV              = 0x06 //  7     0                      2 byte, inverted
	SX126X_GFSK_WHITENING_OFF               = 0x00 //  7     0     GFSK data whitening: disabled
	SX126X_GFSK_WHITENING_ON                = 0x01 //  7     0                          enabled

	//SX126X_CMD_SET_CAD_PARAMS
	SX126X_CAD_ON_1_SYMB  = 0x00 //  7     0     number of symbols used for CAD: 1
	SX126X_CAD_ON_2_SYMB  = 0x01 //  7     0                                     2
	SX126X_CAD_ON_4_SYMB  = 0x02 //  7     0                                     4
	SX126X_CAD_ON_8_SYMB  = 0x03 //  7     0                                     8
	SX126X_CAD_ON_16_SYMB = 0x04 //  7     0                                     16
	SX126X_CAD_GOTO_STDBY = 0x00 //  7     0     after CAD is done, always go to STDBY_RC mode
	SX126X_CAD_GOTO_RX    = 0x01 //  7     0     after CAD is done, go to Rx mode if activity is detected

	//SX126X_CMD_GET_STATUS
	SX126X_STATUS_MODE_STDBY_RC   = 0b00100000 //  6     4     current chip mode: STDBY_RC
	SX126X_STATUS_MODE_STDBY_XOSC = 0b00110000 //  6     4                        STDBY_XOSC
	SX126X_STATUS_MODE_FS         = 0b01000000 //  6     4                        FS
	SX126X_STATUS_MODE_RX         = 0b01010000 //  6     4                        RX
	SX126X_STATUS_MODE_TX         = 0b01100000 //  6     4                        TX
	SX126X_STATUS_DATA_AVAILABLE  = 0b00000100 //  3     1     command status: packet received and data can be retrieved
	SX126X_STATUS_CMD_TIMEOUT     = 0b00000110 //  3     1                     SPI command timed out
	SX126X_STATUS_CMD_INVALID     = 0b00001000 //  3     1                     invalid SPI command
	SX126X_STATUS_CMD_FAILED      = 0b00001010 //  3     1                     SPI command failed to execute
	SX126X_STATUS_TX_DONE         = 0b00001100 //  3     1                     packet transmission done
	SX126X_STATUS_SPI_FAILED      = 0b11111111 //  7     0     SPI transaction failed

	//SX126X_CMD_GET_PACKET_STATUS
	SX126X_GFSK_RX_STATUS_PREAMBLE_ERR    = 0b10000000 //  7     7     GFSK Rx status: preamble error
	SX126X_GFSK_RX_STATUS_SYNC_ERR        = 0b01000000 //  6     6                     sync word error
	SX126X_GFSK_RX_STATUS_ADRS_ERR        = 0b00100000 //  5     5                     address error
	SX126X_GFSK_RX_STATUS_CRC_ERR         = 0b00010000 //  4     4                     CRC error
	SX126X_GFSK_RX_STATUS_LENGTH_ERR      = 0b00001000 //  3     3                     length error
	SX126X_GFSK_RX_STATUS_ABORT_ERR       = 0b00000100 //  2     2                     abort error
	SX126X_GFSK_RX_STATUS_PACKET_RECEIVED = 0b00000010 //  2     2                     packet received
	SX126X_GFSK_RX_STATUS_PACKET_SENT     = 0b00000001 //  2     2                     packet sent

	//SX126X_CMD_GET_DEVICE_ERRORS
	SX126X_PA_RAMP_ERR     = 0b100000000 //  8     8     device errors: PA ramping failed
	SX126X_PLL_LOCK_ERR    = 0b001000000 //  6     6                    PLL failed to lock
	SX126X_XOSC_START_ERR  = 0b000100000 //  5     5                    crystal oscillator failed to start
	SX126X_IMG_CALIB_ERR   = 0b000010000 //  4     4                    image calibration failed
	SX126X_ADC_CALIB_ERR   = 0b000001000 //  3     3                    ADC calibration failed
	SX126X_PLL_CALIB_ERR   = 0b000000100 //  2     2                    PLL calibration failed
	SX126X_RC13M_CALIB_ERR = 0b000000010 //  1     1                    RC13M calibration failed
	SX126X_RC64K_CALIB_ERR = 0b000000001 //  0     0                    RC64K calibration failed

	// SX126X SPI register variables
	//SX126X_REG_LORA_SYNC_WORD_MSB + LSB
	SX126X_SYNC_WORD_PUBLIC  = 0x34 // actually 0x3444  NOTE: The low nibbles in each byte (0x_4_4) are masked out since apparently, they're reserved.
	SX126X_SYNC_WORD_PRIVATE = 0x12 // actually 0x1424        You couldn't make this up if you tried.

	SX126X_LORA_MAC_PUBLIC_SYNCWORD  = 0x3444
	SX126X_LORA_MAC_PRIVATE_SYNCWORD = 0x1424
)
View Source
const (
	DEVICE_TYPE_SX1261 = iota
	DEVICE_TYPE_SX1262 = iota
	DEVICE_TYPE_SX1268 = iota
)
View Source
const (
	RFSWITCH_RX    = iota
	RFSWITCH_TX_LP = iota
	RFSWITCH_TX_HP = iota
)
View Source
const (
	PERIOD_PER_SEC      = (uint32)(1000000 / 15.625) // SX1261 DS 13.1.4
	SPI_BUFFER_SIZE     = 256
	RADIOEVENTCHAN_SIZE = 1
)
View Source
const (
	SX126X_RTC_FREQ_IN_HZ uint32 = 64000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device wraps an SPI connection to a SX126x device.

func New

func New(spi drivers.SPI) *Device

New creates a new SX126x connection.

func (*Device) Calibrate

func (d *Device) Calibrate(calibParam uint8)

Calibrate starts the calibration of a block defined by calibParam

func (*Device) CalibrateImage

func (d *Device) CalibrateImage(freq uint32)

CalibrateImage calibrates the image rejection of the device for the device operating

func (*Device) CheckDeviceReady

func (d *Device) CheckDeviceReady() error

CheckDeviceReady sleep until all busy flags clears

func (*Device) ClearDeviceErrors

func (d *Device) ClearDeviceErrors()

ClearDeviceErrors clears device Errors

func (*Device) ClearIrqStatus

func (d *Device) ClearIrqStatus(clearIrqParams uint16)

ClearIrqStatus clears IRQ flags

func (*Device) DetectDevice

func (d *Device) DetectDevice() bool

DetectDevice() tries to detect the radio module by changing SyncWord value

func (*Device) ExecGetCommand

func (d *Device) ExecGetCommand(cmd uint8, size uint8) []uint8

ExecGetCommand queries the peripheral the peripheral

func (*Device) ExecSetCommand

func (d *Device) ExecSetCommand(cmd uint8, buf []uint8)

ExecSetCommand send a command to configure the peripheral

func (*Device) GetDeviceErrors

func (d *Device) GetDeviceErrors() uint16

GetDeviceErrors returns current Device Errors

func (*Device) GetIrqStatus

func (d *Device) GetIrqStatus() (irqStatus uint16)

GetIrqStatus returns IRQ status

func (*Device) GetLoraStats

func (d *Device) GetLoraStats() (nbPktReceived, nbPktCrcError, nbPktHeaderErr uint16)

GetStats returns the number of informations received on a few last packets Lora: NbPktReceived, NbPktCrcError, NbPktHeaderErr

func (*Device) GetPacketType

func (d *Device) GetPacketType() (packetType uint8)

GetPackeType returns current Packet Type (13.4.3)

func (*Device) GetRadioEventChan

func (d *Device) GetRadioEventChan() chan lora.RadioEvent

--------------------------------------------------

Channel and events

-------------------------------------------------- Get the RadioEvent channel of the device

func (*Device) GetRxBufferStatus

func (d *Device) GetRxBufferStatus() (payloadLengthRx uint8, rxStartBufferPointer uint8)

GetRxBufferStatus returns the length of the last received packet (PayloadLengthRx) and the address of the first byte received (RxStartBufferPointer). (13.5.2)

func (*Device) GetStatus

func (d *Device) GetStatus() (radioStatus uint8)

GetStatus returns radio status(13.5.1)

func (*Device) GetSyncWord

func (d *Device) GetSyncWord() uint16

GetSyncWord gets the Sync Word to use

func (*Device) HandleInterrupt

func (d *Device) HandleInterrupt()

HandleInterrupt must be called by main code on DIO state change.

func (*Device) LoraConfig

func (d *Device) LoraConfig(cnf lora.Config)

LoraConfig() defines Lora configuration for next Lora operations

func (*Device) ReadBuffer

func (d *Device) ReadBuffer(size uint8) []uint8

ReadBuffer Reads size bytes from current buffer position

func (*Device) ReadRegister

func (d *Device) ReadRegister(addr, size uint16) ([]uint8, error)

ReadRegister reads register value

func (*Device) Reset

func (d *Device) Reset()

func (*Device) Rx

func (d *Device) Rx(timeoutMs uint32) ([]uint8, error)

LoraRx tries to receive a Lora packet (with timeout in milliseconds)

func (*Device) SetBandwidth

func (d *Device) SetBandwidth(bw uint8)

SetBandwidth() sets current Lora Bandwidth NB: Change will be applied at next RX / TX

func (*Device) SetBufferBaseAddress

func (d *Device) SetBufferBaseAddress(txBaseAddress, rxBaseAddress uint8)

SetBufferBaseAddress sets base address for buffer

func (*Device) SetCodingRate

func (d *Device) SetCodingRate(cr uint8)

SetCodingRate() sets current Lora Coding Rate NB: Change will be applied at next RX / TX

func (*Device) SetCrc

func (d *Device) SetCrc(enable bool)

SetCrc() sets current CRC mode (ON/OFF) NB: Change will be applied at next RX / TX

func (*Device) SetCurrentLimit

func (d *Device) SetCurrentLimit(limit uint8)

SetCurrentLimit sets max current in the module

func (*Device) SetDeviceType

func (d *Device) SetDeviceType(devType int)

Specify device type (SX1261/2/8)

func (*Device) SetDioIrqParams

func (d *Device) SetDioIrqParams(irqMask, dio1Mask, dio2Mask, dio3Mask uint16)

SetDioIrqParams configures DIO Irq

func (*Device) SetFrequency

func (d *Device) SetFrequency(freq uint32)

SetFrequency() Sets current Lora Frequency NB: Change will be applied at next RX / TX

func (*Device) SetFs

func (d *Device) SetFs()

SetFs sets the device in frequency synthesis mode where the PLL is locked to the carrier frequency.

func (*Device) SetHeaderType

func (d *Device) SetHeaderType(headerType uint8)

SetHeaderType sets implicit or explicit header mode NB: Change will be applied at next RX / TX

func (*Device) SetIqMode

func (d *Device) SetIqMode(mode uint8)

SetIqMode() defines the current IQ Mode (Standard/Inverted) NB: Change will be applied at next RX / TX

func (*Device) SetModulationParams

func (d *Device) SetModulationParams(spreadingFactor, bandwidth, codingRate, lowDataRateOptimize uint8)

SetModulationParams sets the Lora modulation frequency

func (*Device) SetPaConfig

func (d *Device) SetPaConfig(paDutyCycle, hpMax, deviceSel, paLut uint8)

SetPaConfig sets the Power Amplifier configuration deviceSel: 0 for SX1262, 1 for SX1261

func (*Device) SetPacketParam

func (d *Device) SetPacketParam(preambleLength uint16, headerType, crcType, payloadLength, invertIQ uint8)

SetPacketParam sets various packet-related params

func (*Device) SetPacketType

func (d *Device) SetPacketType(packetType uint8)

SetPacketType sets the packet type

func (*Device) SetPreambleLength

func (d *Device) SetPreambleLength(pl uint16)

SetPreambleLength sets current Lora Preamble Length NB: Change will be applied at next RX / TX

func (*Device) SetPublicNetwork

func (d *Device) SetPublicNetwork(enable bool)

SetPublicNetwork sets Sync Word to 0x3444 (Public) or 0x1424 (Private)

func (*Device) SetRadioController

func (d *Device) SetRadioController(rc RadioController) error

SetRadioControl let you define the RadioController

func (*Device) SetRegulatorMode

func (d *Device) SetRegulatorMode(mode uint8)

SetRegulatorMode sets the regulator more (depends on hardware implementation)

func (*Device) SetRfFrequency

func (d *Device) SetRfFrequency(frequency uint32)

SetRfFrequency sets the radio frequency

func (*Device) SetRx

func (d *Device) SetRx(timeoutRtcStep uint32)

SetRx() sets the device in RX mode timeout is expressed in RTC Step unit (15uS) Value of 0x000000 => No timeout. Rx Single mode. Value of 0xffffff => Rx Continuous mode Other values => Timeout active. The device remains in RX until countdown or packet received

func (*Device) SetRxTxFallbackMode

func (d *Device) SetRxTxFallbackMode(fallbackMode uint8)

SetRxTxFallbackMode defines into which mode the chip goes after a successful transmission or after a packet reception.

func (*Device) SetSleep

func (d *Device) SetSleep()

SetSleep sets the device in SLEEP mode with the lowest current consumption possible.

func (*Device) SetSpreadingFactor

func (d *Device) SetSpreadingFactor(sf uint8)

SetSpreadingFactor sets current Lora Spreading Factor NB: Change will be applied at next RX / TX

func (*Device) SetStandby

func (d *Device) SetStandby()

SetStandby sets the device in a configuration mode which is at an intermediate level of consumption

func (*Device) SetSyncWord

func (d *Device) SetSyncWord(sw uint16)

SetSyncWord defines the Sync Word to yse

func (*Device) SetTx

func (d *Device) SetTx(timeoutRtcStep uint32)

SetTx() sets the device in TX mode timeout is expressed in RTC Step unit (15uS) The device will stay in Tx until countdown or packet transmitted Value of 0x000000 will disable timer and device will stay TX

func (*Device) SetTxContinuousPreamble

func (d *Device) SetTxContinuousPreamble()

SetTxContinuousPreamble set device in test mode to constantly modulate LoRa preamble symbols. Take care to initialize all Lora settings like it's done in Tx before calling this function If you don't init properly all the settings, it'll fail

func (*Device) SetTxContinuousWave

func (d *Device) SetTxContinuousWave()

SetTxContinuousWave set device in test mode to generate a continuous wave (RF tone)

func (*Device) SetTxParams

func (d *Device) SetTxParams(power int8, rampTime uint8)

SetTxConfig sets power and rampup time

func (*Device) SetTxPower

func (d *Device) SetTxPower(txpow int8)

SetTxPowerDbm sets current Lora TX Power in DBm NB: Change will be applied at next RX / TX

func (*Device) StopTimerOnPreamble

func (d *Device) StopTimerOnPreamble(enable bool)

StopTimerOnPreamble allows the user to select if the timer is stopped upon preamble detection of SyncWord / header detection.

func (*Device) Tx

func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error

Tx sends a lora packet, (with timeout)

func (*Device) WriteBuffer

func (d *Device) WriteBuffer(data []uint8)

WriteBuffer write data from current buffer position

func (*Device) WriteRegister

func (d *Device) WriteRegister(addr uint16, data []uint8)

WriteRegister writes value to register

type RadioControl

type RadioControl struct {
	// contains filtered or unexported fields
}

RadioControl for boards that are connected using normal pins.

func NewRadioControl

func NewRadioControl(nssPin, busyPin, dio1Pin,
	rxPin, txLowPin, txHighPin machine.Pin) *RadioControl

func (*RadioControl) Init

func (rc *RadioControl) Init() error

Init() configures whatever needed for sx126x radio control

func (*RadioControl) SetNss

func (rc *RadioControl) SetNss(state bool) error

SetNss sets the NSS line aka chip select for SPI.

func (*RadioControl) SetRfSwitchMode

func (rc *RadioControl) SetRfSwitchMode(mode int) error

func (*RadioControl) SetupInterrupts

func (rc *RadioControl) SetupInterrupts(handler func()) error

add interrupt handler for Radio IRQs for pins

func (*RadioControl) WaitWhileBusy

func (rc *RadioControl) WaitWhileBusy() error

WaitWhileBusy wait until the radio is no longer busy

type RadioController

type RadioController interface {
	Init() error
	SetRfSwitchMode(mode int) error
	SetNss(state bool) error
	WaitWhileBusy() error
	SetupInterrupts(handler func()) error
}

SX126X radio transceiver has several pins that control RF_IN, RF_OUT, NSS, and BUSY. This interface allows the creation of struct that can drive the RF Switch (Used in Lora RX and Lora Tx)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL