RadioLib
Universal wireless communication library for Arduino
SX128x Class Reference

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

#include <SX128x.h>

Inheritance diagram for SX128x:
PhysicalLayer SX1281 SX1280 SX1282

Public Member Functions

 SX128x (Module *mod)
 Default constructor. More...
 
int16_t begin (float freq=2400.0, float bw=812.5, uint8_t sf=9, uint8_t cr=7, uint8_t syncWord=RADIOLIB_SX128X_SYNC_WORD_PRIVATE, int8_t pwr=10, uint16_t preambleLength=12)
 Initialization method for LoRa modem. More...
 
int16_t beginGFSK (float freq=2400.0, uint16_t br=800, float freqDev=400.0, int8_t pwr=10, uint16_t preambleLength=16)
 Initialization method for GFSK modem. More...
 
int16_t beginBLE (float freq=2400.0, uint16_t br=800, float freqDev=400.0, int8_t pwr=10, uint8_t dataShaping=RADIOLIB_SHAPING_0_5)
 Initialization method for BLE modem. More...
 
int16_t beginFLRC (float freq=2400.0, uint16_t br=650, uint8_t cr=3, int8_t pwr=10, uint16_t preambleLength=16, uint8_t dataShaping=RADIOLIB_SHAPING_0_5)
 Initialization method for FLRC modem. More...
 
int16_t reset (bool verify=true)
 Reset method. Will reset the chip to the default state using RST pin. More...
 
int16_t transmit (const uint8_t *data, size_t len, uint8_t addr=0) override
 Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t receive (uint8_t *data, size_t len) override
 Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t transmitDirect (uint32_t frf=0) override
 Starts direct mode transmission. More...
 
int16_t receiveDirect () override
 Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN. More...
 
int16_t scanChannel () override
 Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. More...
 
int16_t scanChannel (const ChannelScanConfig_t &config) override
 Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. More...
 
int16_t sleep () override
 Sets the module to sleep mode. To wake the device up, call standby(). Overload for PhysicalLayer compatibility. More...
 
int16_t sleep (bool retainConfig)
 Sets the module to sleep mode. To wake the device up, call standby(). More...
 
int16_t standby () override
 Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator). More...
 
int16_t standby (uint8_t mode, bool wakeup=false)
 Sets the module to standby mode. More...
 
void setDio1Action (void(*func)(void))
 Sets interrupt service routine to call when DIO1 activates. More...
 
void clearDio1Action ()
 Clears interrupt service routine to call when DIO1 activates.
 
void setPacketReceivedAction (void(*func)(void)) override
 Sets interrupt service routine to call when a packet is received. More...
 
void clearPacketReceivedAction () override
 Clears interrupt service routine to call when a packet is received.
 
void setPacketSentAction (void(*func)(void)) override
 Sets interrupt service routine to call when a packet is sent. More...
 
void clearPacketSentAction () override
 Clears interrupt service routine to call when a packet is sent.
 
int16_t startTransmit (const uint8_t *data, size_t len, uint8_t addr=0) override
 Interrupt-driven binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer. More...
 
int16_t finishTransmit () override
 Clean up after transmission is done. More...
 
int16_t startReceive () override
 Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalLayer. More...
 
int16_t startReceive (uint16_t timeout, RadioLibIrqFlags_t irqFlags=RADIOLIB_IRQ_RX_DEFAULT_FLAGS, RadioLibIrqFlags_t irqMask=RADIOLIB_IRQ_RX_DEFAULT_MASK, size_t len=0)
 Interrupt-driven receive method. DIO1 will be activated when full packet is received. More...
 
uint16_t getIrqStatus ()
 Reads the current IRQ status. More...
 
int16_t readData (uint8_t *data, size_t len) override
 Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData! More...
 
uint32_t getIrqFlags () override
 Read currently active IRQ flags. More...
 
int16_t setIrqFlags (uint32_t irq) override
 Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone). More...
 
int16_t clearIrqFlags (uint32_t irq) override
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). More...
 
int16_t startChannelScan () override
 Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout. More...
 
int16_t startChannelScan (const ChannelScanConfig_t &config) override
 Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout. More...
 
int16_t getChannelScanResult () override
 Read the channel scan result. More...
 
int16_t setFrequency (float freq) override
 Sets carrier frequency. Allowed values are in range from 2400.0 to 2500.0 MHz. More...
 
int16_t setBandwidth (float bw)
 Sets LoRa bandwidth. Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz. More...
 
int16_t setSpreadingFactor (uint8_t sf)
 Sets LoRa spreading factor. Allowed values range from 5 to 12. More...
 
int16_t setCodingRate (uint8_t cr, bool longInterleaving=false)
 Sets LoRa coding rate denominator. Allowed values range from 5 to 8. More...
 
int16_t setOutputPower (int8_t pwr) override
 Sets output power. Allowed values are in range from -18 to 13 dBm. More...
 
int16_t checkOutputPower (int8_t pwr, int8_t *clipped) override
 Check if output power is configurable. More...
 
int16_t setModem (ModemType_t modem) override
 Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters. More...
 
int16_t getModem (ModemType_t *modem) override
 Get modem currently in use by the radio. More...
 
int16_t setPreambleLength (uint32_t preambleLength)
 Sets preamble length for currently active modem. Allowed values range from 1 to 65535. More...
 
int16_t setDataRate (DataRate_t dr) override
 Set data rate. More...
 
int16_t setBitRate (float br) override
 Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem). More...
 
int16_t setFrequencyDeviation (float freqDev) override
 Sets FSK frequency deviation. Allowed values range from 0.0 to 3200.0 kHz. More...
 
int16_t setDataShaping (uint8_t sh) override
 Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. More...
 
int16_t setSyncWord (const uint8_t *syncWord, uint8_t len)
 Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long. More...
 
int16_t setSyncWord (uint8_t syncWord, uint8_t controlBits=0x44)
 Sets LoRa sync word. More...
 
int16_t setCRC (uint8_t len, uint32_t initial=0x1D0F, uint16_t polynomial=0x1021)
 Sets CRC configuration. More...
 
int16_t setWhitening (bool enabled)
 Sets whitening parameters, not available for LoRa or FLRC modem. More...
 
int16_t setAccessAddress (uint32_t addr)
 Sets BLE access address. More...
 
int16_t setHighSensitivityMode (bool enable)
 Enables or disables receiver high sensitivity mode. More...
 
int16_t setGainControl (uint8_t gain=0)
 Enables or disables receiver manual gain control. More...
 
float getRSSI () override
 Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. More...
 
float getRSSI (bool packet)
 Gets RSSI (Recorded Signal Strength Indicator). More...
 
float getSNR () override
 Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem. More...
 
float getFrequencyError ()
 Gets frequency error of the latest received packet. More...
 
size_t getPacketLength (bool update=true) override
 Query modem for the packet length of received payload. More...
 
size_t getPacketLength (bool update, uint8_t *offset)
 Query modem for the packet length of received payload and Rx buffer offset. More...
 
RadioLibTime_t getTimeOnAir (size_t len) override
 Get expected time-on-air for a given size of payload. More...
 
int16_t implicitHeader (size_t len)
 Set implicit header mode for future reception/transmission. More...
 
int16_t explicitHeader ()
 Set explicit header mode for future reception/transmission. More...
 
int16_t setEncoding (uint8_t encoding) override
 Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility. More...
 
void setRfSwitchPins (uint32_t rxEn, uint32_t txEn)
 Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes: When idle both pins will be LOW, during TX the txEn pin will be HIGH, during RX the rxPin will be HIGH. More...
 
void setRfSwitchTable (const uint32_t(&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[])
 Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes. More...
 
uint8_t randomByte () override
 Dummy random method, to ensure PhysicalLayer compatibility. More...
 
int16_t invertIQ (bool enable) override
 Enable/disable inversion of the I and Q signals. More...
 
void setDirectAction (void(*func)(void)) override
 Dummy method, to ensure PhysicalLayer compatibility. More...
 
void readBit (uint32_t pin) override
 Dummy method, to ensure PhysicalLayer compatibility. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
virtual int16_t transmit (const uint8_t *data, size_t len, uint8_t addr=0)
 Binary transmit method. Must be implemented in module class. More...
 
virtual int16_t receive (uint8_t *data, size_t len)
 Binary receive method. Must be implemented in module class. 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 (const uint8_t *data, size_t len, uint8_t addr=0)
 Interrupt-driven binary transmit method. More...
 
virtual int16_t readData (uint8_t *data, size_t len)
 Reads data that was received after calling startReceive method. More...
 
- Public Member Functions inherited from PhysicalLayer
 PhysicalLayer (float step, size_t maxLen)
 Default constructor. More...
 
int16_t transmit (const char *str, uint8_t addr=0)
 C-string transmit method. More...
 
virtual int16_t standby (uint8_t mode)
 Sets module to a specific standby mode. More...
 
virtual int16_t startReceive (uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len)
 Interrupt-driven receive method. A DIO pin will be activated when full packet is received. Must be implemented in module class. 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 setSyncWord (uint8_t *sync, size_t len)
 Set sync word. Must be implemented in module class if the module supports it. More...
 
virtual int16_t setPreambleLength (size_t len)
 Set preamble length. Must be implemented in module class if the module supports it. More...
 
virtual int16_t checkDataRate (DataRate_t dr)
 Check the data rate can be configured by this module. Must be implemented in module class if the module supports it. More...
 
float getFreqStep () const
 Gets the module frequency step size that was set in constructor. More...
 
virtual RadioLibTime_t calculateRxTimeout (RadioLibTime_t timeoutUs)
 Calculate the timeout value for this specific module / series (in number of symbols or units of time). More...
 
uint32_t getIrqMapped (RadioLibIrqFlags_t irq)
 Convert from radio-agnostic IRQ flags to radio-specific flags. More...
 
int16_t checkIrq (RadioLibIrqType_t irq)
 Check whether a specific IRQ bit is set (e.g. RxTimeout, CadDone). More...
 
int16_t setIrq (RadioLibIrqFlags_t irq)
 Set interrupt on specific IRQ bit(s) (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags! More...
 
int16_t clearIrq (RadioLibIrqFlags_t irq)
 Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone). Keep in mind that not all radio modules support all RADIOLIB_IRQ_ flags! More...
 
int32_t random (int32_t max)
 Get truly random number in range 0 - max. More...
 
int32_t random (int32_t min, int32_t max)
 Get truly random number in range min - max. More...
 
int16_t startDirect ()
 Configure module parameters for direct modes. Must be called prior to "ham" modes like RTTY or AX.25. Only available in FSK mode. More...
 
int16_t setDirectSyncWord (uint32_t syncWord, uint8_t len)
 Set sync word to be used to determine start of packet in direct reception mode. More...
 
int16_t available ()
 Get the number of direct mode bytes currently available in buffer. More...
 
void dropSync ()
 Forcefully drop synchronization.
 
uint8_t read (bool drop=true)
 Get data from direct mode buffer. More...
 
virtual int16_t setDIOMapping (uint32_t pin, uint32_t value)
 Configure DIO pin mapping to get a given signal on a DIO pin (if available). More...
 
virtual void setChannelScanAction (void(*func)(void))
 Sets interrupt service routine to call when a channel scan is finished. More...
 
virtual void clearChannelScanAction ()
 Clears interrupt service routine to call when a channel scan is finished.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ SX128x()

SX128x::SX128x ( Module mod)
explicit

Default constructor.

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

Member Function Documentation

◆ begin()

int16_t SX128x::begin ( float  freq = 2400.0,
float  bw = 812.5,
uint8_t  sf = 9,
uint8_t  cr = 7,
uint8_t  syncWord = RADIOLIB_SX128X_SYNC_WORD_PRIVATE,
int8_t  pwr = 10,
uint16_t  preambleLength = 12 
)

Initialization method for LoRa modem.

Parameters
freqCarrier frequency in MHz. Defaults to 2400.0 MHz.
bwLoRa bandwidth in kHz. Defaults to 812.5 kHz.
sfLoRa spreading factor. Defaults to 9.
crLoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
syncWord2-byte LoRa sync word. Defaults to RADIOLIB_SX128X_SYNC_WORD_PRIVATE (0x12).
pwrOutput power in dBm. Defaults to 10 dBm.
preambleLengthLoRa preamble length in symbols. Defaults to 12 symbols.
Returns
Status Codes

◆ beginBLE()

int16_t SX128x::beginBLE ( float  freq = 2400.0,
uint16_t  br = 800,
float  freqDev = 400.0,
int8_t  pwr = 10,
uint8_t  dataShaping = RADIOLIB_SHAPING_0_5 
)

Initialization method for BLE modem.

Parameters
freqCarrier frequency in MHz. Defaults to 2400.0 MHz.
brBLE bit rate in kbps. Defaults to 800 kbps.
freqDevFrequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz.
pwrOutput power in dBm. Defaults to 10 dBm.
dataShapingTime-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5.
Returns
Status Codes

◆ beginFLRC()

int16_t SX128x::beginFLRC ( float  freq = 2400.0,
uint16_t  br = 650,
uint8_t  cr = 3,
int8_t  pwr = 10,
uint16_t  preambleLength = 16,
uint8_t  dataShaping = RADIOLIB_SHAPING_0_5 
)

Initialization method for FLRC modem.

Parameters
freqCarrier frequency in MHz. Defaults to 2400.0 MHz.
brFLRC bit rate in kbps. Defaults to 650 kbps.
crFLRC coding rate. Defaults to 3 (coding rate 3/4).
pwrOutput power in dBm. Defaults to 10 dBm.
preambleLengthFLRC preamble length in bits. Defaults to 16 bits.
dataShapingTime-bandwidth product of the Gaussian filter to be used for shaping. Defaults to 0.5.
Returns
Status Codes

◆ beginGFSK()

int16_t SX128x::beginGFSK ( float  freq = 2400.0,
uint16_t  br = 800,
float  freqDev = 400.0,
int8_t  pwr = 10,
uint16_t  preambleLength = 16 
)

Initialization method for GFSK modem.

Parameters
freqCarrier frequency in MHz. Defaults to 2400.0 MHz.
brFSK bit rate in kbps. Defaults to 800 kbps.
freqDevFrequency deviation from carrier frequency in kHz. Defaults to 400.0 kHz.
pwrOutput power in dBm. Defaults to 10 dBm.
preambleLengthFSK preamble length in bits. Defaults to 16 bits.
Returns
Status Codes

◆ checkOutputPower()

int16_t SX128x::checkOutputPower ( int8_t  pwr,
int8_t *  clipped 
)
overridevirtual

Check if output power is configurable.

Parameters
pwrOutput power in dBm.
clippedClipped output power value to what is possible within the module's range.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ clearIrqFlags()

int16_t SX128x::clearIrqFlags ( uint32_t  irq)
overridevirtual

Clear interrupt on a specific IRQ bit (e.g. RxTimeout, CadDone).

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ explicitHeader()

int16_t SX128x::explicitHeader ( )

Set explicit header mode for future reception/transmission.

Parameters
lenPayload length in bytes.
Returns
Status Codes

◆ finishTransmit()

int16_t SX128x::finishTransmit ( )
overridevirtual

Clean up after transmission is done.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getChannelScanResult()

int16_t SX128x::getChannelScanResult ( )
overridevirtual

Read the channel scan result.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getFrequencyError()

float SX128x::getFrequencyError ( )

Gets frequency error of the latest received packet.

Returns
Frequency error in Hz.

◆ getIrqFlags()

uint32_t SX128x::getIrqFlags ( )
overridevirtual

Read currently active IRQ flags.

Returns
IRQ flags.

Reimplemented from PhysicalLayer.

◆ getIrqStatus()

uint16_t SX128x::getIrqStatus ( )

Reads the current IRQ status.

Returns
IRQ status bits

◆ getModem()

int16_t SX128x::getModem ( ModemType_t *  modem)
overridevirtual

Get modem currently in use by the radio.

Parameters
modemPointer to a variable to save the retrieved configuration into.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ getPacketLength() [1/2]

size_t SX128x::getPacketLength ( bool  update,
uint8_t *  offset 
)

Query modem for the packet length of received payload and Rx buffer offset.

Parameters
updateUpdate received packet length. Will return cached value when set to false.
offsetPointer to variable to store the Rx buffer offset.
Returns
Length of last received packet in bytes.

◆ getPacketLength() [2/2]

size_t SX128x::getPacketLength ( bool  update = true)
overridevirtual

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.

Reimplemented from PhysicalLayer.

◆ getRSSI() [1/2]

float SX128x::getRSSI ( )
overridevirtual

Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.

Returns
RSSI of the last received packet in dBm.

Reimplemented from PhysicalLayer.

◆ getRSSI() [2/2]

float SX128x::getRSSI ( bool  packet)

Gets RSSI (Recorded Signal Strength Indicator).

Parameters
packetWhether to read last packet RSSI, or the current value.
Returns
RSSI value in dBm.

◆ getSNR()

float SX128x::getSNR ( )
overridevirtual

Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa or ranging modem.

Returns
SNR of the last received packet in dB.

Reimplemented from PhysicalLayer.

◆ getTimeOnAir()

RadioLibTime_t SX128x::getTimeOnAir ( size_t  len)
overridevirtual

Get expected time-on-air for a given size of payload.

Parameters
lenPayload length in bytes.
Returns
Expected time-on-air in microseconds.
Todo:
implement this mess - SX1280 datasheet v3.0 section 7.4.4.2

Reimplemented from PhysicalLayer.

◆ implicitHeader()

int16_t SX128x::implicitHeader ( size_t  len)

Set implicit header mode for future reception/transmission.

Returns
Status Codes

◆ invertIQ()

int16_t SX128x::invertIQ ( bool  enable)
overridevirtual

Enable/disable inversion of the I and Q signals.

Parameters
enableQI inversion enabled (true) or disabled (false);
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ randomByte()

uint8_t SX128x::randomByte ( )
overridevirtual

Dummy random method, to ensure PhysicalLayer compatibility.

Returns
Always returns 0.

Reimplemented from PhysicalLayer.

◆ readBit()

void SX128x::readBit ( uint32_t  pin)
overridevirtual

Dummy method, to ensure PhysicalLayer compatibility.

Parameters
pinIgnored.

Reimplemented from PhysicalLayer.

◆ readData() [1/2]

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 read. When set to 0, the packet length will be retrieved automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

◆ readData() [2/2]

int16_t SX128x::readData ( uint8_t *  data,
size_t  len 
)
overridevirtual

Reads data received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData!

Parameters
dataPointer to array to save the received binary data.
lenNumber of bytes that will be read. When set to 0, the packet length will be retrieved automatically. When more bytes than received are requested, only the number of bytes requested will be returned.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ receive() [1/2]

int16_t PhysicalLayer::receive

Binary receive method. Must be implemented in module class.

Parameters
dataPointer to array to save the received binary data.
lenPacket length, needed for some modules under special circumstances (e.g. LoRa implicit header mode).
Returns
Status Codes

◆ receive() [2/2]

int16_t SX128x::receive ( uint8_t *  data,
size_t  len 
)
overridevirtual

Blocking binary receive method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ receiveDirect()

int16_t SX128x::receiveDirect ( )
overridevirtual

Starts direct mode reception. Only implemented for PhysicalLayer compatibility, as SX128x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ reset()

int16_t SX128x::reset ( bool  verify = true)

Reset method. Will reset the chip to the default state using RST pin.

Parameters
verifyWhether correct module startup should be verified. When set to true, RadioLib will attempt to verify the module has started correctly by repeatedly issuing setStandby command. Enabled by default.
Returns
Status Codes

◆ scanChannel() [1/2]

int16_t SX128x::scanChannel ( )
overridevirtual

Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ scanChannel() [2/2]

int16_t SX128x::scanChannel ( const ChannelScanConfig_t config)
overridevirtual

Performs scan for LoRa transmission in the current channel. Detects both preamble and payload.

Parameters
configCAD configuration structure.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setAccessAddress()

int16_t SX128x::setAccessAddress ( uint32_t  addr)

Sets BLE access address.

Parameters
addrBLE access address.
Returns
Status Codes

◆ setBandwidth()

int16_t SX128x::setBandwidth ( float  bw)

Sets LoRa bandwidth. Allowed values are 203.125, 406.25, 812.5 and 1625.0 kHz.

Parameters
bwLoRa bandwidth to be set in kHz.
Returns
Status Codes

◆ setBitRate()

int16_t SX128x::setBitRate ( float  br)
overridevirtual

Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).

Parameters
brFSK/FLRC bit rate to be set in kbps.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setCodingRate()

int16_t SX128x::setCodingRate ( uint8_t  cr,
bool  longInterleaving = false 
)

Sets LoRa coding rate denominator. Allowed values range from 5 to 8.

Parameters
crLoRa coding rate denominator to be set.
longInterleavingWhether to enable long interleaving mode. Not available for coding rate 4/7, defaults to false.
Returns
Status Codes

◆ setCRC()

int16_t SX128x::setCRC ( uint8_t  len,
uint32_t  initial = 0x1D0F,
uint16_t  polynomial = 0x1021 
)

Sets CRC configuration.

Parameters
lenCRC length in bytes, Allowed values are 1, 2 or 3, set to 0 to disable CRC.
initialInitial CRC value. Defaults to 0x1D0F (CCIT CRC), not available for LoRa modem.
polynomialPolynomial for CRC calculation. Defaults to 0x1021 (CCIT CRC), not available for LoRa or BLE modem.
Returns
Status Codes

◆ setDataRate()

int16_t SX128x::setDataRate ( DataRate_t  dr)
overridevirtual

Set data rate.

Parameters
drData rate struct. Interpretation depends on currently active modem (FSK or LoRa).
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setDataShaping()

int16_t SX128x::setDataShaping ( uint8_t  sh)
overridevirtual

Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.

Parameters
shTime-bandwidth product of Gaussian filter to be set.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setDio1Action()

void SX128x::setDio1Action ( void(*)(void)  func)

Sets interrupt service routine to call when DIO1 activates.

Parameters
funcISR to call.

◆ setDirectAction()

void SX128x::setDirectAction ( void(*)(void)  func)
overridevirtual

Dummy method, to ensure PhysicalLayer compatibility.

Parameters
funcIgnored.

Reimplemented from PhysicalLayer.

◆ setEncoding()

int16_t SX128x::setEncoding ( uint8_t  encoding)
overridevirtual

Sets transmission encoding. Serves only as alias for PhysicalLayer compatibility.

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

Reimplemented from PhysicalLayer.

◆ setFrequency()

int16_t SX128x::setFrequency ( float  freq)
overridevirtual

Sets carrier frequency. Allowed values are in range from 2400.0 to 2500.0 MHz.

Parameters
freqCarrier frequency to be set in MHz.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setFrequencyDeviation()

int16_t SX128x::setFrequencyDeviation ( float  freqDev)
overridevirtual

Sets FSK frequency deviation. Allowed values range from 0.0 to 3200.0 kHz.

Parameters
freqDevFSK frequency deviation to be set in kHz.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setGainControl()

int16_t SX128x::setGainControl ( uint8_t  gain = 0)

Enables or disables receiver manual gain control.

Parameters
gainUse 0 for automatic gain, 1 for minimum gain and up to 13 for maximum gain.
Returns
Status Codes

◆ setHighSensitivityMode()

int16_t SX128x::setHighSensitivityMode ( bool  enable)

Enables or disables receiver high sensitivity mode.

Parameters
enableTrue to enable and false to disable.
Returns
Status Codes

◆ setIrqFlags()

int16_t SX128x::setIrqFlags ( uint32_t  irq)
overridevirtual

Set interrupt on DIO1 to be sent on a specific IRQ bit (e.g. RxTimeout, CadDone).

Parameters
irqModule-specific IRQ flags.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setModem()

int16_t SX128x::setModem ( ModemType_t  modem)
overridevirtual

Set modem for the radio to use. Will perform full reset and reconfigure the radio using its default parameters.

Parameters
modemModem type to set - FSK, LoRa or LR-FHSS.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setOutputPower()

int16_t SX128x::setOutputPower ( int8_t  pwr)
overridevirtual

Sets output power. Allowed values are in range from -18 to 13 dBm.

Parameters
pwrOutput power to be set in dBm.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ setPacketReceivedAction()

void SX128x::setPacketReceivedAction ( void(*)(void)  func)
overridevirtual

Sets interrupt service routine to call when a packet is received.

Parameters
funcISR to call.

Reimplemented from PhysicalLayer.

◆ setPacketSentAction()

void SX128x::setPacketSentAction ( void(*)(void)  func)
overridevirtual

Sets interrupt service routine to call when a packet is sent.

Parameters
funcISR to call.

Reimplemented from PhysicalLayer.

◆ setPreambleLength()

int16_t SX128x::setPreambleLength ( uint32_t  preambleLength)

Sets preamble length for currently active modem. Allowed values range from 1 to 65535.

Parameters
preambleLengthPreamble length to be set in symbols (LoRa) or bits (FSK/BLE/FLRC).
Returns
Status Codes

◆ setRfSwitchPins()

void SX128x::setRfSwitchPins ( uint32_t  rxEn,
uint32_t  txEn 
)

Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes: When idle both pins will be LOW, during TX the txEn pin will be HIGH, during RX the rxPin will be HIGH.

Radiolib will automatically set the pin mode and value of these pins, so do not control them from the sketch.

When more than two pins or more control over the output values are needed, use the setRfSwitchTable() function.

Parameters
rxEnRX enable pin.
txEnTX enable pin.

◆ setRfSwitchTable()

void SX128x::setRfSwitchTable ( const uint32_t(&)  pins[Module::RFSWITCH_MAX_PINS],
const Module::RfSwitchMode_t  table[] 
)

Some modules contain external RF switch controlled by pins. This function gives RadioLib control over those pins to automatically switch between various modes.

Radiolib will automatically set the pin mode and value of these pins, so do not control them from the sketch.

Parameters
pinsA reference to an array of pins to control. This should always be an array of 3 elements. If you need less pins, use RADIOLIB_NC for the unused elements.
tableA reference to an array of pin values to use for each supported mode. Each element is an RfSwitchMode_T struct that lists the mode for which it applies and the values for each of the pins passed in the pins argument respectively.

The pins array will be copied into the Module object, so the original array can be deallocated after this call. However, a reference to the table array will be stored, so that array must remain valid as long RadioLib is being used.

The mode field in each table row should normally use any of the MODE_* constants from the Module::OpMode_t enum. However, some radios support additional modes and will define their own OpMode_t enum.

The length of the table is variable (to support radios that add additional modes), so the table must always be terminated with the special END_OF_MODE_TABLE value.

Normally all modes should be listed in the table, but for some radios, modes can be omitted to indicate they are not supported (e.g. when a radio has a high power and low power TX mode but external circuitry only supports low power). If applicable, this is documented in the radio class itself.

Example

For example, on a board that has an RF switch with an enable pin connected to PA0 and a TX/RX select pin connected to PA1:

// In global scope, define the pin array and mode table
static const uint32_t rfswitch_pins[] =
{PA0, PA1, RADIOLIB_NC};
static const Module::RfSwitchMode_t rfswitch_table[] = {
{Module::MODE_IDLE, {LOW, LOW}},
{Module::MODE_RX, {HIGH, LOW}},
{Module::MODE_TX, {HIGH, HIGH}},
Module::END_OF_MODE_TABLE,
};
void setup() {
...
// Then somewhere in setup, pass them to radiolib
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
...
}
@ MODE_TX
Transmission mode.
Definition: Module.h:119
@ MODE_IDLE
Idle mode.
Definition: Module.h:113
@ MODE_RX
Receive mode.
Definition: Module.h:116
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition: Module.h:89

◆ setSpreadingFactor()

int16_t SX128x::setSpreadingFactor ( uint8_t  sf)

Sets LoRa spreading factor. Allowed values range from 5 to 12.

Parameters
sfLoRa spreading factor to be set.
Returns
Status Codes

◆ setSyncWord() [1/2]

int16_t SX128x::setSyncWord ( const uint8_t *  syncWord,
uint8_t  len 
)

Sets FSK/FLRC sync word in the form of array of up to 5 bytes (FSK). For FLRC modem, the sync word must be exactly 4 bytes long.

Parameters
syncWordSync word to be set.
lenSync word length in bytes.
Returns
Status Codes
Todo:
add support for multiple sync words

◆ setSyncWord() [2/2]

int16_t SX128x::setSyncWord ( uint8_t  syncWord,
uint8_t  controlBits = 0x44 
)

Sets LoRa sync word.

Parameters
syncWordLoRa sync word to be set.
controlBitsUndocumented control bits, required for compatibility purposes.
Returns
Status Codes

◆ setWhitening()

int16_t SX128x::setWhitening ( bool  enabled)

Sets whitening parameters, not available for LoRa or FLRC modem.

Parameters
enabledSet to true to enable whitening.
Returns
Status Codes

◆ sleep() [1/2]

int16_t SX128x::sleep ( )
overridevirtual

Sets the module to sleep mode. To wake the device up, call standby(). Overload for PhysicalLayer compatibility.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ sleep() [2/2]

int16_t SX128x::sleep ( bool  retainConfig)

Sets the module to sleep mode. To wake the device up, call standby().

Parameters
retainConfigSet to true to retain configuration and data buffer or to false to discard current configuration and data buffer. Defaults to true.
Returns
Status Codes

◆ standby() [1/2]

int16_t SX128x::standby ( )
overridevirtual

Sets the module to standby mode (overload for PhysicalLayer compatibility, uses 13 MHz RC oscillator).

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ standby() [2/2]

int16_t SX128x::standby ( uint8_t  mode,
bool  wakeup = false 
)

Sets the module to standby mode.

Parameters
modeOscillator to be used in standby mode. Can be set to RADIOLIB_SX128X_STANDBY_RC (13 MHz RC oscillator) or RADIOLIB_SX128X_STANDBY_XOSC (52 MHz external crystal oscillator).
wakeupWhether to force the module to wake up. Setting to true will immediately attempt to wake up the module.
Returns
Status Codes

◆ startChannelScan() [1/2]

int16_t SX128x::startChannelScan ( )
overridevirtual

Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startChannelScan() [2/2]

int16_t SX128x::startChannelScan ( const ChannelScanConfig_t config)
overridevirtual

Interrupt-driven channel activity detection method. DIO1 will be activated when LoRa preamble is detected, or upon timeout.

Parameters
configCAD configuration structure.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startReceive() [1/2]

int16_t SX128x::startReceive ( )
overridevirtual

Interrupt-driven receive method with default parameters. Implemented for compatibility with PhysicalLayer.

Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ startReceive() [2/2]

int16_t SX128x::startReceive ( uint16_t  timeout,
RadioLibIrqFlags_t  irqFlags = RADIOLIB_IRQ_RX_DEFAULT_FLAGS,
RadioLibIrqFlags_t  irqMask = RADIOLIB_IRQ_RX_DEFAULT_MASK,
size_t  len = 0 
)

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

Parameters
timeoutRaw timeout value, expressed as multiples of 15.625 us. Defaults to RADIOLIB_SX128X_RX_TIMEOUT_INF for infinite timeout (Rx continuous mode), set to RADIOLIB_SX128X_RX_TIMEOUT_NONE for no timeout (Rx single mode). If timeout other than infinite is set, signal will be generated on DIO1.
irqFlagsSets the IRQ flags, defaults to RX done, RX timeout, CRC error and header error.
irqMaskSets the mask of IRQ flags that will trigger DIO1, defaults to RX done.
lenOnly for PhysicalLayer compatibility, not used.
Returns
Status Codes

◆ startTransmit() [1/3]

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/3]

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

◆ startTransmit() [3/3]

int16_t SX128x::startTransmit ( const uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
overridevirtual

Interrupt-driven binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
addrAddress to send the data to. Unsupported, compatibility only.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ transmit() [1/3]

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() [2/3]

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

◆ transmit() [3/3]

int16_t SX128x::transmit ( const uint8_t *  data,
size_t  len,
uint8_t  addr = 0 
)
overridevirtual

Blocking binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.

Parameters
dataBinary data to be sent.
lenNumber of bytes to send.
addrAddress to send the data to. Unsupported, compatibility only.
Returns
Status Codes

Reimplemented from PhysicalLayer.

◆ transmitDirect()

int16_t SX128x::transmitDirect ( uint32_t  frf = 0)
overridevirtual

Starts direct mode transmission.

Parameters
frfRaw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
Returns
Status Codes

Reimplemented from PhysicalLayer.


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