rfm95

package module
v0.0.0-...-f4eac88 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 6 Imported by: 0

README

The rfm95 package provides a Go interface to an SPI-attached RFM95W module.

An RFM95W module on a convenient breakout board is available here.

rfm95 module

A Raspberry Pi add-on module with an RFM95W, OLED display, and pushbuttons is available here.

rfm95 radiofruit bonnet

Note that an antenna must be attached before using these modules.

The current version supports only OOK modulation (on-off keying) and a proprietary packet format (variable-length, null-terminated). Patches to support more general use are welcome.

Wiring

Raspberry Pi

The default configuration for ARM CPUs corresponds to the wiring of the Adafruit RFM95W bonnet:

Function GPIO Header Pin
SPI0 SDO 10 19
SPI0 SDI 9 21
SPI0 SCLK 11 23
SPI0 CE1 7 26
RFM95 DIO2 24 18
RFM95 RESET 25 22

The SPI configuration corresponds to the Linux /dev/spidev0.1 device.

Intel Edison

The default configuration for 386 CPUs assumes the following wiring:

Function GPIO Mini-Breakout Pin
SPI5 SDO 115 J17-12
SPI5 SDI 114 J18-11
SPI5 SCLK 109 J17-11
SPI5 CE1 111 J17-10
RFM95 DIO0 46 J19-5
RFM95 RESET 47 J20-5

The SPI configuration corresponds to the Linux /dev/spidev5.1 device.

Documentation

Index

Constants

View Source
const (
	// FXOSC is the radio's oscillator frequency in Hertz.
	FXOSC = 32000000

	// SPIWriteMode is used to encode register addresses for SPI writes.
	SPIWriteMode = 1 << 7
)
View Source
const (
	RegOpMode     = 0x01 // Operating mode & LoRa / FSK selection
	RegBitrateMsb = 0x02 // Bit Rate setting, Most Significant Bits
	RegBitrateLsb = 0x03 // Bit Rate setting, Least Significant Bits
	RegFdevMsb    = 0x04 // Frequency Deviation setting, Most Significant Bits
	RegFdevLsb    = 0x05 // Frequency Deviation setting, Least Significant Bits
	RegFrfMsb     = 0x06 // RF Carrier Frequency, Most Significant Bits
	RegFrfMid     = 0x07 // RF Carrier Frequency, Intermediate Bits
	RegFrfLsb     = 0x08 // RF Carrier Frequency, Least Significant Bits
)

Registers for Common settings

View Source
const (
	RegPaConfig = 0x09 // PA selection and Output Power control
	RegPaRamp   = 0x0A // Control of the PA ramp time, low phase noise PLL
	RegOcp      = 0x0B // Over Current Protection control
)

Registers for the Transmitter

View Source
const (
	RegLna            = 0x0C // LNA settings
	RegRxConfig       = 0x0D // AFC, AGC, ctrl
	RegRssiConfig     = 0x0E // RSSI
	RegRssiCollision  = 0x0F // RSSI Collision detector
	RegRssiThresh     = 0x10 // RSSI Threshold control
	RegRssiValue      = 0x11 // RSSI value in dBm
	RegRxBw           = 0x12 // Channel Filter BW Control
	RegAfcBw          = 0x13 // AFC Channel Filter BW
	RegOokPeak        = 0x14 // OOK demodulator
	RegOokFix         = 0x15 // Threshold of the OOK demodulator
	RegOokAvg         = 0x16 // Average of the OOK demodulator
	RegAfcFei         = 0x1A // AFC and FEI control
	RegAfcMsb         = 0x1B // Frequency correction value of the AFC, MSB
	RegAfcLsb         = 0x1C // Frequency correction value of the AFC, LSB
	RegFeiMsb         = 0x1D // Value of the calculated frequency error, MSB
	RegFeiLsb         = 0x1E // Value of the calculated frequency error, LSB
	RegPreambleDetect = 0x1F // Settings of the Preamble Detector
	RegRxTimeout1     = 0x20 // Timeout duration between Rx request and RSSI detection
	RegRxTimeout2     = 0x21 // Timeout duration between RSSI detection and PayloadReady
	RegRxTimeout3     = 0x22 // Timeout duration between RSSI detection and SyncAddress
	RegRxDelay        = 0x23 // Delay between Rx cycles
)

Registers for the Receiver

View Source
const (
	RegPreambleMsb   = 0x25 // Preamble length, MSB
	RegPreambleLsb   = 0x26 // Preamble length, LSB
	RegSyncConfig    = 0x27 // Sync Word Recognition control
	RegSyncValue1    = 0x28 // Sync Word bytes 1 through 8
	RegSyncValue2    = 0x29
	RegSyncValue3    = 0x2A
	RegSyncValue4    = 0x2B
	RegSyncValue5    = 0x2C
	RegSyncValue6    = 0x2D
	RegSyncValue7    = 0x2E
	RegSyncValue8    = 0x2F
	RegPacketConfig1 = 0x30 // Packet mode settings
	RegPacketConfig2 = 0x31 // Packet mode settings
	RegPayloadLength = 0x32 // Payload length setting
	RegNodeAdrs      = 0x33 // Node address
	RegBroadcastAdrs = 0x34 // Broadcast address
	RegFifoThresh    = 0x35 // Fifo threshold, Tx start condition
)

Packet Handling registers

View Source
const (
	RegSeqConfig1 = 0x36 // Top level Sequencer settings
	RegSeqConfig2 = 0x37 // Top level Sequencer settings
	RegTimerResol = 0x38 // Timer 1 and 2 resolution control
	RegTimer1Coef = 0x39 // Timer 1 setting
	RegTimer2Coef = 0x3A // Timer 2 setting
)

Sequencer registers

View Source
const (
	RegImageCal = 0x3B // Image calibration engine control
	RegTemp     = 0x3C // Temperature Sensor value
	RegLowBat   = 0x3D // Low Battery Indicator Settings
)

Service registers

View Source
const (
	RegIrqFlags1 = 0x3E // Status register: PLL Lock state, Timeout, RSSI
	RegIrqFlags2 = 0x3F // Status register: FIFO handling flags, Low Battery
)

Status registers

View Source
const (
	RegDioMapping1 = 0x40 // Mapping of pins DIO0 to DIO3
	RegDioMapping2 = 0x41 // Mapping of pins DIO4 and DIO5, ClkOut frequency
)

IO control registers

View Source
const (
	RegPllHop      = 0x44 // Control the fast frequency hopping mode
	RegTcxo        = 0x4B // TCXO or XTAL input setting
	RegPaDac       = 0x4D // Higher power settings of the PA
	RegFormerTemp  = 0x5B // Stored temperature during the former IQ Calibration
	RegBitRateFrac = 0x5D // Fractional part in the Bit Rate division ratio
	RegAgcRef      = 0x61 // Adjustment of the AGC thresholds
	RegAgcThresh1  = 0x62
	RegAgcThresh2  = 0x63
	RegAgcThresh3  = 0x64
	RegPll         = 0x70 // Control of the PLL bandwidth
)

Additional registers

View Source
const (
	FskOokMode = 0 << 7
	LoRaMode   = 1 << 7

	ModulationTypeMask = 3 << 5
	ModulationTypeFSK  = 0 << 5
	ModulationTypeOOK  = 1 << 5

	ModeMask        = 7
	SleepMode       = 0
	StandbyMode     = 1
	FreqSynthModeTX = 2
	TransmitterMode = 3
	FreqSynthModeRX = 4
	ReceiverMode    = 5
)

RegOpMode

View Source
const (
	PaBoost          = 1 << 7
	OutputPowerShift = 0
)

RegPaConfig

View Source
const (
	ModulationShapingNone   = 0 << 5
	ModulationShapingNarrow = 1 << 5
	ModulationShapingWide   = 2 << 5
	PaRamp3_4ms             = 0x0
	PaRamp2ms               = 0x1
	PaRamp1ms               = 0x2
	PaRamp500μs             = 0x3
	PaRamp250μs             = 0x4
	PaRamp125μs             = 0x5
	PaRamp100μs             = 0x6
	PaRamp62μs              = 0x7
	PaRamp50μs              = 0x8
	PaRamp40μs              = 0x9
	PaRamp31μs              = 0xA
	PaRamp25μs              = 0xB
	PaRamp20μs              = 0xC
	PaRamp15μs              = 0xD
	PaRamp12μs              = 0xE
	PaRamp10μs              = 0xF
)

RegPaRamp

View Source
const (
	LnaGainMax      = 1 << 5
	LnaGainMax_6dB  = 2 << 5
	LnaGainMax_12dB = 3 << 5
	LnaGainMax_24dB = 4 << 5
	LnaGainMax_36dB = 5 << 5
	LnaGainMax_48dB = 6 << 5
)

RegLna

View Source
const (
	AfcAutoOn         = 1 << 4
	AgcAutoOn         = 1 << 3
	RxTriggerPreamble = 6 << 0
	RxTriggerRSSI     = 1 << 0
)

RegRxConfig

View Source
const (
	RxBwMantShift = 3
	RxBwMantMask  = 3 << 3
	RxBwMant16    = 0 << 3
	RxBwMant20    = 1 << 3
	RxBwMant24    = 2 << 3
	RxBwExpShift  = 0
	RxBwExpMask   = 7 << 0
)

RegRxBw

View Source
const (
	SyncOn        = 1 << 4
	SyncSizeShift = 0
)

RegSyncConfig

View Source
const (
	FixedLength           = 0 << 7
	VariableLength        = 1 << 7
	DcFreeShift           = 5
	CrcOn                 = 1 << 4
	CrcOff                = 0 << 4
	CrcAutoClearOff       = 1 << 3
	AddressFilteringShift = 1
)

RegPacketConfig1

View Source
const (
	PacketMode           = 1 << 6
	PayloadLengthMSBMask = 7
)

RegPacketConfig2

View Source
const (
	TxStartCondition   = 1 << 7
	FifoThresholdShift = 0
)

RegFifoThresh

View Source
const (
	SequencerStart           = 1 << 7
	SequencerStop            = 1 << 6
	IdleModeStandby          = 0 << 5
	IdleModeSleep            = 1 << 5
	FromStartToLowPower      = 0 << 3
	FromStartToRX            = 1 << 3
	FromStartToTX            = 2 << 3
	FromStartToTXOnFifoLevel = 3 << 3
)

RegSeqConfig1

View Source
const (
	ModeReady        = 1 << 7
	RxReady          = 1 << 6
	TxReady          = 1 << 5
	PllLock          = 1 << 4
	Rssi             = 1 << 3
	Timeout          = 1 << 2
	PreambleDetect   = 1 << 1
	SyncAddressMatch = 1 << 0
)

RegIrqFlags1

View Source
const (
	FifoFull     = 1 << 7
	FifoEmpty    = 1 << 6
	FifoLevel    = 1 << 5
	FifoOverrun  = 1 << 4
	PacketSent   = 1 << 3
	PayloadReady = 1 << 2
	CrcOk        = 1 << 1
	LowBat       = 1 << 0
)

RegIrqFlags2

View Source
const (
	Dio0MappingShift = 6
	Dio1MappingShift = 4
	Dio2MappingShift = 2
	Dio3MappingShift = 0
)

RegDioMapping1

View Source
const (
	Dio4MappingShift  = 6
	Dio5MappingShift  = 4
	MapPreambleDetect = 1 << 0
	MapRssi           = 0 << 0
)

RegDioMapping2

View Source
const (
	PaDacDefault   = 0x04
	PaDacPlus20dBm = 0x07
)

RegPaDac

View Source
const ConfigurationStart = RegOpMode

Skip RegFifo to avoid burst mode access.

View Source
const (
	RegFifo = 0x00 // FIFO read/write access
)

FIFO

View Source
const (
	RegOsc = 0x24 // RC Oscillators Settings, CLK-OUT frequency
)

RC Oscillator registers

View Source
const (
	RegVersion = 0x42 // Hope RF ID relating the silicon revision
)

Version register

Variables

This section is empty.

Functions

func DefaultConfiguration

func DefaultConfiguration() []byte

DefaultConfiguration returns a copy of the default (recommended) values.

func ResetConfiguration

func ResetConfiguration() []byte

ResetConfiguration returns a copy of the register values after reset.

Types

type Radio

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

Radio represents an open radio device.

func Open

func Open() *Radio

Open opens the radio device.

func (*Radio) Bitrate

func (r *Radio) Bitrate() uint32

Bitrate returns the radio's bit rate, in bps.

func (*Radio) ChannelBW

func (r *Radio) ChannelBW() uint32

ChannelBW returns the radio's channel bandwidth, in Hertz.

func (*Radio) Close

func (r *Radio) Close()

Close closes the radio device.

func (*Radio) Device

func (*Radio) Device() string

Device returns the pathname of the radio's device.

func (*Radio) Error

func (r *Radio) Error() error

Error returns the error state of the radio device.

func (*Radio) Frequency

func (r *Radio) Frequency() uint32

Frequency returns the radio's current frequency, in Hertz.

func (*Radio) Hardware

func (r *Radio) Hardware() *radio.Hardware

Hardware returns the radio's hardware information.

func (*Radio) Init

func (r *Radio) Init(frequency uint32)

Init initializes the radio device.

func (*Radio) InitRF

func (r *Radio) InitRF(frequency uint32)

InitRF initializes the radio to communicate with a Medtronic insulin pump at the given frequency.

func (*Radio) Name

func (r *Radio) Name() string

Name returns the radio's name.

func (*Radio) ReadConfiguration

func (r *Radio) ReadConfiguration(useBurst bool) []byte

ReadConfiguration reads the current register configuration from the radio, using either burst-mode or individual SPI reads.

func (*Radio) ReadModulationType

func (r *Radio) ReadModulationType() byte

ReadModulationType returns the radio's modulation type.

func (*Radio) ReadRSSI

func (r *Radio) ReadRSSI() int

ReadRSSI returns the radio's RSSI, in dBm.

func (*Radio) Receive

func (r *Radio) Receive(timeout time.Duration) ([]byte, int)

Receive listens with the given timeout for an incoming packet. It returns the packet and the associated RSSI.

func (*Radio) Reset

func (r *Radio) Reset()

Reset resets the radio device. See section 7.2.2 of data sheet. NOTE: the RFM95 requires the reset pin to be in input mode except while resetting the chip, unlike the RFM69 for example.

func (*Radio) Send

func (r *Radio) Send(data []byte)

Send transmits the given packet.

func (*Radio) SendAndReceive

func (r *Radio) SendAndReceive(data []byte, timeout time.Duration) ([]byte, int)

SendAndReceive transmits the given packet, then listens with the given timeout for an incoming packet. It returns the packet and the associated RSSI. (This could be further optimized by using an Automode to go directly from TX to RX, rather than returning to standby in between.)

func (*Radio) SetBitrate

func (r *Radio) SetBitrate(br uint32)

SetBitrate sets the radio's bit rate to the given rate, in bps.

func (*Radio) SetChannelBW

func (r *Radio) SetChannelBW(bw uint32)

SetChannelBW sets the radio's channel bandwidth to the given value, in Hertz.

func (*Radio) SetError

func (r *Radio) SetError(err error)

SetError sets the error state of the radio device.

func (*Radio) SetFrequency

func (r *Radio) SetFrequency(freq uint32)

SetFrequency sets the radio to the given frequency, in Hertz.

func (*Radio) Sleep

func (r *Radio) Sleep()

Sleep puts the radio into sleep mode.

func (*Radio) State

func (r *Radio) State() string

State returns the radio's current state as a string.

func (*Radio) Version

func (r *Radio) Version() uint16

Version returns the radio's hardware version.

func (*Radio) WriteConfiguration

func (r *Radio) WriteConfiguration(config []byte, useBurst bool)

WriteConfiguration writes the given register configuration to the radio, using either burst-mode or individual SPI writes.

Directories

Path Synopsis
cmd
demo command
regtest command
rxtest command

Jump to

Keyboard shortcuts

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