sx127x

package
v0.0.0-...-0087ba1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

README

SX127x LoRa Radio

This processor comes in several different packages.

Adafruit LoRa Radio Featherwing

https://www.adafruit.com/product/3231

This is the LoRa 9x @ 900 MHz radio version, which can be used for either 868MHz or 915MHz transmission/reception - the exact radio frequency is determined when you load the software since it can be tuned around dynamically. They can easily go 2 Km line of sight using simple wire antennas, or up to 20Km with directional antennas and settings tweaks.

Connecting

To use the LoRa Featherwing with a Pybadge/Gobadge, you need to connect some pads on the board itself. Solder some jumper wires as follows:

RST -> A CS -> B DIO1 -> C IRQ -> D

You also need to connect an antenna. The easiest is to cut a small piece of wire to the correct length based on the desired frequency:

EU868 Mhz - 34.54 cm

You can also use a fancier solution such as a uFL SMA connector with matching antenna.

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

View Source
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
)
View Source
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 New

func New(spi machine.SPI, rstPin machine.Pin) *Device

New creates a new SX127x connection. The SPI bus must already be configured.

func (*Device) DetectDevice

func (d *Device) DetectDevice() bool

DetectDevice checks if device responds on the SPI bus

func (*Device) GetRSSI

func (d *Device) GetRSSI() uint8

GetRSSI returns current RSSI

func (*Device) GetRadioEventChan

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

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

Channel and events

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

func (*Device) GetVersion

func (d *Device) GetVersion() uint8

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

func (d *Device) IsTransmitting() bool

IsTransmitting tests if a packet transmission is in progress

func (*Device) LastPacketRSSI

func (d *Device) LastPacketRSSI() uint8

LastPacketRSSI gives the RSSI of the last packet received

func (*Device) LastPacketSNR

func (d *Device) LastPacketSNR() uint8

LastPacketSNR gives the SNR of the last packet received

func (*Device) LoraConfig

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

LoraConfig() defines Lora configuration for next Lora operations

func (*Device) PrintRegisters

func (d *Device) PrintRegisters(compact bool)

PrintRegisters outputs the sx127x transceiver registers

func (*Device) RandomU32

func (d *Device) RandomU32() uint32

PrintRegisters outputs the sx127x transceiver registers

func (*Device) ReadRegister

func (d *Device) ReadRegister(reg uint8) uint8

ReadRegister reads register value

func (*Device) Reset

func (d *Device) Reset()

Reset re-initialize the sx127x device

func (*Device) Rx

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

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

func (*Device) SetAgcAuto

func (d *Device) SetAgcAuto(val uint8)

SetAgcAutoOn enables Automatic Gain Control

func (*Device) SetBandwidth

func (d *Device) SetBandwidth(bw uint8)

SetBandwidth updates the bandwidth the LoRa module is using

func (*Device) SetCodingRate

func (d *Device) SetCodingRate(cr uint8)

SetCodingRate updates the coding rate the LoRa module is using

func (*Device) SetCrc

func (d *Device) SetCrc(enable bool)

SetCrc Enable CRC generation and check on payload

func (*Device) SetFrequency

func (d *Device) SetFrequency(frequency uint32)

SetFrequency updates the frequency the LoRa module is using

func (*Device) SetHeaderType

func (d *Device) SetHeaderType(headerType uint8)

SetHeaderType set implicit or explicit mode

func (*Device) SetHopPeriod

func (d *Device) SetHopPeriod(val uint8)

SetHopPeriod sets number of symbol periods between frequency hops. (0 = disabled).

func (*Device) SetIqMode

func (d *Device) SetIqMode(val uint8)

SetIQMode Sets I/Q polarity configuration

func (*Device) SetLowDataRateOptim

func (d *Device) SetLowDataRateOptim(val uint8)

SetLowDataRateOptimize enables Low Data Rate Optimization

func (*Device) SetLowFrequencyModeOn

func (d *Device) SetLowFrequencyModeOn(val bool)

SetLowFrequencyModeOn enables Low Data Rate Optimization

func (*Device) SetOCP

func (d *Device) SetOCP(mA uint8)

SetOCP defines Overload Current Protection configuration

func (*Device) SetOpMode

func (d *Device) SetOpMode(mode uint8)

SetOpMode changes the sx1276 mode

func (*Device) SetOpModeLora

func (d *Device) SetOpModeLora()

SetOpMode changes the sx1276 mode

func (*Device) SetPreambleLength

func (d *Device) SetPreambleLength(pLen uint16)

SetPreambleLength defines number of preamble

func (*Device) SetPublicNetwork

func (d *Device) SetPublicNetwork(enabled bool)

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

func (d *Device) SetRxTimeout(tmoutSymb uint8)

SetRxTimeout defines RX Timeout expressed as number of symbols Default timeout is 64 * Ts

func (*Device) SetSpreadingFactor

func (d *Device) SetSpreadingFactor(sf uint8)

SetSpreadingFactor changes spreading factor

func (*Device) SetSyncWord

func (d *Device) SetSyncWord(syncWord uint16)

SetSyncWord defines sync word

func (*Device) SetTxContinuousMode

func (d *Device) SetTxContinuousMode(val bool)

SetTxContinuousMode enable Continuous Tx mode

func (*Device) SetTxPower

func (d *Device) SetTxPower(txPower int8)

SetTxPower sets the transmitter output (with paBoost ON)

func (*Device) SetTxPowerWithPaBoost

func (d *Device) SetTxPowerWithPaBoost(txPower int8, paBoost bool)

SetTxPowerWithPaBoost sets the transmitter output power and may activate paBoost

func (*Device) Tx

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

Tx sends a lora packet, (with timeout)

func (*Device) WriteRegister

func (d *Device) WriteRegister(reg uint8, value uint8) 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, 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

Jump to

Keyboard shortcuts

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