LoRaLib
Arduino library for LoRa modules based on LoRa chips by Semtech (SX1272, SX1276, SX1278) and HopeRF (RFM95, RFM96, RFM98)
Module Class Reference

Implements all common low-level SPI methods to control the LoRa chip. The base class SX127x contains private instance of this class. More...

#include <Module.h>

Public Member Functions

 Module (int cs=LORALIB_DEFAULT_SPI_CS, int int0=2, int int1=3, SPIClass &spi=SPI)
 Default constructor. Called internally when creating new LoRa instance. More...
 
void init (uint8_t interface, uint8_t gpio)
 Initialization method. Called internally when connecting to the LoRa chip and should not be called explicitly from Arduino code. More...
 
void term ()
 Termination method. Called internally when required LoRa chip is not found and should not be called explicitly from Arduino code.
 
int16_t SPIgetRegValue (uint8_t reg, uint8_t msb=7, uint8_t lsb=0)
 SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism. More...
 
int16_t SPIsetRegValue (uint8_t reg, uint8_t value, uint8_t msb=7, uint8_t lsb=0, uint8_t checkInterval=2)
 Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism. More...
 
void SPIreadRegisterBurst (uint8_t reg, uint8_t numBytes, uint8_t *inBytes)
 SPI burst read method. More...
 
uint8_t SPIreadRegister (uint8_t reg)
 SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead. More...
 
void SPIwriteRegisterBurst (uint8_t reg, uint8_t *data, uint8_t numBytes)
 SPI burst write method. More...
 
void SPIwriteRegister (uint8_t reg, uint8_t data)
 SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead. More...
 
void SPItransfer (uint8_t cmd, uint8_t reg, uint8_t *dataOut, uint8_t *dataIn, uint8_t numBytes)
 SPI single transfer method. More...
 
int getInt0 () const
 Access method to get the pin number of interrupt/GPIO 0. More...
 
int getInt1 () const
 Access method to get the pin number of interrupt/GPIO 1. More...
 

Detailed Description

Implements all common low-level SPI methods to control the LoRa chip. The base class SX127x contains private instance of this class.

Constructor & Destructor Documentation

Module::Module ( int  cs = LORALIB_DEFAULT_SPI_CS,
int  int0 = 2,
int  int1 = 3,
SPIClass &  spi = SPI 
)

Default constructor. Called internally when creating new LoRa instance.

Parameters
csArduino pin that will be used as chip select signal for SPI. Defaults to 4 on ESP32/ESP8266 boards, or to 10 on other architectures.
int0Arduino pin that will be used as interrupt/GPIO 0. Connect to SX127x/RFM9x pin DIO0. Does not need to be connected to Arduino interrupt pin, unless Arduino sketch is using interrupt-driven transmit/receive methods.
int1Arduino pin that will be used as interrupt/GPIO 1. Connect to SX127x/RFM9x pin DIO1. Does not need to be connected to Arduino interrupt pin, unless Arduino sketch is using interrupt-driven transmit/receive methods.
spiSPIClass instance that will be used for SPI bus control. This can be hardware SPI or some software SPI driver.

Member Function Documentation

int Module::getInt0 ( ) const
inline

Access method to get the pin number of interrupt/GPIO 0.

Returns
Pin number of interrupt/GPIO 0 configured in the constructor.
int Module::getInt1 ( ) const
inline

Access method to get the pin number of interrupt/GPIO 1.

Returns
Pin number of interrupt/GPIO 1 configured in the constructor.
void Module::init ( uint8_t  interface,
uint8_t  gpio 
)

Initialization method. Called internally when connecting to the LoRa chip and should not be called explicitly from Arduino code.

Parameters
interfaceModule interface that should be used. Required for RadioLib compatibility, will always be set to USE_SPI.
gpioDetermines which interrupt/GPIO should be used. Required for RadioLib compatibility, will always be set to INT_BOTH.
int16_t Module::SPIgetRegValue ( uint8_t  reg,
uint8_t  msb = 7,
uint8_t  lsb = 0 
)

SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism.

Parameters
regAddress of SPI register to read.
msbMost significant bit of the register variable. Bits above this one will be masked out.
lsbLeast significant bit of the register variable. Bits below this one will be masked out.
Returns
Masked register value or status code.
uint8_t Module::SPIreadRegister ( uint8_t  reg)

SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.

Parameters
regAddress of SPI register to read.
Returns
Value that was read from register.
void Module::SPIreadRegisterBurst ( uint8_t  reg,
uint8_t  numBytes,
uint8_t *  inBytes 
)

SPI burst read method.

Parameters
regAddress of SPI register to read.
numBytesNumber of bytes that will be read.
inBytesPointer to array that will hold the read data.
int16_t Module::SPIsetRegValue ( uint8_t  reg,
uint8_t  value,
uint8_t  msb = 7,
uint8_t  lsb = 0,
uint8_t  checkInterval = 2 
)

Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.

Parameters
regAddress of SPI register to write.
valueSingle byte value that will be written to the SPI register.
msbMost significant bit of the register variable. Bits above this one will not be affected by the write operation.
lsbLeast significant bit of the register variable. Bits below this one will not be affected by the write operation.
checkIntervalNumber of milliseconds between register writing and verification reading. Some registers need up to 10ms to process the change.
Returns
Status Codes
void Module::SPItransfer ( uint8_t  cmd,
uint8_t  reg,
uint8_t *  dataOut,
uint8_t *  dataIn,
uint8_t  numBytes 
)

SPI single transfer method.

Parameters
cmdSPI access command (read/write/burst/...).
regAddress of SPI register to transfer to/from.
dataOutData that will be transfered from master to slave.
dataInData that was transfered from slave to master.
numBytesNumber of bytes to transfer.
void Module::SPIwriteRegister ( uint8_t  reg,
uint8_t  data 
)

SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.

Parameters
regAddress of SPI register to write.
dataValue that will be written to the register.
void Module::SPIwriteRegisterBurst ( uint8_t  reg,
uint8_t *  data,
uint8_t  numBytes 
)

SPI burst write method.

Parameters
regAddress of SPI register to write.
dataPointer to array that holds the data that will be written.
numBytesNumber of bytes that will be written.

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