# RadioLib: SX127x Class Reference

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:

## Public Member Functions

| SX127x (Module *mod)
| Default constructor. Called internally when creating new LoRa instance. More...
int16_t | begin (uint8_t *chipVersions, uint8_t numVersions, uint8_t syncWord, 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 implementations differ.
int16_t | beginFSK (uint8_t *chipVersions, uint8_t numVersions, float freqDev, float rxBw, 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) override
| 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) override
| 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 () override
| Performs scan for valid LoRa preamble in the current channel. More...
int16_t | sleep () override
| 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 () override
| Sets the LoRa module to standby. More...
int16_t | standby (uint8_t mode) override
| Sets the LoRa module to standby. More...
int16_t | transmitDirect (uint32_t frf=0) override
| 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 () override
| 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), uint32_t dir)
| 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), uint32_t dir)
| Set interrupt service routine function 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.
void | setChannelScanAction (void(*func)(void)) override
| Sets interrupt service routine to call when a channel scan is finished. More...
void | clearChannelScanAction () override
| Clears interrupt service routine to call when a channel scan is finished.
void | setFifoEmptyAction (void(*func)(void))
| Set interrupt service routine function to call when FIFO is empty. More...
void | clearFifoEmptyAction ()
| Clears interrupt service routine to call when FIFO is empty.
void | setFifoFullAction (void(*func)(void))
| Set interrupt service routine function to call when FIFO is full. More...
void | clearFifoFullAction ()
| Clears interrupt service routine to call when FIFO is full.
bool | fifoAdd (uint8_t *data, int totalLen, int *remLen)
| Set interrupt service routine function to call when FIFO is empty. More...
bool | fifoGet (volatile uint8_t *data, int totalLen, volatile int *rcvLen)
| Set interrupt service routine function to call when FIFO is sufficiently full to read. More...
int16_t | startTransmit (uint8_t *data, size_t len, uint8_t addr=0) override
| 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 | 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 (uint8_t len, uint8_t mode=RADIOLIB_SX127X_RXCONTINUOUS)
| Interrupt-driven receive method. DIO0 will be activated when full valid packet is received. More...
int16_t | startReceive (uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override
| Interrupt-driven receive method, implemented for compatibility with PhysicalLayer. More...
int16_t | readData (uint8_t *data, size_t len) override
| Reads data that was received after calling startReceive method. When the packet length is not known in advance, getPacketLength method must be called BEFORE calling readData! More...
int16_t | startChannelScan () override
| Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected. DIO1 will be activated if there's no preamble detected before timeout. More...
int16_t | getChannelScanResult () override
| Read the channel scan result. 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 (size_t preambleLength) override
| Sets LoRa or FSK preamble length. Allowed values range from 6 to 65535 in LoRa mode or 0 to 65535 in FSK mode. More...
int16_t | invertPreamble (bool enable)
| Invert FSK preamble polarity. The default (non-inverted) is 0x55, the inverted is 0xAA. More...
float | getFrequencyError (bool autoCorrect=false)
| Gets frequency error of the latest received packet. More...
float | getAFCError ()
| Gets current AFC error. More...
float | getSNR () override
| Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode. More...
float | getDataRate () const
| Get data rate of the latest transmitted packet. More...
int16_t | setFrequencyDeviation (float freqDev) override
| 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 | setAFCBandwidth (float afcBw)
| Sets FSK automatic frequency correction bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode. More...
int16_t | setAFC (bool isEnabled)
| Enables or disables FSK automatic frequency correction(AFC) More...
int16_t | setAFCAGCTrigger (uint8_t trigger)
| Controls trigger of AFC and AGC. More...
int16_t | setSyncWord (uint8_t *syncWord, size_t len) override
| 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...
int16_t | setOokThresholdType (uint8_t type)
| Selects the type of threshold in the OOK data slicer. More...
int16_t | setOokPeakThresholdDecrement (uint8_t value)
| Period of decrement of the RSSI threshold in the OOK demodulator. More...
int16_t | setOokFixedOrFloorThreshold (uint8_t value)
| Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used. More...
int16_t | setOokPeakThresholdStep (uint8_t value)
| Size of each decrement of the RSSI threshold in the OOK demodulator. More...
int16_t | enableBitSync ()
| Enable Bit synchronizer. More...
int16_t | disableBitSync ()
| Disable Bit synchronizer (not allowed in Packet mode). More...
size_t | getPacketLength (bool update=true) override
| Query modem for the packet length of received payload. More...
int16_t | fixedPacketLengthMode (uint8_t len=RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK)
| Set modem in fixed packet length mode. Available in FSK mode only. More...
int16_t | variablePacketLengthMode (uint8_t maxLen=RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK)
| Set modem in variable packet length mode. Available in FSK mode only. More...
float | getNumSymbols (size_t len)
| Convert from bytes to LoRa symbols. More...
RadioLibTime_t | getTimeOnAir (size_t len) override
| Get expected time-on-air for a given size of payload. More...
RadioLibTime_t | calculateRxTimeout (RadioLibTime_t timeoutUs) override
| Calculate the timeout value for this specific module / series (in number of symbols or units of time) More...
int16_t | irqRxDoneRxTimeout (uint32_t &irqFlags, uint32_t &irqMask) override
| Create the flags that make up RxDone and RxTimeout used for receiving downlinks. More...
bool | isRxTimeout () override
| Check whether the IRQ bit for RxTimeout is set. More...
int16_t | setCrcFiltering (bool enable=true)
| Enable CRC filtering and generation. 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) override
| Sets transmission encoding. Only available in FSK mode. Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING. More...
uint16_t | getIRQFlags ()
| Reads currently active IRQ flags, can be used to check which event caused an interrupt. In LoRa mode, this is the content of SX127X_REG_IRQ_FLAGS register. In FSK mode, this is the contents of SX127X_REG_IRQ_FLAGS_2 (MSB) and SX127X_REG_IRQ_FLAGS_1 (LSB) registers. More...
uint8_t | getModemStatus ()
| Reads modem status. Only available in LoRa mode. More...
int8_t | getTempRaw ()
| Reads uncalibrated temperature value. This function will change operating mode and should not be called during Tx, Rx or CAD. 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
| Get one truly random byte from RSSI noise. More...
int16_t | getChipVersion ()
| Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working. More...
int16_t | invertIQ (bool enable) override
| Enable/disable inversion of the I and Q signals. More...
void | setDirectAction (void(*func)(void)) override
| Set interrupt service routine function to call when data bit is received in direct mode. More...
void | readBit (uint32_t pin) override
| Function to read and process data bit in direct reception mode. More...
int16_t | setFHSSHoppingPeriod (uint8_t freqHoppingPeriod)
| Sets the hopping period and enables FHSS. More...
uint8_t | getFHSSHoppingPeriod (void)
| Gets FHSS hopping period. More...
uint8_t | getFHSSChannel (void)
| Gets the FHSS channel in use. More...
void | clearFHSSInt (void)
| Clear the FHSS interrupt.
int16_t | setDIOMapping (uint32_t pin, uint32_t value) override
| Configure DIO pin mapping to get a given signal on a DIO pin (if available). More...
int16_t | setDIOPreambleDetect (bool usePreambleDetect)
| Configure DIO mapping to use RSSI or Preamble Detect for pins that support it. More...
int16_t | setRSSIThreshold (float dbm)
| Sets the RSSI value above which the RSSI interrupt is signaled. More...
int16_t | setLowBatteryThreshold (int8_t level, uint32_t pin=RADIOLIB_NC)
| Set low battery indicator threshold. 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)
| 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 (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...
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 | setFrequency (float freq)
| Sets carrier frequency. Must be implemented in module class. More...
virtual int16_t | setBitRate (float br)
| Sets FSK bit rate. Only available in FSK mode. Must be implemented in module class. More...
virtual int16_t | setDataShaping (uint8_t sh)
| Sets GFSK data shaping. Only available in FSK mode. Must be implemented in module class. More...
virtual int16_t | setOutputPower (int8_t power)
| Set output power. Must be implemented in module class if the module supports it. More...
virtual int16_t | checkOutputPower (int8_t power, int8_t *clipped)
| Check if output power is configurable. Must be implemented in module class if the module supports it. More...
virtual int16_t | setDataRate (DataRate_t dr)
| Set data. 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 float | getRSSI ()
| Gets RSSI (Recorded Signal Strength Indicator) of the last received packet. 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...

## 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 | ) |

explicit

Default constructor. Called internally when creating new LoRa instance.

Parameters

  mod | Instance of Module that will be used to communicate with the LoRa chip.

## Member Function Documentation

## begin()

int16_t SX127x::begin | ( | uint8_t * | chipVersions,
|  | uint8_t | numVersions,
|  | uint8_t | syncWord,
|  | uint16_t | preambleLength
| ) |  |

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

Parameters

  chipVersions | Array of possible values in SPI version register. Used to verify the connection and hardware version.
  numVersions | Number of possible chip versions.
  syncWord | LoRa sync word.
  preambleLength | Length of LoRa transmission preamble in symbols.

Returns
  Status Codes

## beginFSK()

int16_t SX127x::beginFSK | ( | uint8_t * | chipVersions,
|  | uint8_t | numVersions,
|  | float | freqDev,
|  | float | rxBw,
|  | 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

  chipVersions | Array of possible values in SPI version register. Used to verify the connection and hardware version.
  numVersions | Number of possible chip versions.
  freqDev | Frequency deviation of the FSK transmission in kHz.
  rxBw | Receiver bandwidth in kHz.
  preambleLength | Length of FSK preamble in bits.
  enableOOK | Flag to specify OOK mode. This modulation is similar to FSK.

Returns
  Status Codes

## calculateRxTimeout()

RadioLibTime_t SX127x::calculateRxTimeout | ( | RadioLibTime_t | timeoutUs | ) |

overridevirtual

Calculate the timeout value for this specific module / series (in number of symbols or units of time)

Parameters

  timeoutUs | Timeout in microseconds to listen for

Returns
  Timeout value in a unit that is specific for the used module

Reimplemented from PhysicalLayer.

## disableAddressFiltering()

int16_t SX127x::disableAddressFiltering | ( |  | ) |

Disables FSK address filtering.

Returns
  Status Codes

## disableBitSync()

int16_t SX127x::disableBitSync | ( |  | ) |

Disable Bit synchronizer (not allowed in Packet mode).

Returns
  Status Codes

## enableBitSync()

int16_t SX127x::enableBitSync | ( |  | ) |

Enable Bit synchronizer.

Returns
  Status Codes

## fifoAdd()

bool SX127x::fifoAdd | ( | uint8_t * | data,
|  | int | totalLen,
|  | int * | remLen
| ) |  |

Set interrupt service routine function to call when FIFO is empty.

Parameters

  data | Pointer to the transmission buffer.
  totalLen | Total number of bytes to transmit.
  remLen | Pointer to a counter holding the number of bytes that have been transmitted so far.

Returns
  True when a complete packet is sent, false if more data is needed.

## fifoGet()

bool SX127x::fifoGet | ( | volatile uint8_t * | data,
|  | int | totalLen,
|  | volatile int * | rcvLen
| ) |  |

Set interrupt service routine function to call when FIFO is sufficiently full to read.

Parameters

  data | Pointer to a buffer that stores the receive data.
  totalLen | Total number of bytes to receive.
  rcvLen | Pointer to a counter holding the number of bytes that have been received so far.

Returns
  True when a complete packet is received, false if more data is needed.

## finishTransmit()

int16_t SX127x::finishTransmit | ( |  | ) |

overridevirtual

Clean up after transmission is done.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## fixedPacketLengthMode()

int16_t SX127x::fixedPacketLengthMode | ( | uint8_t | len = `RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK` | ) |

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

Parameters

  len | Packet length.

Returns
  Status Codes

## getAFCError()

float SX127x::getAFCError | ( |  | ) |

Gets current AFC error.

Returns
  Frequency offset from RF in Hz if AFC is enabled and triggered, zero otherwise.

## getChannelScanResult()

int16_t SX127x::getChannelScanResult | ( |  | ) |

overridevirtual

Read the channel scan result.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## getChipVersion()

int16_t SX127x::getChipVersion | ( |  | ) |

Read version SPI register. Should return SX1278_CHIP_VERSION (0x12) or SX1272_CHIP_VERSION (0x22) if SX127x is connected and working.

Returns
  Version register contents or Status Codes

## getDataRate()

float SX127x::getDataRate | ( |  | ) | const

Get data rate of the latest transmitted packet.

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

## getFHSSChannel()

uint8_t SX127x::getFHSSChannel | ( | void |  | ) |

Gets the FHSS channel in use.

Returns
  6 bit channel number

## getFHSSHoppingPeriod()

uint8_t SX127x::getFHSSHoppingPeriod | ( | void |  | ) |

Gets FHSS hopping period.

Returns
  8 bit period

## getFrequencyError()

float SX127x::getFrequencyError | ( | bool | autoCorrect = `false` | ) |

Gets frequency error of the latest received packet.

Parameters

  autoCorrect | When set to true, frequency will be automatically corrected.

Returns
  Frequency error in Hz.

## getIRQFlags()

uint16_t SX127x::getIRQFlags | ( |  | ) |

Reads currently active IRQ flags, can be used to check which event caused an interrupt. In LoRa mode, this is the content of SX127X_REG_IRQ_FLAGS register. In FSK mode, this is the contents of SX127X_REG_IRQ_FLAGS_2 (MSB) and SX127X_REG_IRQ_FLAGS_1 (LSB) registers.

Returns
  IRQ flags.

## getModemStatus()

uint8_t SX127x::getModemStatus | ( |  | ) |

Reads modem status. Only available in LoRa mode.

Returns
  Modem status.

## getNumSymbols()

float SX127x::getNumSymbols | ( | size_t | len | ) |

Convert from bytes to LoRa symbols.

Parameters

  len | Payload length in bytes.

Returns
  The total number of LoRa symbols, including preamble, sync and possible header.

## getPacketLength()

size_t SX127x::getPacketLength | ( | bool | update = `true` | ) |

overridevirtual

Query modem for the packet length of received payload.

Parameters

  update | Update received packet length. Will return cached value when set to false.

Returns
  Length of last received packet in bytes.

Reimplemented from PhysicalLayer.

## getSNR()

float SX127x::getSNR | ( |  | ) |

overridevirtual

Gets signal-to-noise ratio of the latest received packet. Only available in LoRa mode.

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

Reimplemented from PhysicalLayer.

## getTempRaw()

int8_t SX127x::getTempRaw | ( |  | ) |

Reads uncalibrated temperature value. This function will change operating mode and should not be called during Tx, Rx or CAD.

Returns
  Uncalibrated temperature sensor reading.

## getTimeOnAir()

RadioLibTime_t SX127x::getTimeOnAir | ( | size_t | len | ) |

overridevirtual

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

Parameters

  len | Payload length in bytes.

Returns
  Expected time-on-air in microseconds.

Reimplemented from PhysicalLayer.

## invertIQ()

int16_t SX127x::invertIQ | ( | bool | enable | ) |

overridevirtual

Enable/disable inversion of the I and Q signals.

Parameters

  enable | QI inversion enabled (true) or disabled (false);

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## invertPreamble()

int16_t SX127x::invertPreamble | ( | bool | enable | ) |

Invert FSK preamble polarity. The default (non-inverted) is 0x55, the inverted is 0xAA.

Parameters

  enable | Preamble polarity in FSK mode - 0xAA when true, 0x55 when false.

Returns
  Status Codes

## irqRxDoneRxTimeout()

int16_t SX127x::irqRxDoneRxTimeout | ( | uint32_t & | irqFlags,
|  | uint32_t & | irqMask
| ) |  |

overridevirtual

Create the flags that make up RxDone and RxTimeout used for receiving downlinks.

Parameters

  irqFlags | The flags for which IRQs must be triggered
  irqMask | Mask indicating which IRQ triggers a DIO

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## isRxTimeout()

bool SX127x::isRxTimeout | ( |  | ) |

overridevirtual

Check whether the IRQ bit for RxTimeout is set.

Returns
  Whether RxTimeout IRQ is set

Reimplemented from PhysicalLayer.

## 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

## randomByte()

uint8_t SX127x::randomByte | ( |  | ) |

overridevirtual

Get one truly random byte from RSSI noise.

Returns
  TRNG byte.

Reimplemented from PhysicalLayer.

## readBit()

void SX127x::readBit | ( | uint32_t | pin | ) |

overridevirtual

Function to read and process data bit in direct reception mode.

Parameters

  pin | Pin on which to read.

Reimplemented from PhysicalLayer.

## readData() [1/2]

int16_t PhysicalLayer::readData

Reads data that was received after calling startReceive method.

Parameters

  data | Pointer to array to save the received binary data.
  len | Number 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 SX127x::readData | ( | uint8_t * | data,
|  | size_t | len
| ) |  |

overridevirtual

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

Parameters

  data | Pointer to array to save the received binary data.
  len | Number 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

  data | Pointer to array to save the received binary data.
  len | Number of bytes that will be received. Must be known in advance for binary transmissions.

Returns
  Status Codes

## receive() [2/2]

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

overridevirtual

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

  data | Pointer to array to save the received binary data.
  len | Number of bytes that will be received. Must be known in advance for binary transmissions.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## receiveDirect()

int16_t SX127x::receiveDirect | ( |  | ) |

overridevirtual

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

Reimplemented from PhysicalLayer.

## scanChannel()

int16_t SX127x::scanChannel | ( |  | ) |

overridevirtual

Performs scan for valid LoRa preamble in the current channel.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setAFC()

int16_t SX127x::setAFC | ( | bool | isEnabled | ) |

Enables or disables FSK automatic frequency correction(AFC)

Parameters

  isEnabled | AFC enabled or disabled

Returns
  Status Codes

## setAFCAGCTrigger()

int16_t SX127x::setAFCAGCTrigger | ( | uint8_t | trigger | ) |

Controls trigger of AFC and AGC.

Parameters

  trigger | one from SX127X_RX_TRIGGER_NONE, SX127X_RX_TRIGGER_RSSI_INTERRUPT, SX127X_RX_TRIGGER_PREAMBLE_DETECT, SX127X_RX_TRIGGER_BOTH

Returns
  Status Codes

## setAFCBandwidth()

int16_t SX127x::setAFCBandwidth | ( | float | afcBw | ) |

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

Parameters

  afcBw | Receiver AFC bandwidth to be set (in kHz).

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

  broadAddr | Broadcast address to be set.

Returns
  Status Codes

## setChannelScanAction()

void SX127x::setChannelScanAction | ( | void(*)(void) | func | ) |

overridevirtual

Sets interrupt service routine to call when a channel scan is finished.

Parameters

  func | ISR to call.

Reimplemented from PhysicalLayer.

## setCrcFiltering()

int16_t SX127x::setCrcFiltering | ( | bool | enable = `true` | ) |

Enable CRC filtering and generation.

Parameters

  enable | Set or unset CRC filtering and generation.

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

  currentLimit | Current limit to be set (in mA).

Returns
  Status Codes

## setDio0Action()

void SX127x::setDio0Action | ( | void(*)(void) | func,
|  | uint32_t | dir
| ) |  |

Set interrupt service routine function to call when DIO0 activates.

Parameters

  func | Pointer to interrupt service routine.
  dir | Signal change direction.

## setDio1Action()

void SX127x::setDio1Action | ( | void(*)(void) | func,
|  | uint32_t | dir
| ) |  |

Set interrupt service routine function to call when DIO1 activates.

Parameters

  func | Pointer to interrupt service routine.
  dir | Signal change direction.

## setDIOMapping()

int16_t SX127x::setDIOMapping | ( | uint32_t | pin,
|  | uint32_t | value
| ) |  |

overridevirtual

Configure DIO pin mapping to get a given signal on a DIO pin (if available).

Parameters

  pin | Pin number onto which a signal is to be placed.
  value | The value that indicates which function to place on that pin. See chip datasheet for details.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setDIOPreambleDetect()

int16_t SX127x::setDIOPreambleDetect | ( | bool | usePreambleDetect | ) |

Configure DIO mapping to use RSSI or Preamble Detect for pins that support it.

Parameters

  usePreambleDetect | Whether to use PreambleDetect (true) or RSSI (false) on the pins that are mapped to this function.

Returns
  Status Codes

## setDirectAction()

void SX127x::setDirectAction | ( | void(*)(void) | func | ) |

overridevirtual

Set interrupt service routine function to call when data bit is received in direct mode.

Parameters

  func | Pointer to interrupt service routine.

Reimplemented from PhysicalLayer.

## setEncoding()

int16_t SX127x::setEncoding | ( | uint8_t | encoding | ) |

overridevirtual

Sets transmission encoding. Only available in FSK mode. Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING.

Parameters

  encoding | Encoding to be used.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setFHSSHoppingPeriod()

int16_t SX127x::setFHSSHoppingPeriod | ( | uint8_t | freqHoppingPeriod | ) |

Sets the hopping period and enables FHSS.

Parameters

  freqHoppingPeriod | Integer multiple of symbol periods between hops

Returns
  Status Codes

## setFifoEmptyAction()

void SX127x::setFifoEmptyAction | ( | void(*)(void) | func | ) |

Set interrupt service routine function to call when FIFO is empty.

Parameters

  func | Pointer to interrupt service routine.

## setFifoFullAction()

void SX127x::setFifoFullAction | ( | void(*)(void) | func | ) |

Set interrupt service routine function to call when FIFO is full.

Parameters

  func | Pointer to interrupt service routine.

## setFrequencyDeviation()

int16_t SX127x::setFrequencyDeviation | ( | float | freqDev | ) |

overridevirtual

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

  freqDev | Frequency deviation to be set (in kHz).

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setLowBatteryThreshold()

int16_t SX127x::setLowBatteryThreshold | ( | int8_t | level,
|  | uint32_t | pin = `RADIOLIB_NC`
| ) |  |

Set low battery indicator threshold.

Parameters

  level | Battery threshold level (one of RADIOLIB_SX127X_LOW_BAT_THRESHOLD_*), or -1 to disable the detector. Disabled by default. Note that this will not attach any interrupts!
  pin | DIO pin number which will be used to signal low battery. Only DIO0/4 can be used (in packet mode) or DIO3/4 (in continuous mode). Ignored when disabling the detector.

Returns
  Status Codes

## 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

  nodeAddr | Node address to be set.

Returns
  Status Codes

## setOOK()

int16_t SX127x::setOOK | ( | bool | enableOOK | ) |

Enables/disables OOK modulation instead of FSK.

Parameters

  enableOOK | Enable (true) or disable (false) OOK.

Returns
  Status Codes

## setOokFixedOrFloorThreshold()

int16_t SX127x::setOokFixedOrFloorThreshold | ( | uint8_t | value | ) |

Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used.

Parameters

  value | Threshold level in steps of 0.5 dB.

Returns
  Status Codes

## setOokPeakThresholdDecrement()

int16_t SX127x::setOokPeakThresholdDecrement | ( | uint8_t | value | ) |

Period of decrement of the RSSI threshold in the OOK demodulator.

Parameters

  value | Use defines RADIOLIB_SX127X_OOK_PEAK_THRESH_DEC_X_X_CHIP

Returns
  Status Codes

## setOokPeakThresholdStep()

int16_t SX127x::setOokPeakThresholdStep | ( | uint8_t | value | ) |

Size of each decrement of the RSSI threshold in the OOK demodulator.

Parameters

  value | Step size: RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_0_5_DB (default), RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_1_5_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_2_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_3_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_4_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_5_0_DB, RADIOLIB_SX127X_OOK_PEAK_THRESH_STEP_6_0_DB

Returns
  Status Codes

## setOokThresholdType()

int16_t SX127x::setOokThresholdType | ( | uint8_t | type | ) |

Selects the type of threshold in the OOK data slicer.

Parameters

  type | Threshold type: SX127X_OOK_THRESH_PEAK(default), SX127X_OOK_THRESH_FIXED, SX127X_OOK_THRESH_AVERAGE

Returns
  Status Codes

## setPacketReceivedAction()

void SX127x::setPacketReceivedAction | ( | void(*)(void) | func | ) |

overridevirtual

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

Parameters

  func | ISR to call.

Reimplemented from PhysicalLayer.

## setPacketSentAction()

void SX127x::setPacketSentAction | ( | void(*)(void) | func | ) |

overridevirtual

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

Parameters

  func | ISR to call.

Reimplemented from PhysicalLayer.

## setPreambleLength()

int16_t SX127x::setPreambleLength | ( | size_t | preambleLength | ) |

overridevirtual

Sets LoRa or FSK preamble length. Allowed values range from 6 to 65535 in LoRa mode or 0 to 65535 in FSK mode.

Parameters

  preambleLength | Preamble length to be set (in symbols when in LoRa mode or bits in FSK mode).

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setRfSwitchPins()

void SX127x::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

  rxEn | RX enable pin.
  txEn | TX enable pin.

## setRfSwitchTable()

void SX127x::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

  pins | A 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.
  table | A 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);
...
}
Module::MODE_TX
@ MODE_TX
Transmission mode.
Definition: Module.h:111
Module::MODE_IDLE
@ MODE_IDLE
Idle mode.
Definition: Module.h:105
Module::MODE_RX
@ MODE_RX
Receive mode.
Definition: Module.h:108
Module::RfSwitchMode_t
Description of RF switch pin states for a single mode. See setRfSwitchTable for details.
Definition: Module.h:81

## setRSSIConfig()

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

Sets RSSI measurement configuration in FSK mode.

Parameters

  smoothingSamples | Number of samples taken to average the RSSI result. numSamples = 2 ^ (1 + smoothingSamples), allowed values are in range 0 (2 samples) - 7 (256 samples)
  offset | Signed 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

## setRSSIThreshold()

int16_t SX127x::setRSSIThreshold | ( | float | dbm | ) |

Sets the RSSI value above which the RSSI interrupt is signaled.

Parameters

  dbm | A dBm value between -127.5 and 0 inclusive

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

  rxBw | Receiver bandwidth to be set (in kHz).

Returns
  Status Codes

## setSyncWord() [1/2]

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

overridevirtual

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

  syncWord | Sync word array.
  len | Sync word length (in bytes).

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## setSyncWord() [2/2]

int16_t SX127x::setSyncWord | ( | uint8_t | syncWord | ) |

Sets LoRa sync word. Only available in LoRa mode.

Parameters

  syncWord | Sync word to be set.

Returns
  Status Codes

## sleep()

int16_t SX127x::sleep | ( |  | ) |

overridevirtual

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

Reimplemented from PhysicalLayer.

## standby() [1/2]

int16_t SX127x::standby | ( |  | ) |

overridevirtual

Sets the LoRa module to standby.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## standby() [2/2]

int16_t SX127x::standby | ( | uint8_t | mode | ) |

overridevirtual

Sets the LoRa module to standby.

Parameters

  mode | Standby mode to be used. No effect, implemented only for PhysicalLayer compatibility.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startChannelScan()

int16_t SX127x::startChannelScan | ( |  | ) |

overridevirtual

Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected. DIO1 will be activated if there's no preamble detected before timeout.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startReceive() [1/3]

int16_t SX127x::startReceive | ( |  | ) |

overridevirtual

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

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startReceive() [2/3]

int16_t SX127x::startReceive | ( | uint32_t | timeout,
|  | uint32_t | irqFlags,
|  | uint32_t | irqMask,
|  | size_t | len
| ) |  |

overridevirtual

Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.

Parameters

  timeout | Receive mode type and/or raw timeout value in symbols. When set to 0, the timeout will be infinite and the device will remain in Rx mode until explicitly commanded to stop (Rx continuous mode). When non-zero (maximum 1023), the device will be set to Rx single mode and timeout will be set.
  irqFlags | Ignored.
  irqMask | Ignored.
  len | Expected length of packet to be received. Required for LoRa spreading factor 6.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## startReceive() [3/3]

int16_t SX127x::startReceive | ( | uint8_t | len,
|  | uint8_t | mode = `RADIOLIB_SX127X_RXCONTINUOUS`
| ) |  |

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

Parameters

  len | Expected length of packet to be received, or 0 when unused. Defaults to 0, non-zero required for LoRa spreading factor 6.
  mode | Receive mode to be used. Defaults to RxContinuous.

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

  str | C-string that will be transmitted.
  addr | Node 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

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## startTransmit() [3/3]

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

overridevirtual

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

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## transmit() [1/3]

int16_t PhysicalLayer::transmit

C-string transmit method.

Parameters

  str | C-string that will be transmitted.
  addr | Node 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

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

## transmit() [3/3]

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

overridevirtual

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

  data | Binary data that will be transmitted.
  len | Length of binary data to transmit (in bytes).
  addr | Node address to transmit the packet to. Only used in FSK mode.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## transmitDirect()

int16_t SX127x::transmitDirect | ( | uint32_t | frf = `0` | ) |

overridevirtual

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

  frf | 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## variablePacketLengthMode()

int16_t SX127x::variablePacketLengthMode | ( | uint8_t | maxLen = `RADIOLIB_SX127X_MAX_PACKET_LENGTH_FSK` | ) |

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

Parameters

  maxLen | Maximum packet length.

Returns
  Status Codes

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

- src/modules/SX127x/SX127x.h
- src/modules/SX127x/SX127x.cpp