ClusterDuck Protocol
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SX127x Class Referenceabstract

Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes. More...

#include <SX127x.h>

Inheritance diagram for SX127x:
PhysicalLayer SX1272 SX1278 SX1273 RFM95 RFM96 SX1276 SX1277 SX1279 RFM97

Public Member Functions

 SX127x (Module *mod)
 Default constructor. Called internally when creating new LoRa instance. More...
 
int16_t begin (uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength)
 Initialization method. Will be called with appropriate parameters when calling initialization method from derived class. More...
 
virtual void reset ()=0
 Reset method. Will reset the chip to the default state using RST pin. Declared pure virtual since SX1272 and SX1278 implmentations differ.
 
int16_t beginFSK (uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit, uint16_t preambleLength, bool enableOOK)
 Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class. More...
 
int16_t transmit (uint8_t *data, size_t len, uint8_t addr=0)
 Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit. More...
 
int16_t receive (uint8_t *data, size_t len)
 Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to receive Arduino String, see PhysicalLayer::receive. More...
 
int16_t scanChannel ()
 Performs scan for valid LoRa preamble in the current channel. More...
 
int16_t sleep ()
 Sets the LoRa module to sleep to save power. Module will not be able to transmit or receive any data while in sleep mode. Module will wake up automatically when methods like transmit or receive are called. More...
 
int16_t standby ()
 Sets the LoRa module to standby. More...
 
int16_t transmitDirect (uint32_t FRF=0)
 Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. More...
 
int16_t receiveDirect ()
 Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode. More...
 
int16_t packetMode ()
 Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode. More...
 
void setDio0Action (void(*func)(void))
 Set interrupt service routine function to call when DIO0 activates. More...
 
void clearDio0Action ()
 Clears interrupt service routine to call when DIO0 activates.
 
void setDio1Action (void(*func)(void))
 Set interrupt service routine function to call when DIO1 activates. More...
 
void clearDio1Action ()
 Clears interrupt service routine to call when DIO1 activates.
 
int16_t startTransmit (uint8_t *data, size_t len, uint8_t addr=0)
 Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. More...
 
int16_t startReceive (uint8_t len=0, uint8_t mode=SX127X_RXCONTINUOUS)
 Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. More...
 
int16_t readData (uint8_t *data, size_t len)
 Reads data that was received after calling startReceive method. This method reads len characters. More...
 
int16_t setSyncWord (uint8_t syncWord)
 Sets LoRa sync word. Only available in LoRa mode. More...
 
int16_t setCurrentLimit (uint8_t currentLimit)
 Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps. More...
 
int16_t setPreambleLength (uint16_t preambleLength)
 Sets LoRa preamble length. Allowed values range from 6 to 65535. Only available in LoRa mode. More...
 
float getFrequencyError (bool autoCorrect=false)
 Gets frequency error of the latest received packet. More...
 
float getSNR ()
 Gets signal-to-noise ratio of the latest received packet. More...
 
float getDataRate ()
 Get data rate of the latest transmitted packet. More...
 
int16_t setBitRate (float br)
 Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode. More...
 
int16_t setFrequencyDeviation (float freqDev)
 Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode. More...
 
int16_t setRxBandwidth (float rxBw)
 Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. More...
 
int16_t setSyncWord (uint8_t *syncWord, size_t len)
 Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not contain null bytes. Only available in FSK mode. More...
 
int16_t setNodeAddress (uint8_t nodeAddr)
 Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode. More...
 
int16_t setBroadcastAddress (uint8_t broadAddr)
 Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode. More...
 
int16_t disableAddressFiltering ()
 Disables FSK address filtering. More...
 
int16_t setOOK (bool enableOOK)
 Enables/disables OOK modulation instead of FSK. More...
 
size_t getPacketLength (bool update=true)
 Query modem for the packet length of received payload. More...
 
int16_t fixedPacketLengthMode (uint8_t len=SX127X_MAX_PACKET_LENGTH_FSK)
 Set modem in fixed packet length mode. Available in FSK mode only. More...
 
int16_t variablePacketLengthMode (uint8_t maxLen=SX127X_MAX_PACKET_LENGTH_FSK)
 Set modem in variable packet length mode. Available in FSK mode only. More...
 
int16_t setRSSIConfig (uint8_t smoothingSamples, int8_t offset=0)
 Sets RSSI measurement configuration in FSK mode. More...
 
int16_t setEncoding (uint8_t encoding)
 Sets transmission encoding. Only available in FSK mode. More...
 
void regDump ()
 
int16_t transmit (__FlashStringHelper *fstr, uint8_t addr=0)
 Arduino Flash String transmit method. More...
 
int16_t transmit (String &str, uint8_t addr=0)
 Arduino String transmit method. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
virtual int16_t transmit (uint8_t *data, size_t len, uint8_t addr=0)=0
 Binary transmit method. Must be implemented in module class. More...
 
int16_t receive (String &str, size_t len=0)
 Arduino String receive method. More...
 
virtual int16_t receive (uint8_t *data, size_t len)=0
 Binary receive method. Must be implemented in module class. More...
 
int16_t startTransmit (String &str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
virtual int16_t startTransmit (uint8_t *data, size_t len, uint8_t addr=0)=0
 Interrupt-driven binary transmit method. More...
 
int16_t readData (String &str, size_t len=0)
 Reads data that was received after calling startReceive method. More...
 
virtual int16_t readData (uint8_t *data, size_t len)=0
 Reads data that was received after calling startReceive method. More...
 
- Public Member Functions inherited from PhysicalLayer
 PhysicalLayer (float freqStep, size_t maxPacketLength)
 Default constructor. More...
 
int16_t transmit (__FlashStringHelper *fstr, uint8_t addr=0)
 Arduino Flash String transmit method. More...
 
int16_t transmit (String &str, uint8_t addr=0)
 Arduino String transmit method. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
int16_t receive (String &str, size_t len=0)
 Arduino String receive method. More...
 
int16_t startTransmit (String &str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t startTransmit (const char *str, uint8_t addr=0)
 Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes. More...
 
int16_t readData (String &str, size_t len=0)
 Reads data that was received after calling startReceive method. More...
 
virtual int16_t setDataShaping (float sh)=0
 Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class. More...
 
float getFreqStep ()
 Gets the module frequency step size that was set in constructor. More...
 

Protected Member Functions

int16_t setFrequencyRaw (float newFreq)
 
int16_t config ()
 
int16_t configFSK ()
 
int16_t getActiveModem ()
 
int16_t directMode ()
 
int16_t setPacketMode (uint8_t mode, uint8_t len)
 

Protected Attributes

Module_mod
 
float _freq
 
float _bw
 
uint8_t _sf
 
uint8_t _cr
 
float _br
 
float _rxBw
 
bool _ook
 

Detailed Description

Base class for SX127x series. All derived classes for SX127x (e.g. SX1278 or SX1272) inherit from this base class. This class should not be instantiated directly from Arduino sketch, only from its derived classes.

Constructor & Destructor Documentation

◆ SX127x()

SX127x::SX127x ( Module mod)

Default constructor. Called internally when creating new LoRa instance.

Parameters
modInstance of Module that will be used to communicate with the LoRa chip.

Member Function Documentation

◆ begin()

int16_t SX127x::begin ( uint8_t  chipVersion,
uint8_t  syncWord,
uint8_t  currentLimit,
uint16_t  preambleLength 
)

Initialization method. Will be called with appropriate parameters when calling initialization method from derived class.

Parameters
chipVersionValue in SPI version register. Used to verify the connection and hardware version.
syncWordLoRa sync word.
currentLimitTrim value for OCP (over current protection) in mA.
preambleLengthLength of LoRa transmission preamble in symbols.
Returns
Status Codes

◆ beginFSK()

int16_t SX127x::beginFSK ( uint8_t  chipVersion,
float  br,
float  freqDev,
float  rxBw,
uint8_t  currentLimit,
uint16_t  preambleLength,
bool  enableOOK 
)

Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class.

Parameters
chipVersionValue in SPI version register. Used to verify the connection and hardware version.
brBit rate of the FSK transmission in kbps (kilobits per second).
freqDevFrequency deviation of the FSK transmission in kHz.
rxBwReceiver bandwidth in kHz.
currentLimitTrim value for OCP (over current protection) in mA.
preambleLengthLength of FSK preamble in bits.
enableOOKFlag to specify OOK mode. This modulation is similar to FSK.
Returns
Status Codes

◆ disableAddressFiltering()

int16_t SX127x::disableAddressFiltering ( )

Disables FSK address filtering.

Returns
Status Codes

◆ fixedPacketLengthMode()

int16_t SX127x::fixedPacketLengthMode ( uint8_t  len = SX127X_MAX_PACKET_LENGTH_FSK)

Set modem in fixed packet length mode. Available in FSK mode only.

Parameters
lenPacket length.
Returns
Status Codes

◆ getDataRate()

float SX127x::getDataRate ( )

Get data rate of the latest transmitted packet.

Returns
Last packet data rate in bps (bits per second).

◆ getFrequencyError()

float SX127x::getFrequencyError ( bool  autoCorrect = false)

Gets frequency error of the latest received packet.

Parameters
autoCorrectWhen set to true, frequency will be automatically corrected.
Returns
Frequency error in Hz.

◆ getPacketLength()

size_t SX127x::getPacketLength ( bool  update = true)
virtual

Query modem for the packet length of received payload.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
Returns
Length of last received packet in bytes.

Implements PhysicalLayer.

◆ getSNR()

float SX127x::getSNR ( )

Gets signal-to-noise ratio of the latest received packet.

Returns
Last packet signal-to-noise ratio (SNR).

◆ packetMode()

int16_t SX127x::packetMode ( )

Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode.

Returns
Status Codes

◆ readData() [1/3]

int16_t PhysicalLayer::readData

Reads data that was received after calling startReceive method.

Parameters
strAddress of Arduino String to save the received data.
lenExpected number of characters in the message.
Returns
Status Codes

◆ readData() [2/3]

int16_t SX127x::readData ( uint8_t *  data,
size_t  len 
)
virtual

Reads data that was received after calling startReceive method. This method reads len characters.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

Implements PhysicalLayer.

◆ readData() [3/3]

virtual int16_t PhysicalLayer::readData

Reads data that was received after calling startReceive method.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

◆ receive() [1/3]

int16_t PhysicalLayer::receive

Arduino String receive method.

Parameters
strAddress of Arduino String to save the received data.
lenExpected number of characters in the message. Leave as 0 if expecting a unknown size packet
Returns
Status Codes

◆ receive() [2/3]

int16_t SX127x::receive ( uint8_t *  data,
size_t  len 
)
virtual

Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to receive Arduino String, see PhysicalLayer::receive.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

Implements PhysicalLayer.

◆ receive() [3/3]

virtual int16_t PhysicalLayer::receive

Binary receive method. Must be implemented in module class.

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be received. Must be known in advance for binary transmissions.
Returns
Status Codes

◆ receiveDirect()

int16_t SX127x::receiveDirect ( )
virtual

Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.

Returns
Status Codes

Implements PhysicalLayer.

◆ scanChannel()

int16_t SX127x::scanChannel ( )

Performs scan for valid LoRa preamble in the current channel.

Returns
Status Codes

◆ setBitRate()

int16_t SX127x::setBitRate ( float  br)

Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode.

Parameters
brBit rate to be set (in kbps).
Returns
Status Codes

◆ setBroadcastAddress()

int16_t SX127x::setBroadcastAddress ( uint8_t  broadAddr)

Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode.

Parameters
broadAddrBroadcast address to be set.
Returns
Status Codes

◆ setCurrentLimit()

int16_t SX127x::setCurrentLimit ( uint8_t  currentLimit)

Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps.

Parameters
currentLimitCurrent limit to be set (in mA).
Returns
Status Codes

◆ setDio0Action()

void SX127x::setDio0Action ( void(*)(void)  func)

Set interrupt service routine function to call when DIO0 activates.

Parameters
funcPointer to interrupt service routine.

◆ setDio1Action()

void SX127x::setDio1Action ( void(*)(void)  func)

Set interrupt service routine function to call when DIO1 activates.

Parameters
funcPointer to interrupt service routine.

◆ setEncoding()

int16_t SX127x::setEncoding ( uint8_t  encoding)
virtual

Sets transmission encoding. Only available in FSK mode.

Parameters
encodingEncoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening.
Returns
Status Codes

Implements PhysicalLayer.

◆ setFrequencyDeviation()

int16_t SX127x::setFrequencyDeviation ( float  freqDev)
virtual

Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode.

Parameters
freqDevFrequency deviation to be set (in kHz).
Returns
Status Codes

Implements PhysicalLayer.

◆ setNodeAddress()

int16_t SX127x::setNodeAddress ( uint8_t  nodeAddr)

Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode.

Parameters
nodeAddrNode address to be set.
Returns
Status Codes

◆ setOOK()

int16_t SX127x::setOOK ( bool  enableOOK)

Enables/disables OOK modulation instead of FSK.

Parameters
enableOOKEnable (true) or disable (false) OOK.
Returns
Status Codes

◆ setPreambleLength()

int16_t SX127x::setPreambleLength ( uint16_t  preambleLength)

Sets LoRa preamble length. Allowed values range from 6 to 65535. Only available in LoRa mode.

Parameters
preambleLengthPreamble length to be set (in symbols).
Returns
Status Codes

◆ setRSSIConfig()

int16_t SX127x::setRSSIConfig ( uint8_t  smoothingSamples,
int8_t  offset = 0 
)

Sets RSSI measurement configuration in FSK mode.

Parameters
smoothingSamplesNumber of samples taken to avergae the RSSI result. numSamples = 2 ^ (1 + smoothingSamples), allowed values are in range 0 (2 samples) - 7 (256 samples)
offsetSigned RSSI offset that will be automatically compensated. 1 dB per LSB, defaults to 0, allowed values are in range -16 dB to +15 dB.
Returns
Status Codes

◆ setRxBandwidth()

int16_t SX127x::setRxBandwidth ( float  rxBw)

Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode.

Parameters
rxBwReceiver bandwidth to be set (in kHz).
Returns
Status Codes

◆ setSyncWord() [1/2]

int16_t SX127x::setSyncWord ( uint8_t *  syncWord,
size_t  len 
)

Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not contain null bytes. Only available in FSK mode.

Parameters
syncWordSync word array.
lenSync word length (in bytes).
Returns
Status Codes

◆ setSyncWord() [2/2]

int16_t SX127x::setSyncWord ( uint8_t  syncWord)

Sets LoRa sync word. Only available in LoRa mode.

Parameters
syncWordSync word to be set.
Returns
Status Codes

◆ sleep()

int16_t SX127x::sleep ( )

Sets the LoRa module to sleep to save power. Module will not be able to transmit or receive any data while in sleep mode. Module will wake up automatically when methods like transmit or receive are called.

Returns
Status Codes

◆ standby()

int16_t SX127x::standby ( )
virtual

Sets the LoRa module to standby.

Returns
Status Codes

Implements PhysicalLayer.

◆ startReceive()

int16_t SX127x::startReceive ( uint8_t  len = 0,
uint8_t  mode = SX127X_RXCONTINUOUS 
)

Interrupt-driven receive method. DIO0 will be activated when full valid packet is received.

Parameters
lenExpected length of packet to be received. Required for LoRa spreading factor 6.
modeReceive mode to be used. Defaults to RxContinuous.
Returns
Status Codes

◆ startTransmit() [1/4]

int16_t PhysicalLayer::startTransmit

Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ startTransmit() [2/4]

int16_t PhysicalLayer::startTransmit

Interrupt-driven Arduino String transmit method. Unlike the standard transmit method, this one is non-blocking. Interrupt pin will be activated when transmission finishes.

Parameters
strAddress of Arduino String that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ startTransmit() [3/4]

int16_t SX127x::startTransmit ( uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
virtual

Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

Implements PhysicalLayer.

◆ startTransmit() [4/4]

virtual int16_t PhysicalLayer::startTransmit

Interrupt-driven binary transmit method.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [1/5]

int16_t PhysicalLayer::transmit

Arduino Flash String transmit method.

Parameters
strPointer to Arduino Flash String that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [2/5]

int16_t PhysicalLayer::transmit

C-string transmit method.

Parameters
strC-string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [3/5]

int16_t PhysicalLayer::transmit

Arduino String transmit method.

Parameters
strAddress of Arduino string that will be transmitted.
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmit() [4/5]

int16_t SX127x::transmit ( uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
virtual

Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using LoRa or up to 63 bytes using FSK modem. For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

Implements PhysicalLayer.

◆ transmit() [5/5]

virtual int16_t PhysicalLayer::transmit

Binary transmit method. Must be implemented in module class.

Parameters
dataBinary data that will be transmitted.
lenLength of binary data to transmit (in bytes).
addrNode address to transmit the packet to. Only used in FSK mode.
Returns
Status Codes

◆ transmitDirect()

int16_t SX127x::transmitDirect ( uint32_t  FRF = 0)
virtual

Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.

Parameters
FRF24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
Returns
Status Codes

Implements PhysicalLayer.

◆ variablePacketLengthMode()

int16_t SX127x::variablePacketLengthMode ( uint8_t  maxLen = SX127X_MAX_PACKET_LENGTH_FSK)

Set modem in variable packet length mode. Available in FSK mode only.

Parameters
lenMaximum packet length.
Returns
Status Codes

The documentation for this class was generated from the following files: