XRange SX1272Lib

Dependents:   XRangePingPong XRange-LoRaWAN-lmic-app lora-transceiver

Fork of SX1276Lib by Semtech

Embed: (wiki syntax)

« Back to documentation index

SX1272 Class Reference

#include <sx1272.h>

Inherits Radio.

Inherited by XRange.

Public Member Functions

virtual RadioState GetState (void)
virtual void SetModem (ModemType modem)
 Configures the SX1276 with the given modem.
virtual void SetChannel (uint32_t freq)
 Sets the channel frequency.
virtual bool IsChannelFree (ModemType modem, uint32_t freq, int8_t rssiThresh)
 Sets the channels configuration.
virtual uint32_t Random (void)
 Generates a 32 bits random value based on the RSSI readings.
virtual void SetRxConfig (ModemType modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidthAfc, uint16_t preambleLen, uint16_t symbTimeout, bool fixLen, uint8_t payloadLen, bool crcOn, bool freqHopOn, uint8_t hopPeriod, bool iqInverted, bool rxContinuous)
 Sets the reception parameters.
virtual void SetTxConfig (ModemType modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preambleLen, bool fixLen, bool crcOn, bool freqHopOn, uint8_t hopPeriod, bool iqInverted, uint32_t timeout)
 Sets the transmission parameters.
virtual double TimeOnAir (ModemType modem, uint8_t pktLen)
 Computes the packet time on air for the given payload.
virtual void Send (uint8_t *buffer, uint8_t size)
 Sends the buffer of size. Prepares the packet to be sent and sets the radio in transmission.
virtual void Sleep (void)
 Sets the radio in sleep mode.
virtual void Standby (void)
 Sets the radio in standby mode.
virtual void Rx (uint32_t timeout)
 Sets the radio in reception mode for the given time.
virtual void Tx (uint32_t timeout)
 Sets the radio in transmission mode for the given time.
virtual void StartCad (void)
 Start a Channel Activity Detection.
virtual int16_t GetRssi (ModemType modem)
 Reads the current RSSI value.
virtual void Write (uint8_t addr, uint8_t data)=0
 Writes the radio register at the specified address.
virtual uint8_t Read (uint8_t addr)=0
 Reads the radio register at the specified address.
virtual void Write (uint8_t addr, uint8_t *buffer, uint8_t size)=0
 Writes multiple radio registers starting at address.
virtual void Read (uint8_t addr, uint8_t *buffer, uint8_t size)=0
 Reads multiple radio registers starting at address.
virtual void WriteFifo (uint8_t *buffer, uint8_t size)=0
 Writes the buffer contents to the SX1276 FIFO.
virtual void ReadFifo (uint8_t *buffer, uint8_t size)=0
 Reads the contents of the SX1276 FIFO.
virtual void Reset (void)=0
 Resets the SX1276.

Protected Member Functions

void RxChainCalibration (void)
virtual void IoInit (void)=0
 Initializes the radio I/Os pins interface.
virtual void RadioRegistersInit ()=0
 Initializes the radio registers.
virtual void SpiInit (void)=0
 Initializes the radio SPI.
virtual void IoIrqInit (DioIrqHandler *irqHandlers)=0
 Initializes DIO IRQ handlers.
virtual void IoDeInit (void)=0
 De-initializes the radio I/Os pins interface.
virtual uint8_t GetPaSelect (uint32_t channel)=0
 Gets the board PA selection configuration.
virtual void SetAntSwLowPower (bool status)=0
 Set the RF Switch I/Os pins in Low Power mode.
virtual void AntSwInit (void)=0
 Initializes the RF Switch I/Os pins interface.
virtual void AntSwDeInit (void)=0
 De-initializes the RF Switch I/Os pins interface.
virtual void SetAntSw (uint8_t rxTx)=0
 Controls the antena switch if necessary.
virtual bool CheckRfFrequency (uint32_t frequency)=0
 Checks if the given RF frequency is supported by the hardware.
virtual void SetOpMode (uint8_t opMode)
 Sets the SX1276 operating mode.
virtual void OnDio0Irq (void)
 DIO 0 IRQ callback.
virtual void OnDio1Irq (void)
 DIO 1 IRQ callback.
virtual void OnDio2Irq (void)
 DIO 2 IRQ callback.
virtual void OnDio3Irq (void)
 DIO 3 IRQ callback.
virtual void OnDio4Irq (void)
 DIO 4 IRQ callback.
virtual void OnDio5Irq (void)
 DIO 5 IRQ callback.
virtual void OnTimeoutIrq (void)
 Tx & Rx timeout timer callback.

Static Protected Member Functions

static uint8_t GetFskBandwidthRegValue (uint32_t bandwidth)

Protected Attributes

SPI spi
DigitalInOut reset
InterruptIn dio0
DioIrqHandler * dioIrq
Timeout txTimeoutTimer
uint8_t rxTx
void(* txDone )()
 Tx Done callback prototype.
void(* txTimeout )()
 Tx Timeout callback prototype.
void(* rxDone )(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
 Rx Done callback prototype.
void(* rxTimeout )()
 Rx Timeout callback prototype.
void(* rxError )()
 Rx Error callback prototype.
void(* fhssChangeChannel )(uint8_t CurrentChannel)
 FHSS Change Channel callback prototype.
void(* cadDone )(bool channelActivityDetected)
 CAD Done callback prototype.

Detailed Description

Constant values need to compute the RSSI value

Actual implementation of a SX1276 radio, inherits Radio

Definition at line 53 of file sx1272.h.


Member Function Documentation

virtual void AntSwDeInit ( void   ) [protected, pure virtual]

De-initializes the RF Switch I/Os pins interface.

Remarks:
Needed to decrease the power consumption in MCU lowpower modes

Implemented in XRange.

virtual void AntSwInit ( void   ) [protected, pure virtual]

Initializes the RF Switch I/Os pins interface.

Implemented in XRange.

virtual bool CheckRfFrequency ( uint32_t  frequency ) [protected, pure virtual]

Checks if the given RF frequency is supported by the hardware.

Parameters:
[IN]frequency RF frequency to be checked
Return values:
isSupported[true: supported, false: unsupported]

Implements Radio.

Implemented in XRange.

uint8_t GetFskBandwidthRegValue ( uint32_t  bandwidth ) [static, protected]

Returns the known FSK bandwidth registers value

Parameters:
[IN]bandwidth Bandwidth value in Hz
Return values:
regValueBandwidth register value.

Definition at line 165 of file sx1272.cpp.

virtual uint8_t GetPaSelect ( uint32_t  channel ) [protected, pure virtual]

Gets the board PA selection configuration.

Parameters:
[IN]channel Channel frequency in Hz
Return values:
PaSelectRegPaConfig PaSelect value

Implemented in XRange.

int16_t GetRssi ( ModemType  modem ) [virtual]

Reads the current RSSI value.

Return values:
rssiValueCurrent RSSI value in [dBm]

Implements Radio.

Definition at line 851 of file sx1272.cpp.

RadioState GetState ( void   ) [virtual]

Return current radio status

Parameters:
statusRadio status. [IDLE, RX_RUNNING, TX_RUNNING]

Implements Radio.

Definition at line 83 of file sx1272.cpp.

virtual void IoDeInit ( void   ) [protected, pure virtual]

De-initializes the radio I/Os pins interface.

Remarks:
Useful when going in MCU lowpower modes

Implemented in XRange.

virtual void IoInit ( void   ) [protected, pure virtual]

Initializes the radio I/Os pins interface.

Implemented in XRange.

virtual void IoIrqInit ( DioIrqHandler *  irqHandlers ) [protected, pure virtual]

Initializes DIO IRQ handlers.

Parameters:
[IN]irqHandlers Array containing the IRQ callback functions

Implemented in XRange.

bool IsChannelFree ( ModemType  modem,
uint32_t  freq,
int8_t  rssiThresh 
) [virtual]

Sets the channels configuration.

Parameters:
[IN]modem Radio modem to be used [0: FSK, 1: LoRa]
[IN]freq Channel RF frequency
[IN]rssiThresh RSSI threshold
Return values:
isFree[true: Channel is free, false: Channel is not free]

Implements Radio.

Definition at line 98 of file sx1272.cpp.

void OnDio0Irq ( void   ) [protected, virtual]

DIO 0 IRQ callback.

Definition at line 970 of file sx1272.cpp.

void OnDio1Irq ( void   ) [protected, virtual]

DIO 1 IRQ callback.

Definition at line 1166 of file sx1272.cpp.

void OnDio2Irq ( void   ) [protected, virtual]

DIO 2 IRQ callback.

Definition at line 1240 of file sx1272.cpp.

void OnDio3Irq ( void   ) [protected, virtual]

DIO 3 IRQ callback.

Definition at line 1304 of file sx1272.cpp.

void OnDio4Irq ( void   ) [protected, virtual]

DIO 4 IRQ callback.

Definition at line 1335 of file sx1272.cpp.

void OnDio5Irq ( void   ) [protected, virtual]

DIO 5 IRQ callback.

Definition at line 1354 of file sx1272.cpp.

void OnTimeoutIrq ( void   ) [protected, virtual]

Tx & Rx timeout timer callback.

Definition at line 924 of file sx1272.cpp.

virtual void RadioRegistersInit (  ) [protected, pure virtual]

Initializes the radio registers.

Implemented in XRange.

uint32_t Random ( void   ) [virtual]

Generates a 32 bits random value based on the RSSI readings.

Remarks:
This function sets the radio in LoRa modem mode and disables all interrupts. After calling this function either Radio.SetRxConfig or Radio.SetTxConfig functions must be called.
Return values:
randomValue32 bits random value

Implements Radio.

Definition at line 122 of file sx1272.cpp.

virtual uint8_t Read ( uint8_t  addr ) [pure virtual]

Reads the radio register at the specified address.

Parameters:
[IN],:addr Register address
Return values:
dataRegister value

Implements Radio.

Implemented in XRange.

virtual void Read ( uint8_t  addr,
uint8_t *  buffer,
uint8_t  size 
) [pure virtual]

Reads multiple radio registers starting at address.

Parameters:
[IN]addr First Radio register address
[OUT]buffer Buffer where to copy the registers data
[IN]size Number of registers to be read

Implements Radio.

Implemented in XRange.

virtual void ReadFifo ( uint8_t *  buffer,
uint8_t  size 
) [pure virtual]

Reads the contents of the SX1276 FIFO.

Parameters:
[OUT]buffer Buffer where to copy the FIFO read data.
[IN]size Number of bytes to be read from the FIFO

Implements Radio.

Implemented in XRange.

virtual void Reset ( void   ) [pure virtual]

Resets the SX1276.

Implemented in XRange.

void Rx ( uint32_t  timeout ) [virtual]

Sets the radio in reception mode for the given time.

Parameters:
[IN]timeout Reception timeout [us] [0: continuous, others timeout]

Implements Radio.

Definition at line 640 of file sx1272.cpp.

void RxChainCalibration ( void   ) [protected]

Performs the Rx chain calibration for LF and HF bands

Remarks:
Must be called just after the reset so all registers are at their default values

Definition at line 79 of file sx1272.cpp.

void Send ( uint8_t *  buffer,
uint8_t  size 
) [virtual]

Sends the buffer of size. Prepares the packet to be sent and sets the radio in transmission.

Parameters:
[IN],:buffer Buffer pointer
[IN],:size Buffer size

Implements Radio.

Definition at line 552 of file sx1272.cpp.

virtual void SetAntSw ( uint8_t  rxTx ) [protected, pure virtual]

Controls the antena switch if necessary.

Remarks:
see errata note
Parameters:
[IN]rxTx [1: Tx, 0: Rx]

Implemented in XRange.

virtual void SetAntSwLowPower ( bool  status ) [protected, pure virtual]

Set the RF Switch I/Os pins in Low Power mode.

Parameters:
[IN]status enable or disable

Implemented in XRange.

void SetChannel ( uint32_t  freq ) [virtual]

Sets the channel frequency.

Parameters:
[IN]freq Channel RF frequency

Implements Radio.

Definition at line 88 of file sx1272.cpp.

void SetModem ( ModemType  modem ) [virtual]

Configures the SX1276 with the given modem.

Parameters:
[IN]modem Modem to be used [0: FSK, 1: LoRa]

Implements Radio.

Definition at line 896 of file sx1272.cpp.

void SetOpMode ( uint8_t  opMode ) [protected, virtual]

Sets the SX1276 operating mode.

Parameters:
[IN]opMode New operating mode

Definition at line 871 of file sx1272.cpp.

void SetRxConfig ( ModemType  modem,
uint32_t  bandwidth,
uint32_t  datarate,
uint8_t  coderate,
uint32_t  bandwidthAfc,
uint16_t  preambleLen,
uint16_t  symbTimeout,
bool  fixLen,
uint8_t  payloadLen,
bool  crcOn,
bool  freqHopOn,
uint8_t  hopPeriod,
bool  iqInverted,
bool  rxContinuous 
) [virtual]

Sets the reception parameters.

Parameters:
[IN]modem Radio modem to be used [0: FSK, 1: LoRa]
[IN]bandwidth Sets the bandwidth FSK : >= 2600 and <= 250000 Hz LoRa: [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
[IN]datarate Sets the Datarate FSK : 600..300000 bits/s LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips]
[IN]coderate Sets the coding rate ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
[IN]bandwidthAfc Sets the AFC Bandwidth ( FSK only ) FSK : >= 2600 and <= 250000 Hz LoRa: N/A ( set to 0 )
[IN]preambleLen Sets the Preamble length ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: Length in symbols ( the hardware adds 4 more symbols )
[IN]symbTimeout Sets the RxSingle timeout value ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: timeout in symbols
[IN]fixLen Fixed length packets [0: variable, 1: fixed]
[IN]payloadLen Sets payload length when fixed lenght is used
[IN]crcOn Enables/Disables the CRC [0: OFF, 1: ON]
[IN]freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
[IN]hopPeriod Number of symbols bewteen each hop (LoRa only)
[IN]iqInverted Inverts IQ signals ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [0: not inverted, 1: inverted]
[IN]rxContinuous Sets the reception in continuous mode [false: single mode, true: continuous mode]

Implements Radio.

Definition at line 181 of file sx1272.cpp.

void SetTxConfig ( ModemType  modem,
int8_t  power,
uint32_t  fdev,
uint32_t  bandwidth,
uint32_t  datarate,
uint8_t  coderate,
uint16_t  preambleLen,
bool  fixLen,
bool  crcOn,
bool  freqHopOn,
uint8_t  hopPeriod,
bool  iqInverted,
uint32_t  timeout 
) [virtual]

Sets the transmission parameters.

Parameters:
[IN]modem Radio modem to be used [0: FSK, 1: LoRa]
[IN]power Sets the output power [dBm]
[IN]fdev Sets the frequency deviation ( FSK only ) FSK : [Hz] LoRa: 0
[IN]bandwidth Sets the bandwidth ( LoRa only ) FSK : 0 LoRa: [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
[IN]datarate Sets the Datarate FSK : 600..300000 bits/s LoRa: [6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips]
[IN]coderate Sets the coding rate ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
[IN]preambleLen Sets the preamble length
[IN]fixLen Fixed length packets [0: variable, 1: fixed]
[IN]crcOn Enables disables the CRC [0: OFF, 1: ON]
[IN]freqHopOn Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only)
[IN]hopPeriod Number of symbols bewteen each hop (LoRa only)
[IN]iqInverted Inverts IQ signals ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [0: not inverted, 1: inverted]
[IN]timeout Transmission timeout [us]

Implements Radio.

Definition at line 313 of file sx1272.cpp.

void Sleep ( void   ) [virtual]

Sets the radio in sleep mode.

Implements Radio.

Definition at line 623 of file sx1272.cpp.

virtual void SpiInit ( void   ) [protected, pure virtual]

Initializes the radio SPI.

Implemented in XRange.

void Standby ( void   ) [virtual]

Sets the radio in standby mode.

Implements Radio.

Definition at line 632 of file sx1272.cpp.

void StartCad ( void   ) [virtual]

Start a Channel Activity Detection.

Implements Radio.

Definition at line 817 of file sx1272.cpp.

double TimeOnAir ( ModemType  modem,
uint8_t  pktLen 
) [virtual]

Computes the packet time on air for the given payload.

Can only be called once SetRxConfig or SetTxConfig have been called

Parameters:
[IN]modem Radio modem to be used [0: FSK, 1: LoRa]
[IN]pktLen Packet payload length
Return values:
airTimeComputed airTime for the given packet payload length

Implements Radio.

Definition at line 495 of file sx1272.cpp.

void Tx ( uint32_t  timeout ) [virtual]

Sets the radio in transmission mode for the given time.

Parameters:
[IN]timeout Transmission timeout [us] [0: continuous, others timeout]

Implements Radio.

Definition at line 756 of file sx1272.cpp.

virtual void Write ( uint8_t  addr,
uint8_t  data 
) [pure virtual]

Writes the radio register at the specified address.

Parameters:
[IN],:addr Register address
[IN],:data New register value

Implements Radio.

Implemented in XRange.

virtual void Write ( uint8_t  addr,
uint8_t *  buffer,
uint8_t  size 
) [pure virtual]

Writes multiple radio registers starting at address.

Parameters:
[IN]addr First Radio register address
[IN]buffer Buffer containing the new register's values
[IN]size Number of registers to be written

Implements Radio.

Implemented in XRange.

virtual void WriteFifo ( uint8_t *  buffer,
uint8_t  size 
) [pure virtual]

Writes the buffer contents to the SX1276 FIFO.

Parameters:
[IN]buffer Buffer containing data to be put on the FIFO.
[IN]size Number of bytes to be written to the FIFO

Implements Radio.

Implemented in XRange.


Field Documentation

void( * cadDone)(bool channelActivityDetected) [protected, inherited]

CAD Done callback prototype.

Parameters:
[IN]ChannelDetected Channel Activity detected during the CAD

Definition at line 77 of file radio.h.

InterruptIn dio0 [protected]

SX1276 DIO pins

Definition at line 70 of file sx1272.h.

DioIrqHandler* dioIrq [protected]

Hardware DIO IRQ functions

Definition at line 86 of file sx1272.h.

void( * fhssChangeChannel)(uint8_t CurrentChannel) [protected, inherited]

FHSS Change Channel callback prototype.

Parameters:
[IN]CurrentChannel Index number of the current channel

Definition at line 70 of file radio.h.

DigitalInOut reset [protected]

SX1276 Reset pin

Definition at line 65 of file sx1272.h.

void( * rxDone)(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) [protected, inherited]

Rx Done callback prototype.

Parameters:
[IN]payload Received buffer pointer
[IN]size Received buffer size
[IN]rssi RSSI value computed while receiving the frame [dBm]
[IN]snr Raw SNR value given by the radio hardware FSK : N/A ( set to 0 ) LoRa: SNR value in dB

Definition at line 53 of file radio.h.

void( * rxError)() [protected, inherited]

Rx Error callback prototype.

Definition at line 63 of file radio.h.

void( * rxTimeout)() [protected, inherited]

Rx Timeout callback prototype.

Definition at line 58 of file radio.h.

uint8_t rxTx [protected]

rxTx: [1: Tx, 0: Rx]

Definition at line 98 of file sx1272.h.

SPI spi [protected]

SPI Interface

Definition at line 59 of file sx1272.h.

void( * txDone)() [protected, inherited]

Tx Done callback prototype.

Definition at line 36 of file radio.h.

void( * txTimeout)() [protected, inherited]

Tx Timeout callback prototype.

Definition at line 41 of file radio.h.

Timeout txTimeoutTimer [protected]

Tx and Rx timers

Definition at line 91 of file sx1272.h.