rfm69

package module
v0.0.0-...-fdce910 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 rfm69 package provides a Go interface to an SPI-attached RFM69HCW module.

An RFM69HCW module on a convenient breakout board is available here or here.

rfm69hcw module

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

rfm69 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 RFM69HCW bonnet:

Function GPIO Header Pin
SPI0 SDO 10 19
SPI0 SDI 9 21
SPI0 SCLK 11 23
SPI0 CE1 7 26
RFM69 DIO0 22 15
RFM69 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
RFM69 DIO0 46 J19-5
RFM69 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 (
	RegFifo       = 0x00 // FIFO read/write access
	RegOpMode     = 0x01 // Operating modes of the transceiver
	RegDataModul  = 0x02 // Data operation mode and Modulation settings
	RegBitrateMsb = 0x03 // Bit Rate setting, Most Significant Bits
	RegBitrateLsb = 0x04 // Bit Rate setting, Least Significant Bits
	RegFdevMsb    = 0x05 // Frequency Deviation setting, Most Significant Bits
	RegFdevLsb    = 0x06 // Frequency Deviation setting, Least Significant Bits
	RegFrfMsb     = 0x07 // RF Carrier Frequency, Most Significant Bits
	RegFrfMid     = 0x08 // RF Carrier Frequency, Intermediate Bits
	RegFrfLsb     = 0x09 // RF Carrier Frequency, Least Significant Bits
	RegOsc1       = 0x0A // RF Oscillators Settings
	RegAfcCtrl    = 0x0B // AFC control in low modulation index situations
	RegListen1    = 0x0D // Listen Mode settings
	RegListen2    = 0x0E // Listen Mode Idle duration
	RegListen3    = 0x0F // Listen Mode Rx duration
	RegVersion    = 0x10
)

Common Configuration Registers

View Source
const (
	RegPaLevel = 0x11 // PA selection and Output Power control
	RegPaRamp  = 0x12 // Control of the PA ramp time in FSK mode
	RegOcp     = 0x13 // Over Current Protection control
)

Transmitter Registers

View Source
const (
	RegLna        = 0x18 // LNA settings
	RegRxBw       = 0x19 // Channel Filter BW Control
	RegAfcBw      = 0x1A // Channel Filter BW control during the AFC routine
	RegOokPeak    = 0x1B // OOK demodulator selection and control in peak mode
	RegOokAvg     = 0x1C // Average threshold control of the OOK demodulator
	RegOokFix     = 0x1D // Fixed threshold control of the OOK demodulator
	RegAfcFei     = 0x1E // AFC and FEI control and status
	RegAfcMsb     = 0x1F // MSB of the frequency correction of the AFC
	RegAfcLsb     = 0x20 // LSB of the frequency correction of the AFC
	RegFeiMsb     = 0x21 // MSB of the calculated frequency error
	RegFeiLsb     = 0x22 // LSB of the calculated frequency error
	RegRssiConfig = 0x23 // RSSI-related settings
	RegRssiValue  = 0x24 // RSSI value in dBm
)

Receiver Registers

View Source
const (
	RegDioMapping1 = 0x25 // Mapping of pins DIO0 to DIO3
	RegDioMapping2 = 0x26 // Mapping of pins DIO4 and DIO5, ClkOut frequency
	RegIrqFlags1   = 0x27 // Status register: PLL Lock state, Timeout, RSSI > Threshold...
	RegIrqFlags2   = 0x28 // Status register: FIFO handling flags...
	RegRssiThresh  = 0x29 // RSSI Threshold control
	RegRxTimeout1  = 0x2A // Timeout duration between Rx request and RSSI detection
	RegRxTimeout2  = 0x2B // Timeout duration between RSSI detection and PayloadReady
)

IRQ and Pin Mapping Registers

View Source
const (
	RegPreambleMsb   = 0x2C // Preamble length, MSB
	RegPreambleLsb   = 0x2D // Preamble length, LSB
	RegSyncConfig    = 0x2E // Sync Word Recognition control
	RegSyncValue1    = 0x2F // Sync Word bytes, 1 through 8
	RegSyncValue2    = 0x30
	RegSyncValue3    = 0x31
	RegSyncValue4    = 0x32
	RegSyncValue5    = 0x33
	RegSyncValue6    = 0x34
	RegSyncValue7    = 0x35
	RegSyncValue8    = 0x36
	RegPacketConfig1 = 0x37 // Packet mode settings
	RegPayloadLength = 0x38 // Payload length setting
	RegNodeAdrs      = 0x39 // Node address
	RegBroadcastAdrs = 0x3A // Broadcast address
	RegAutoModes     = 0x3B // Auto modes settings
	RegFifoThresh    = 0x3C // Fifo threshold, Tx start condition
	RegPacketConfig2 = 0x3D // Packet mode settings
	RegAesKey1       = 0x3E // 16 bytes of the cypher key
	RegAesKey2       = 0x3F
	RegAesKey3       = 0x40
	RegAesKey4       = 0x41
	RegAesKey5       = 0x42
	RegAesKey6       = 0x43
	RegAesKey7       = 0x44
	RegAesKey8       = 0x45
	RegAesKey9       = 0x46
	RegAesKey10      = 0x47
	RegAesKey11      = 0x48
	RegAesKey12      = 0x49
	RegAesKey13      = 0x4A
	RegAesKey14      = 0x4B
	RegAesKey15      = 0x4C
	RegAesKey16      = 0x4D
)

Packet Engine Registers

View Source
const (
	RegTemp1 = 0x4E // Temperature Sensor control
	RegTemp2 = 0x4F // Temperature readout
)

Temperature Sensor Registers

View Source
const (
	RegTest     = 0x50 // Internal test registers
	RegTestLna  = 0x58 // Sensitivity boost
	RegTestPa1  = 0x5A // High Power PA settings
	RegTestPa2  = 0x5C // High Power PA settings
	RegTestDagc = 0x6F // Fading Margin Improvement
	RegTestAfc  = 0x71 // AFC offset for low modulation index AFC
)

Test Registers

View Source
const (
	SequencerOff    = 1 << 7
	ListenOn        = 1 << 6
	ListenAbort     = 1 << 5
	ModeShift       = 2
	ModeMask        = 7 << 2
	SleepMode       = 0 << 2
	StandbyMode     = 1 << 2
	FreqSynthMode   = 2 << 2
	TransmitterMode = 3 << 2
	ReceiverMode    = 4 << 2
)

RegOpMode

View Source
const (
	PacketMode                   = 0 << 5
	ContinuousModeWithBitSync    = 2 << 5
	ContinuousModeWithoutBitSync = 3 << 5
	ModulationTypeMask           = 3 << 3
	ModulationTypeFSK            = 0 << 3
	ModulationTypeOOK            = 1 << 3
	ModulationShapingShift       = 0
)

RegDataModul

View Source
const (
	RcCalStart = 1 << 7
	RcCalDone  = 1 << 6
)

RegOsc1

View Source
const (
	ListenResolIdleShift = 6
	ListenResolRxShift   = 4
	ListenCriteria       = 1 << 3
	ListenEndShift       = 1
)

RegListen1

View Source
const (
	Pa0On            = 1 << 7
	Pa1On            = 1 << 6
	Pa2On            = 1 << 5
	OutputPowerShift = 0
)

RegPaLevel See http://blog.andrehessling.de/2015/02/07/figuring-out-the-power-level-settings-of-hoperfs-rfm69-hwhcw-modules/

View Source
const (
	OcpOn        = 1 << 4
	OcpTrimShift = 0
)

RegOcp

View Source
const (
	LnaZin              = 1 << 7
	LnaCurrentGainShift = 3
	LnaGainSelectShift  = 0
)

RegLna

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

RegRxBw

View Source
const (
	OokThreshTypeShift     = 6
	OokPeakThreshStepShift = 3
	OokPeakThreshDecShift  = 0
)

RegOokPeak

View Source
const (
	FeiDone        = 1 << 6
	FeiStart       = 1 << 5
	AfcDone        = 1 << 4
	AfcAutoclearOn = 1 << 3
	AfcAutoOn      = 1 << 2
	AfcClear       = 1 << 1
	AfcStart       = 1 << 0
)

RegAfcFei

View Source
const (
	RssiDone  = 1 << 1
	RssiStart = 1 << 0
)

RegRssiConfig

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

RegDioMapping1

View Source
const (
	Dio4MappingShift = 6
	Dio5MappingShift = 4
	ClkOutShift      = 0
)

RegDioMapping2

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

RegIrqFlags1

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

RegIrqFlags2

View Source
const (
	SyncOn            = 1 << 7
	FifoFillCondition = 1 << 6
	SyncSizeShift     = 3
	SyncTolShift      = 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 (
	EnterConditionShift        = 5
	EnterConditionNone         = 0 << 5
	EnterConditionFifoNotEmpty = 1 << 5
	EnterConditionFifoLevel    = 2 << 5
	EnterConditionCrcOk        = 3 << 5
	EnterConditionPayloadReady = 4 << 5
	EnterConditionSyncAddress  = 5 << 5
	EnterConditionPacketSent   = 6 << 5
	EnterConditionFifoEmpty    = 7 << 5
	ExitConditionShift         = 2
	ExitConditionNone          = 0 << 2
	ExitConditionFifoEmpty     = 1 << 2
	ExitConditionFifoLevel     = 2 << 2
	ExitConditionCrcOk         = 3 << 2
	ExitConditionPayloadReady  = 4 << 2
	ExitConditionSyncAddress   = 5 << 2
	ExitConditionPacketSent    = 6 << 2
	ExitConditionTimeout       = 7 << 2
	IntermediateModeShift      = 0
	IntermediateModeSleep      = 0 << 0
	IntermediateModeStandby    = 1 << 0
	IntermediateModeRx         = 2 << 0
	IntermediateModeTx         = 3 << 0
)

RegAutoModes

View Source
const (
	TxStartFifoNotEmpty = 1 << 7
	TxStartFifoLevel    = 0 << 7
	FifoThresholdShift  = 0
)

RegFifoThresh

View Source
const (
	InterPacketRxDelayShift = 4
	RestartRx               = 1 << 2
	AutoRxRestartOn         = 1 << 1
	AutoRxRestartOff        = 0 << 1
	AesOn                   = 1 << 0
)

RegPacketConfig2

View Source
const (
	TempMeasStart   = 1 << 3
	TempMeasRunning = 1 << 2
)

RegTemp1

View Source
const (
	AfcLowBetaOn = 1 << 5
)

RegAfcCtrl

View Source
const ConfigurationStart = RegOpMode

Skip RegFifo to avoid burst mode access.

View Source
const (
	OokAverageThreshFiltShift = 6
)

RegOokAvg

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.

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