Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Cayenne-LPP SDBlockDevice
SX1272_LoRaRadio Class Reference
Radio driver implementation for Semtech SX1272 plus variants. More...
#include <SX1272_LoRaRadio.h>
Public Member Functions | |
| SX1272_LoRaRadio (PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset, PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5, PinName rf_switch_ctl1=NC, PinName rf_switch_ctl2=NC, PinName txctl=NC, PinName rxctl=NC, PinName ant_switch=NC, PinName pwr_amp_ctl=NC, PinName tcxo=NC) | |
| Use this constructor if pin definitions are provided manually. | |
| virtual | ~SX1272_LoRaRadio () |
| Destructor. | |
| virtual void | init_radio (radio_events_t *events) |
| Registers radio events with the Mbed LoRaWAN stack and undergoes initialization steps if any. | |
| virtual void | radio_reset () |
| Resets the radio module. | |
| virtual void | sleep (void) |
| Put the RF module in sleep mode. | |
| virtual void | standby (void) |
| Sets the radio in standby mode. | |
| virtual void | set_rx_config (radio_modems_t modem, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint32_t bandwidth_afc, uint16_t preamble_len, uint16_t symb_timeout, bool fix_len, uint8_t payload_len, bool crc_on, bool freq_hop_on, uint8_t hop_period, bool iq_inverted, bool rx_continuous) |
| Sets the reception parameters. | |
| virtual void | set_tx_config (radio_modems_t modem, int8_t power, uint32_t fdev, uint32_t bandwidth, uint32_t datarate, uint8_t coderate, uint16_t preamble_len, bool fix_len, bool crc_on, bool freq_hop_on, uint8_t hop_period, bool iq_inverted, uint32_t timeout) |
| Sets the transmission parameters. | |
| virtual void | send (uint8_t *buffer, uint8_t size) |
| Sends the buffer of size. | |
| virtual void | receive (uint32_t timeout) |
| Sets the radio in reception mode for the given time. | |
| virtual void | set_channel (uint32_t freq) |
| Sets the carrier frequency. | |
| virtual uint32_t | random (void) |
| Generates a 32 bits random value based on the RSSI readings. | |
| virtual uint8_t | get_status (void) |
| Get radio status. | |
| virtual void | set_max_payload_length (radio_modems_t modem, uint8_t max) |
| Sets the maximum payload length. | |
| virtual void | set_public_network (bool enable) |
| Sets the network to public or private. | |
| virtual uint32_t | time_on_air (radio_modems_t modem, uint8_t pkt_len) |
| Computes the packet time on air for the given payload. | |
| virtual bool | perform_carrier_sense (radio_modems_t modem, uint32_t freq, int16_t rssi_threshold, uint32_t max_carrier_sense_time) |
| Perform carrier sensing. | |
| virtual void | start_cad (void) |
| Sets the radio in CAD mode. | |
| virtual bool | check_rf_frequency (uint32_t frequency) |
| Check if the given RF is in range. | |
| virtual void | set_tx_continuous_wave (uint32_t freq, int8_t power, uint16_t time) |
| Sets the radio in continuous wave transmission mode. | |
| virtual void | lock (void) |
| Acquire exclusive access. | |
| virtual void | unlock (void) |
| Release exclusive access. | |
Detailed Description
Radio driver implementation for Semtech SX1272 plus variants.
Supports only SPI at the moment. Implements pure virtual LoRaRadio class.
Definition at line 54 of file SX1272_LoRaRadio.h.
Constructor & Destructor Documentation
| SX1272_LoRaRadio | ( | PinName | mosi, |
| PinName | miso, | ||
| PinName | sclk, | ||
| PinName | nss, | ||
| PinName | reset, | ||
| PinName | dio0, | ||
| PinName | dio1, | ||
| PinName | dio2, | ||
| PinName | dio3, | ||
| PinName | dio4, | ||
| PinName | dio5, | ||
| PinName | rf_switch_ctl1 = NC, |
||
| PinName | rf_switch_ctl2 = NC, |
||
| PinName | txctl = NC, |
||
| PinName | rxctl = NC, |
||
| PinName | ant_switch = NC, |
||
| PinName | pwr_amp_ctl = NC, |
||
| PinName | tcxo = NC |
||
| ) |
Use this constructor if pin definitions are provided manually.
Constructor.
The pins that are marked NC are optional. It is assumed that these pins are not connected until/unless configured otherwise.
Definition at line 166 of file SX1272_LoRaRadio.cpp.
| ~SX1272_LoRaRadio | ( | ) | [virtual] |
Destructor.
Definition at line 223 of file SX1272_LoRaRadio.cpp.
Member Function Documentation
| bool check_rf_frequency | ( | uint32_t | frequency ) | [virtual] |
Check if the given RF is in range.
TODO: The purpose of this API is unclear.
- Parameters:
-
frequency frequency needed to be checked
Need to start an internal discussion.
Definition at line 286 of file SX1272_LoRaRadio.cpp.
| uint8_t get_status | ( | void | ) | [virtual] |
Get radio status.
Returns current status of the radio state machine.
- Parameters:
-
status Radio status [RF_IDLE, RF_RX_RUNNING, RF_TX_RUNNING]
- Returns:
- Return current radio status
Definition at line 307 of file SX1272_LoRaRadio.cpp.
| void init_radio | ( | radio_events_t * | events ) | [virtual] |
Registers radio events with the Mbed LoRaWAN stack and undergoes initialization steps if any.
Initializes radio module.
- Parameters:
-
events Structure containing the driver callback functions
Definition at line 251 of file SX1272_LoRaRadio.cpp.
| void lock | ( | void | ) | [virtual] |
| bool perform_carrier_sense | ( | radio_modems_t | modem, |
| uint32_t | freq, | ||
| int16_t | rssi_threshold, | ||
| uint32_t | max_carrier_sense_time | ||
| ) | [virtual] |
Perform carrier sensing.
Checks for a certain time if the RSSI is above a given threshold. This threshold determines if there is already a transmission going on in the channel or not.
- Parameters:
-
modem Type of the radio modem freq Carrier frequency rssi_threshold Threshold value of RSSI max_carrier_sense_time time to sense the channel
- Returns:
- true if there is no active transmission in the channel, false otherwise
Checks for a certain time if the RSSI is above a given threshold. This threshold determines if there is already a transmission going on in the channel or not.
Definition at line 1059 of file SX1272_LoRaRadio.cpp.
| void radio_reset | ( | ) | [virtual] |
Resets the radio module.
Can be used by application/stack or the driver itself Ref: Datasheet 7.2.2 Manual Reset.
Definition at line 394 of file SX1272_LoRaRadio.cpp.
| uint32_t random | ( | void | ) | [virtual] |
Generates a 32 bits random value based on the RSSI readings.
Generates 32 bit random number based upon RSSI monitoring Used for various calculation by the stack for example dev nonce.
Remark 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.
- Returns:
- 32 bits random value
When this API is used modem is set in LoRa mode and all interrupts are masked. If the user had been using FSK mode, it should be noted that a change of mode is required again because the registers have changed. In addition to that RX and TX configuration APIs should be called again in order to have correct desires setup.
Definition at line 1174 of file SX1272_LoRaRadio.cpp.
| void receive | ( | uint32_t | timeout ) | [virtual] |
Sets the radio in reception mode for the given time.
Sets the radio module in receive mode.
It should be noted that if the timeout is set to 0, it essentially puts the receiver in continuous mode and hence from thereon it should be treated as if in continuous mode. However, an appropriate way of setting the receiver in continuous mode is by using set_rx_config() API.
- Parameters:
-
timeout Reception timeout [ms]
A DIO4 interrupt let's the state machine know that a preamble is detected and finally a DIO0 interrupt let's the state machine know that a packet is ready to be read from the FIFO
Definition at line 881 of file SX1272_LoRaRadio.cpp.
| void send | ( | uint8_t * | buffer, |
| uint8_t | size | ||
| ) | [virtual] |
Sends the buffer of size.
Prepares and sends the radio packet out in the air.
Prepares the packet to be sent and sets the radio in transmission
- Parameters:
-
buffer Buffer pointer size Buffer size
Definition at line 723 of file SX1272_LoRaRadio.cpp.
| void set_channel | ( | uint32_t | freq ) | [virtual] |
Sets the carrier frequency.
Sets up carrier frequency.
- Parameters:
-
freq Channel RF frequency
Definition at line 295 of file SX1272_LoRaRadio.cpp.
| void set_max_payload_length | ( | radio_modems_t | modem, |
| uint8_t | max | ||
| ) | [virtual] |
Sets the maximum payload length.
Puts a limit on the size of payload the module can handle By default it is MAX, i.e., 256 bytes.
- Parameters:
-
modem Radio modem to be used [0: FSK, 1: LoRa] max Maximum payload length in bytes
Definition at line 1015 of file SX1272_LoRaRadio.cpp.
| void set_public_network | ( | bool | enable ) | [virtual] |
Sets the network to public or private.
TODO: Making sure if this API is valid only for LoRa modulation ?
Updates the sync byte. Applies to LoRa modem only
- Parameters:
-
enable if true, it enables a public network
Indicates if the node is part of a private or public network
Definition at line 1036 of file SX1272_LoRaRadio.cpp.
| void set_rx_config | ( | radio_modems_t | modem, |
| uint32_t | bandwidth, | ||
| uint32_t | datarate, | ||
| uint8_t | coderate, | ||
| uint32_t | bandwidth_afc, | ||
| uint16_t | preamble_len, | ||
| uint16_t | symb_timeout, | ||
| bool | fix_len, | ||
| uint8_t | payload_len, | ||
| bool | crc_on, | ||
| bool | freq_hop_on, | ||
| uint8_t | hop_period, | ||
| bool | iq_inverted, | ||
| bool | rx_continuous | ||
| ) | [virtual] |
Sets the reception parameters.
Sets up receiver related configurations.
- Parameters:
-
modem Radio modem to be used [0: FSK, 1: LoRa] bandwidth Sets the bandwidth FSK : >= 2600 and <= 250000 Hz LoRa: [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved] 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] 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] bandwidth_afc Sets the AFC Bandwidth ( FSK only ) FSK : >= 2600 and <= 250000 Hz LoRa: N/A ( set to 0 ) preamble_len Sets the Preamble length ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: Length in symbols ( the hardware adds 4 more symbols ) symb_timeout Sets the RxSingle timeout value FSK : timeout number of bytes LoRa: timeout in symbols fixLen Fixed length packets [0: variable, 1: fixed] payload_len Sets payload length when fixed lenght is used crc_on Enables/Disables the CRC [0: OFF, 1: ON] freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) hop_period Number of symbols bewteen each hop (LoRa only) iq_inverted Inverts IQ signals ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [0: not inverted, 1: inverted] rx_continuous Sets the reception in continuous mode [false: single mode, true: continuous mode]
Must be called before setting the radio in rx mode
Definition at line 408 of file SX1272_LoRaRadio.cpp.
| void set_tx_config | ( | radio_modems_t | modem, |
| int8_t | power, | ||
| uint32_t | fdev, | ||
| uint32_t | bandwidth, | ||
| uint32_t | datarate, | ||
| uint8_t | coderate, | ||
| uint16_t | preamble_len, | ||
| bool | fix_len, | ||
| bool | crc_on, | ||
| bool | freq_hop_on, | ||
| uint8_t | hop_period, | ||
| bool | iq_inverted, | ||
| uint32_t | timeout | ||
| ) | [virtual] |
Sets the transmission parameters.
Sets up transmitter related configuration.
- Parameters:
-
modem Radio modem to be used [0: FSK, 1: LoRa] power Sets the output power [dBm] fdev Sets the frequency deviation ( FSK only ) FSK : [Hz] LoRa: 0 bandwidth Sets the bandwidth ( LoRa only ) FSK : 0 LoRa: [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved] 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] 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] preamble_len Sets the preamble length fix_len Fixed length packets [0: variable, 1: fixed] crc_on Enables disables the CRC [0: OFF, 1: ON] freq_hop_on Enables disables the intra-packet frequency hopping [0: OFF, 1: ON] (LoRa only) hop_period Number of symbols bewteen each hop (LoRa only) iq_inverted Inverts IQ signals ( LoRa only ) FSK : N/A ( set to 0 ) LoRa: [0: not inverted, 1: inverted] timeout Transmission timeout [us]
Must be called before putting the radio module in Tx mode or trying to send
Definition at line 538 of file SX1272_LoRaRadio.cpp.
| void set_tx_continuous_wave | ( | uint32_t | freq, |
| int8_t | power, | ||
| uint16_t | time | ||
| ) | [virtual] |
Sets the radio in continuous wave transmission mode.
Set transmission in continuous wave mode.
- Parameters:
-
freq Channel RF frequency power Sets the output power [dBm] time Transmission mode timeout [s]
Definition at line 1133 of file SX1272_LoRaRadio.cpp.
| void sleep | ( | void | ) | [virtual] |
Put the RF module in sleep mode.
sets the radio module to sleep
Definition at line 316 of file SX1272_LoRaRadio.cpp.
| void standby | ( | void | ) | [virtual] |
Sets the radio in standby mode.
Put radio in Standby mode.
Definition at line 1155 of file SX1272_LoRaRadio.cpp.
| void start_cad | ( | void | ) | [virtual] |
Sets the radio in CAD mode.
Channel Activity detection (can be done only in LoRa mode)
If any activity on the channel is detected, an interrupt is asserted on DIO3. A callback will be generated to the stack/application upon the assertion of DIO3.
Definition at line 1098 of file SX1272_LoRaRadio.cpp.
| uint32_t time_on_air | ( | radio_modems_t | modem, |
| uint8_t | pkt_len | ||
| ) | [virtual] |
Computes the packet time on air for the given payload.
Calculates time on Air i.e., dwell time for a single packet.
Remark can only be called once SetRxConfig or SetTxConfig have been called
- Parameters:
-
modem Radio modem to be used [0: FSK, 1: LoRa] pkt_len Packet payload length
- Returns:
- Computed airTime for the given packet payload length
Crucial for the stack in order to calculate dwell time so as to control duty cycling.
Definition at line 662 of file SX1272_LoRaRadio.cpp.
| void unlock | ( | void | ) | [virtual] |
Generated on Sat Jul 16 2022 05:24:58 by
1.7.2