Documentation ¶
Overview ¶
Package sx127x provides a driver for SX127x LoRa transceivers. References: https://electronics.stackexchange.com/questions/394296/can-t-get-simple-lora-receiver-to-work https://www.st.com/resource/en/user_manual/dm00300436-stm32-lora-expansion-package-for-stm32cube-stmicroelectronics.pdf
Index ¶
- Constants
- type Device
- func (d *Device) DetectDevice() bool
- func (d *Device) GetRSSI() uint8
- func (d *Device) GetRadioEventChan() chan lora.RadioEvent
- func (d *Device) GetVersion() uint8
- func (d *Device) HandleInterrupt()
- func (d *Device) IsTransmitting() bool
- func (d *Device) LastPacketRSSI() uint8
- func (d *Device) LastPacketSNR() uint8
- func (d *Device) LoraConfig(cnf lora.Config)
- func (d *Device) PrintRegisters(compact bool)
- func (d *Device) RandomU32() uint32
- func (d *Device) ReadRegister(reg uint8) uint8
- func (d *Device) Reset()
- func (d *Device) Rx(timeoutMs uint32) ([]uint8, error)
- func (d *Device) SetAgcAuto(val uint8)
- func (d *Device) SetBandwidth(bw uint8)
- func (d *Device) SetCodingRate(cr uint8)
- func (d *Device) SetCrc(enable bool)
- func (d *Device) SetFrequency(frequency uint32)
- func (d *Device) SetHeaderType(headerType uint8)
- func (d *Device) SetHopPeriod(val uint8)
- func (d *Device) SetIqMode(val uint8)
- func (d *Device) SetLowDataRateOptim(val uint8)
- func (d *Device) SetLowFrequencyModeOn(val bool)
- func (d *Device) SetOCP(mA uint8)
- func (d *Device) SetOpMode(mode uint8)
- func (d *Device) SetOpModeLora()
- func (d *Device) SetPreambleLength(pLen uint16)
- func (d *Device) SetPublicNetwork(enabled bool)
- func (d *Device) SetRadioController(rc RadioController) error
- func (d *Device) SetRxTimeout(tmoutSymb uint8)
- func (d *Device) SetSpreadingFactor(sf uint8)
- func (d *Device) SetSyncWord(syncWord uint16)
- func (d *Device) SetTxContinuousMode(val bool)
- func (d *Device) SetTxPower(txPower int8)
- func (d *Device) SetTxPowerWithPaBoost(txPower int8, paBoost bool)
- func (d *Device) Tx(pkt []uint8, timeoutMs uint32) error
- func (d *Device) WriteRegister(reg uint8, value uint8) uint8
- type RadioControl
- type RadioController
Constants ¶
const ( // registers SX127X_REG_FIFO = 0x00 SX127X_REG_OP_MODE = 0x01 SX127X_REG_FRF_MSB = 0x06 SX127X_REG_FRF_MID = 0x07 SX127X_REG_FRF_LSB = 0x08 SX127X_REG_PA_CONFIG = 0x09 SX127X_REG_PA_RAMP = 0x0a SX127X_REG_OCP = 0x0b SX127X_REG_LNA = 0x0c SX127X_REG_FIFO_ADDR_PTR = 0x0d SX127X_REG_FIFO_TX_BASE_ADDR = 0x0e SX127X_REG_FIFO_RX_BASE_ADDR = 0x0f SX127X_REG_FIFO_RX_CURRENT_ADDR = 0x10 SX127X_REG_IRQ_FLAGS_MASK = 0x11 SX127X_REG_IRQ_FLAGS = 0x12 SX127X_REG_RX_NB_BYTES = 0x13 SX127X_REG_PKT_SNR_VALUE = 0x19 SX127X_REG_PKT_RSSI_VALUE = 0x1a SX127X_REG_RSSI_VALUE = 0x1b SX127X_REG_MODEM_CONFIG_1 = 0x1d SX127X_REG_MODEM_CONFIG_2 = 0x1e SX127X_REG_SYMB_TIMEOUT_LSB = 0x1f SX127X_REG_PREAMBLE_MSB = 0x20 SX127X_REG_PREAMBLE_LSB = 0x21 SX127X_REG_PAYLOAD_LENGTH = 0x22 SX127X_REG_MAX_PAYLOAD_LENGTH = 0x23 SX127X_REG_HOP_PERIOD = 0x24 SX127X_REG_MODEM_CONFIG_3 = 0x26 SX127X_REG_FREQ_ERROR_MSB = 0x28 SX127X_REG_FREQ_ERROR_MID = 0x29 SX127X_REG_FREQ_ERROR_LSB = 0x2a SX127X_REG_RSSI_WIDEBAND = 0x2c SX127X_REG_DETECTION_OPTIMIZE = 0x31 SX127X_REG_INVERTIQ = 0x33 SX127X_REG_DETECTION_THRESHOLD = 0x37 SX127X_REG_SYNC_WORD = 0x39 SX127X_REG_INVERTIQ2 = 0x3b SX127X_REG_DIO_MAPPING_1 = 0x40 SX127X_REG_DIO_MAPPING_2 = 0x41 SX127X_REG_VERSION = 0x42 SX127X_REG_PA_DAC = 0x4d // PA config SX127X_PA_BOOST = 0x80 // Bits masking the corresponding IRQs from the radio SX127X_IRQ_LORA_RXTOUT_MASK = uint8(0x80) SX127X_IRQ_LORA_RXDONE_MASK = uint8(0x40) SX127X_IRQ_LORA_CRCERR_MASK = uint8(0x20) SX127X_IRQ_LORA_HEADER_MASK = uint8(0x10) SX127X_IRQ_LORA_TXDONE_MASK = uint8(0x08) SX127X_IRQ_LORA_CDDONE_MASK = uint8(0x04) SX127X_IRQ_LORA_FHSSCH_MASK = uint8(0x02) SX127X_IRQ_LORA_CDDETD_MASK = uint8(0x01) // DIO function mappings D0D1D2D3 SX127X_MAP_DIO0_LORA_RXDONE = uint8(0x00) // 00------ SX127X_MAP_DIO0_LORA_TXDONE = uint8(0x40) // 01------ SX127X_MAP_DIO1_LORA_RXTOUT = uint8(0x00) // --00---- SX127X_MAP_DIO1_LORA_NOP = uint8(0x30) // --11---- SX127X_MAP_DIO2_LORA_NOP = uint8(0xC0) // ----11-- SX127X_PAYLOAD_LENGTH = uint8(0x40) // Low Noise Amp SX127X_LNA_MAX_GAIN = uint8(0x23) SX127X_LNA_OFF_GAIN = uint8(0x00) SX127X_LNA_LOW_GAIN = uint8(0x20) // Bandwidth SX127X_LORA_BW_7_8 = uint8(0x00) SX127X_LORA_BW_10_4 = uint8(0x01) SX127X_LORA_BW_15_6 = uint8(0x02) SX127X_LORA_BW_20_8 = uint8(0x03) SX127X_LORA_BW_31_25 = uint8(0x04) SX127X_LORA_BW_41_7 = uint8(0x05) SX127X_LORA_BW_62_5 = uint8(0x06) SX127X_LORA_BW_125_0 = uint8(0x07) SX127X_LORA_BW_250_0 = uint8(0x08) SX127X_LORA_BW_500_0 = uint8(0x09) // Automatic gain control SX127X_AGC_AUTO_OFF = uint8(0x00) SX127X_AGC_AUTO_ON = uint8(0x01) // Operation modes SX127X_OPMODE_LORA = uint8(0x80) SX127X_OPMODE_MASK = uint8(0x07) SX127X_OPMODE_SLEEP = uint8(0x00) SX127X_OPMODE_STANDBY = uint8(0x01) SX127X_OPMODE_FSTX = uint8(0x02) SX127X_OPMODE_TX = uint8(0x03) SX127X_OPMODE_FSRX = uint8(0x04) SX127X_OPMODE_RX = uint8(0x05) SX127X_OPMODE_RX_SINGLE = uint8(0x06) SX127X_OPMODE_CAD = uint8(0x07) SX127X_LORA_MAC_PUBLIC_SYNCWORD = 0x34 SX127X_LORA_MAC_PRIVATE_SYNCWORD = 0x14 )
const ( RADIOEVENTCHAN_SIZE = 1 SPI_BUFFER_SIZE = 5 )
So we can keep track of the origin of interruption
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 SX127x device.
func (*Device) DetectDevice ¶
DetectDevice checks if device responds on the SPI bus
func (*Device) GetRadioEventChan ¶
func (d *Device) GetRadioEventChan() chan lora.RadioEvent
--------------------------------------------------
Channel and events
-------------------------------------------------- Get the RadioEvent channel of the device
func (*Device) GetVersion ¶
GetVersion returns hardware version of sx1276 chipset
func (*Device) HandleInterrupt ¶
func (d *Device) HandleInterrupt()
HandleInterrupt must be called by main code on DIO state change.
func (*Device) IsTransmitting ¶
IsTransmitting tests if a packet transmission is in progress
func (*Device) LastPacketRSSI ¶
LastPacketRSSI gives the RSSI of the last packet received
func (*Device) LastPacketSNR ¶
LastPacketSNR gives the SNR of the last packet received
func (*Device) LoraConfig ¶
LoraConfig() defines Lora configuration for next Lora operations
func (*Device) PrintRegisters ¶
PrintRegisters outputs the sx127x transceiver registers
func (*Device) ReadRegister ¶
ReadRegister reads register value
func (*Device) SetAgcAuto ¶
SetAgcAutoOn enables Automatic Gain Control
func (*Device) SetBandwidth ¶
SetBandwidth updates the bandwidth the LoRa module is using
func (*Device) SetCodingRate ¶
SetCodingRate updates the coding rate the LoRa module is using
func (*Device) SetFrequency ¶
SetFrequency updates the frequency the LoRa module is using
func (*Device) SetHeaderType ¶
SetHeaderType set implicit or explicit mode
func (*Device) SetHopPeriod ¶
SetHopPeriod sets number of symbol periods between frequency hops. (0 = disabled).
func (*Device) SetLowDataRateOptim ¶
SetLowDataRateOptimize enables Low Data Rate Optimization
func (*Device) SetLowFrequencyModeOn ¶
SetLowFrequencyModeOn enables Low Data Rate Optimization
func (*Device) SetPreambleLength ¶
SetPreambleLength defines number of preamble
func (*Device) SetPublicNetwork ¶
SetPublicNetwork changes Sync Word to match network type
func (*Device) SetRadioController ¶
func (d *Device) SetRadioController(rc RadioController) error
SetRadioControl let you define the RadioController
func (*Device) SetRxTimeout ¶
SetRxTimeout defines RX Timeout expressed as number of symbols Default timeout is 64 * Ts
func (*Device) SetSpreadingFactor ¶
SetSpreadingFactor changes spreading factor
func (*Device) SetSyncWord ¶
SetSyncWord defines sync word
func (*Device) SetTxContinuousMode ¶
SetTxContinuousMode enable Continuous Tx mode
func (*Device) SetTxPower ¶
SetTxPower sets the transmitter output (with paBoost ON)
func (*Device) SetTxPowerWithPaBoost ¶
SetTxPowerWithPaBoost sets the transmitter output power and may activate paBoost
type RadioControl ¶
type RadioControl struct {
// contains filtered or unexported fields
}
RadioControl for boards that are connected using normal pins.
func NewRadioControl ¶
func NewRadioControl(nssPin, dio0Pin, dio1Pin machine.Pin) *RadioControl
func (*RadioControl) Init ¶
func (rc *RadioControl) Init() error
Init() configures whatever needed for sx127x radio control
func (*RadioControl) SetNss ¶
func (rc *RadioControl) SetNss(state bool) error
SetNss sets the NSS line aka chip select for SPI.
func (*RadioControl) SetupInterrupts ¶
func (rc *RadioControl) SetupInterrupts(handler func()) error
add interrupt handlers for Radio IRQs for pins
type RadioController ¶
type RadioController interface { Init() error SetNss(state bool) error SetupInterrupts(handler func()) error }
SX127X radio transceiver has several pins that control NSS, and that are signalled when RX or TX operations are completed. This interface allows the creation of types that can control this