RadioLib Universal wireless communication library for Arduino

Public Member Functions | List of all members
SX1268 Class Reference

Derived class for SX1268 modules. More...

`#include <SX1268.h>`

Inheritance diagram for SX1268:

## Public Member Functions
| SX1268 (Module *mod)
| Default constructor. More...
int16_t | begin (float freq=434.0, float bw=125.0, uint8_t sf=9, uint8_t cr=7, uint8_t syncWord=RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power=10, uint16_t preambleLength=8, float tcxoVoltage=1.6, bool useRegulatorLDO=false)
| Initialization method for LoRa modem. More...
int16_t | beginFSK (float freq=434.0, float br=4.8, float freqDev=5.0, float rxBw=156.2, int8_t power=10, uint16_t preambleLength=16, float tcxoVoltage=1.6, bool useRegulatorLDO=false)
| Initialization method for FSK modem. More...
int16_t | setFrequency (float freq)
| Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz. More...
int16_t | setFrequency (float freq, bool calibrate)
| Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz. More...
int16_t | setOutputPower (int8_t power)
| Sets output power. Allowed values are in range from -9 to 22 dBm. More...
Public Member Functions inherited from SX126x
| SX126x (Module *mod)
| Default constructor. More...
Module * | getMod ()
int16_t | begin (uint8_t cr, uint8_t syncWord, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO=false)
| Initialization method for LoRa modem. More...
int16_t | beginFSK (float br, float freqDev, float rxBw, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO=false)
| Initialization method for FSK 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 (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 SX126x series does not support direct mode reception. Will always return RADIOLIB_ERR_UNKNOWN. More...
int16_t | scanChannel (uint8_t symbolNum=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin=RADIOLIB_SX126X_CAD_PARAM_DEFAULT)
| Performs scan for LoRa transmission in the current channel. Detects both preamble and payload. More...
int16_t | sleep (bool retainConfig=true)
| Sets the module to sleep mode. 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)
| 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.
int16_t | startTransmit (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 (uint32_t timeout=RADIOLIB_SX126X_RX_TIMEOUT_INF, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE, size_t len=0)
| Interrupt-driven receive method. DIO1 will be activated when full packet is received. More...
int16_t | startReceiveDutyCycle (uint32_t rxPeriod, uint32_t sleepPeriod, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE)
| Interrupt-driven receive method where the device mostly sleeps and periodically wakes to listen. Note that this function assumes the unit will take 500us + TCXO_delay to change state. See datasheet section 13.1.7, version 1.2. More...
int16_t | startReceiveDutyCycleAuto (uint16_t senderPreambleLength=0, uint16_t minSymbols=8, uint16_t irqFlags=RADIOLIB_SX126X_IRQ_RX_DEFAULT, uint16_t irqMask=RADIOLIB_SX126X_IRQ_RX_DONE)
| Calls startReceiveDutyCycle with rxPeriod and sleepPeriod set so the unit shouldn't miss any messages. 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. More...
int16_t | startChannelScan (uint8_t symbolNum=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detPeak=RADIOLIB_SX126X_CAD_PARAM_DEFAULT, uint8_t detMin=RADIOLIB_SX126X_CAD_PARAM_DEFAULT)
| Interrupt-driven channel activity detection method. DIO0 will be activated when LoRa preamble is detected, or upon timeout. More...
int16_t | getChannelScanResult ()
| Read the channel scan result. More...
int16_t | setBandwidth (float bw)
| Sets LoRa bandwidth. Allowed values are 7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125.0, 250.0 and 500.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)
| Sets LoRa coding rate denominator. Allowed values range from 5 to 8. More...
int16_t | setSyncWord (uint8_t syncWord, uint8_t controlBits=0x44)
| Sets LoRa sync word. More...
int16_t | setCurrentLimit (float currentLimit)
| Sets current protection limit. Can be set in 2.5 mA steps. More...
float | getCurrentLimit ()
| Reads current protection limit. More...
int16_t | setPreambleLength (uint16_t preambleLength)
| Sets preamble length for LoRa or FSK modem. Allowed values range from 1 to 65535. More...
int16_t | setFrequencyDeviation (float freqDev) override
| Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz. More...
int16_t | setBitRate (float br)
| Sets FSK bit rate. Allowed values range from 0.6 to 300.0 kbps. More...
int16_t | setRxBandwidth (float rxBw)
| Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5, 23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz. More...
int16_t | setRxBoostedGainMode (bool rxbgm, bool persist=true)
| Enables or disables Rx Boosted Gain mode as described in SX126x datasheet section 9.6 (SX1261/2 v2.1, SX1268 v1.1) More...
int16_t | setDataShaping (uint8_t sh) override
| Sets time-bandwidth product of Gaussian filter applied for shaping. Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5, RADIOLIB_SHAPING_0_7 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping. More...
int16_t | setSyncWord (uint8_t *syncWord, uint8_t len)
| Sets FSK sync word in the form of array of up to 8 bytes. More...
int16_t | setSyncBits (uint8_t *syncWord, uint8_t bitsLen)
| Sets FSK sync word in the form of array of up to 8 bytes. More...
int16_t | setNodeAddress (uint8_t nodeAddr)
| Sets node address. Calling this method will also enable address filtering for node address only. More...
int16_t | setBroadcastAddress (uint8_t broadAddr)
| Sets broadcast address. Calling this method will also enable address filtering for node and broadcast address. More...
int16_t | disableAddressFiltering ()
| Disables address filtering. Calling this method will also erase previously set addresses. More...
int16_t | setCRC (uint8_t len, uint16_t initial=0x1D0F, uint16_t polynomial=0x1021, bool inverted=true)
| Sets CRC configuration. More...
int16_t | setWhitening (bool enabled, uint16_t initial=0x0100)
| Sets FSK whitening parameters. More...
int16_t | setTCXO (float voltage, uint32_t delay=5000)
| Sets TCXO (Temperature Compensated Crystal Oscillator) configuration. More...
int16_t | setDio2AsRfSwitch (bool enable=true)
| Set DIO2 to function as RF switch (default in Semtech example designs). More...
float | getDataRate () const
| Gets effective data rate for the last transmitted packet. The value is calculated only for payload bytes. More...
float | getRSSI (bool packet=true)
| GetsRSSI (Recorded Signal Strength Indicator). More...
float | getSNR ()
| Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem. More...
float | getFrequencyError ()
| Gets frequency error of the latest received packet. WARNING: This functionality is based on SX128x implementation and not documented on SX126x. While it seems to be working, it should be used with caution! 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_SX126X_MAX_PACKET_LENGTH)
| Set modem in fixed packet length mode. Available in FSK mode only. More...
int16_t | variablePacketLengthMode (uint8_t maxLen=RADIOLIB_SX126X_MAX_PACKET_LENGTH)
| Set modem in variable packet length mode. Available in FSK mode only. More...
uint32_t | getTimeOnAir (size_t len)
| 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 | setRegulatorLDO ()
| Set regulator mode to LDO. More...
int16_t | setRegulatorDCDC ()
| Set regulator mode to DC-DC. More...
int16_t | setEncoding (uint8_t encoding) override
| Sets transmission encoding. Available in FSK mode only. 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...
int16_t | forceLDRO (bool enable)
| Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX126x::autoLDRO() More...
int16_t | autoLDRO ()
| Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically when symbol length exceeds 16 ms. More...
uint8_t | randomByte ()
| Get one truly random byte from RSSI noise. More...
int16_t | invertIQ (bool enable)
| Enable/disable inversion of the I and Q signals. More...
void | setDirectAction (void(*func)(void))
| Set interrupt service routine function to call when data bit is receveid in direct mode. More...
void | readBit (uint32_t pin)
| Function to read and process data bit in direct reception mode. More...
int16_t | uploadPatch (const uint32_t *patch, size_t len, bool nonvolatile=true)
| Upload binary patch into the SX126x device RAM. Patch is needed to e.g., enable spectral scan and must be uploaded again on every power cycle. More...
int16_t | spectralScanStart (uint16_t numSamples, uint8_t window=RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval=RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US)
| Start spectral scan. Requires binary path to be uploaded. More...
void | spectralScanAbort ()
| Abort an ongoing spectral scan.
int16_t | spectralScanGetStatus ()
| Read the status of spectral scan. More...
int16_t | spectralScanGetResult (uint16_t *results)
| Read the result of spectral scan. 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...
virtual int16_t | sleep ()
| Sets module to sleep. 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...
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...
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...

## Additional Inherited Members
Public Attributes inherited from SX126x
bool | XTAL
| Whether the module has an XTAL (true) or TCXO (false). Defaults to false.

## Detailed Description

Derived class for SX1268 modules.

## Constructor & Destructor Documentation

## ◆ SX1268()

SX1268::SX1268 | ( | Module * | mod | ) |

Default constructor.

Parameters

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

## Member Function Documentation

## ◆ begin()

int16_t SX1268::begin | ( | float | freq = `434.0`,
|  | float | bw = `125.0`,
|  | uint8_t | sf = `9`,
|  | uint8_t | cr = `7`,
|  | uint8_t | syncWord = `RADIOLIB_SX126X_SYNC_WORD_PRIVATE`,
|  | int8_t | power = `10`,
|  | uint16_t | preambleLength = `8`,
|  | float | tcxoVoltage = `1.6`,
|  | bool | useRegulatorLDO = `false`
| ) |  |

Initialization method for LoRa modem.

Parameters

  freq | Carrier frequency in MHz. Defaults to 434.0 MHz.
  bw | LoRa bandwidth in kHz. Defaults to 125.0 kHz.
  sf | LoRa spreading factor. Defaults to 9.
  cr | LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
  syncWord | 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
  power | Output power in dBm. Defaults to 10 dBm.
  preambleLength | LoRa preamble length in symbols. Defaults to 8 symbols.
  tcxoVoltage | TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
  useRegulatorLDO | Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.

Returns
  Status Codes

## ◆ beginFSK()

int16_t SX1268::beginFSK | ( | float | freq = `434.0`,
|  | float | br = `4.8`,
|  | float | freqDev = `5.0`,
|  | float | rxBw = `156.2`,
|  | int8_t | power = `10`,
|  | uint16_t | preambleLength = `16`,
|  | float | tcxoVoltage = `1.6`,
|  | bool | useRegulatorLDO = `false`
| ) |  |

Initialization method for FSK modem.

Parameters

  freq | Carrier frequency in MHz. Defaults to 434.0 MHz.
  br | FSK bit rate in kbps. Defaults to 4.8 kbps.
  freqDev | Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz.
  rxBw | Receiver bandwidth in kHz. Defaults to 156.2 kHz.
  power | Output power in dBm. Defaults to 10 dBm.
  preambleLength | FSK preamble length in bits. Defaults to 16 bits.
  tcxoVoltage | TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
  useRegulatorLDO | Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.

Returns
  Status Codes

## ◆ setFrequency() [1/2]

int16_t SX1268::setFrequency | ( | float | freq | ) |
| virtual

Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz.

Parameters

  freq | Carrier frequency to be set in MHz.

Returns
  Status Codes

Reimplemented from PhysicalLayer.

## ◆ setFrequency() [2/2]

int16_t SX1268::setFrequency | ( | float | freq,
|  | bool | calibrate
| ) |  |

Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz.

Parameters

  freq | Carrier frequency to be set in MHz.
  calibrate | Run image calibration.

Returns
  Status Codes

Todo:
  integers only (all modules - frequency, data rate, bandwidth etc.)

## ◆ setOutputPower()

int16_t SX1268::setOutputPower | ( | int8_t | power | ) |

Sets output power. Allowed values are in range from -9 to 22 dBm.

Parameters

  power | Output power to be set in dBm.

Returns
  Status Codes

Todo:
  power ramp time configuration

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

- src/modules/SX126x/SX1268.h
- src/modules/SX126x/SX1268.cpp