Driver for Semtech SX1272 and SX1276 radios. More...
Driver for Semtech SX1272 and SX1276 radios.
This module contains the driver for radio devices of the Semtech SX127x series (SX1272 and SX1276). Only LoRa long range modem is supported at the moment.
SX127x modules are designed to be used in the ISM radio frequency (RF) band. This RF band depends on different regional regulations worldwide. Be careful to configure the device to use a RF frequency allowed in your region. Here is the list of allowed frequencies for your region (see LoRaWAN regional parameters document available online):
For more information on Semtech SX1272 and SX1276 modules see:
Modules | |
Semtech SX1272 and SX1276 driver compile configuration | |
Files | |
file | sx127x.h |
Public interface for SX127X driver. | |
file | sx127x_internal.h |
Semtech SX127X internal functions. | |
file | sx127x_netdev.h |
Netdev driver definitions for SX127X driver. | |
file | sx127x_params.h |
Default configuration for SX127X driver. | |
file | sx127x_registers.h |
SX127X registers. | |
Data Structures | |
struct | sx127x_lora_settings_t |
LoRa configuration structure. More... | |
struct | sx127x_radio_settings_t |
Radio settings. More... | |
struct | sx127x_internal_t |
SX127X internal data. More... | |
struct | sx127x_params_t |
SX127X hardware and global parameters. More... | |
struct | sx127x_t |
SX127X device descriptor. More... | |
Typedefs | |
typedef uint8_t | sx127x_flags_t |
SX127X IRQ flags. | |
typedef void() | sx127x_dio_irq_handler_t(sx127x_t *dev) |
Hardware IO IRQ callback function definition. | |
Enumerations | |
enum | { SX127X_INIT_OK = 0, SX127X_ERR_SPI, SX127X_ERR_GPIOS, SX127X_ERR_NODEV } |
SX127X initialization result. More... | |
enum | { SX127X_MODEM_FSK = 0, SX127X_MODEM_LORA } |
Radio driver supported modems. More... | |
enum | { SX127X_RF_IDLE = 0, SX127X_RF_RX_RUNNING, SX127X_RF_TX_RUNNING, SX127X_RF_CAD } |
Radio driver internal state machine states definition. More... | |
enum | { SX127X_RX_DONE = 0, SX127X_TX_DONE, SX127X_RX_TIMEOUT, SX127X_TX_TIMEOUT, SX127X_RX_ERROR_CRC, SX127X_FHSS_CHANGE_CHANNEL, SX127X_CAD_DONE } |
Event types. More... | |
enum | { SX127X_PA_RFO = 0, SX127X_PA_BOOST } |
Power amplifier modes. More... | |
Functions | |
void | sx127x_setup (sx127x_t *dev, const sx127x_params_t *params) |
Setup the SX127X. More... | |
int | sx127x_reset (const sx127x_t *dev) |
Resets the SX127X. More... | |
int | sx127x_init (sx127x_t *dev) |
Initializes the transceiver. More... | |
void | sx127x_init_radio_settings (sx127x_t *dev) |
Initialize radio settings with default values. More... | |
uint32_t | sx127x_random (sx127x_t *dev) |
Generates 32 bits random value based on the RSSI readings. More... | |
void | sx127x_start_cad (sx127x_t *dev) |
Start a channel activity detection. More... | |
bool | sx127x_is_channel_free (sx127x_t *dev, uint32_t freq, int16_t rssi_threshold) |
Checks that channel is free with specified RSSI threshold. More... | |
int16_t | sx127x_read_rssi (const sx127x_t *dev) |
Reads the current RSSI value. More... | |
uint8_t | sx127x_get_state (const sx127x_t *dev) |
Gets current state of transceiver. More... | |
void | sx127x_set_state (sx127x_t *dev, uint8_t state) |
Sets current state of transceiver. More... | |
void | sx127x_set_modem (sx127x_t *dev, uint8_t modem) |
Configures the radio with the given modem. More... | |
uint8_t | sx127x_get_syncword (const sx127x_t *dev) |
Gets the synchronization word. More... | |
void | sx127x_set_syncword (sx127x_t *dev, uint8_t syncword) |
Sets the synchronization word. More... | |
uint32_t | sx127x_get_channel (const sx127x_t *dev) |
Gets the channel RF frequency. More... | |
void | sx127x_set_channel (sx127x_t *dev, uint32_t freq) |
Sets the channel RF frequency. More... | |
uint32_t | sx127x_get_time_on_air (const sx127x_t *dev, uint8_t pkt_len) |
Computes the packet time on air in milliseconds. More... | |
void | sx127x_set_sleep (sx127x_t *dev) |
Sets the radio in sleep mode. More... | |
void | sx127x_set_standby (sx127x_t *dev) |
Sets the radio in stand-by mode. More... | |
void | sx127x_set_rx (sx127x_t *dev) |
Sets the radio in reception mode. More... | |
void | sx127x_set_tx (sx127x_t *dev) |
Sets the radio in transmission mode. More... | |
uint8_t | sx127x_get_max_payload_len (const sx127x_t *dev) |
Gets the maximum payload length. More... | |
void | sx127x_set_max_payload_len (const sx127x_t *dev, uint8_t maxlen) |
Sets the maximum payload length. More... | |
uint8_t | sx127x_get_op_mode (const sx127x_t *dev) |
Gets the SX127X operating mode. More... | |
void | sx127x_set_op_mode (const sx127x_t *dev, uint8_t op_mode) |
Sets the SX127X operating mode. More... | |
uint8_t | sx127x_get_bandwidth (const sx127x_t *dev) |
Gets the SX127X bandwidth. More... | |
void | sx127x_set_bandwidth (sx127x_t *dev, uint8_t bandwidth) |
Sets the SX127X bandwidth. More... | |
uint8_t | sx127x_get_spreading_factor (const sx127x_t *dev) |
Gets the SX127X LoRa spreading factor. More... | |
void | sx127x_set_spreading_factor (sx127x_t *dev, uint8_t sf) |
Sets the SX127X LoRa spreading factor. More... | |
uint8_t | sx127x_get_coding_rate (const sx127x_t *dev) |
Gets the SX127X LoRa coding rate. More... | |
void | sx127x_set_coding_rate (sx127x_t *dev, uint8_t coderate) |
Sets the SX127X LoRa coding rate. More... | |
bool | sx127x_get_rx_single (const sx127x_t *dev) |
Checks if the SX127X LoRa RX single mode is enabled/disabled. More... | |
void | sx127x_set_rx_single (sx127x_t *dev, bool single) |
Enable/disable the SX127X LoRa RX single mode. More... | |
bool | sx127x_get_crc (const sx127x_t *dev) |
Checks if the SX127X CRC verification mode is enabled. More... | |
void | sx127x_set_crc (sx127x_t *dev, bool crc) |
Enable/Disable the SX127X CRC verification mode. More... | |
uint8_t | sx127x_get_hop_period (const sx127x_t *dev) |
Gets the SX127X frequency hopping period. More... | |
void | sx127x_set_hop_period (sx127x_t *dev, uint8_t hop_period) |
Sets the SX127X frequency hopping period. More... | |
bool | sx127x_get_fixed_header_len_mode (const sx127x_t *dev) |
Gets the SX127X LoRa fixed header length mode. More... | |
void | sx127x_set_fixed_header_len_mode (sx127x_t *dev, bool mode) |
Sets the SX127X to fixed header length mode (explicit mode) More... | |
uint8_t | sx127x_get_payload_length (const sx127x_t *dev) |
Gets the SX127X payload length. More... | |
void | sx127x_set_payload_length (sx127x_t *dev, uint8_t len) |
Sets the SX127X payload length. More... | |
uint8_t | sx127x_get_tx_power (const sx127x_t *dev) |
Gets the SX127X TX radio power. More... | |
void | sx127x_set_tx_power (sx127x_t *dev, int8_t power) |
Sets the SX127X transmission power. More... | |
uint16_t | sx127x_get_preamble_length (const sx127x_t *dev) |
Gets the SX127X preamble length. More... | |
void | sx127x_set_preamble_length (sx127x_t *dev, uint16_t preamble) |
Sets the SX127X LoRa preamble length. More... | |
void | sx127x_set_symbol_timeout (sx127x_t *dev, uint16_t timeout) |
Sets the SX127X LoRa symbol timeout. More... | |
void | sx127x_set_rx_timeout (sx127x_t *dev, uint32_t timeout) |
Sets the SX127X RX timeout. More... | |
void | sx127x_set_tx_timeout (sx127x_t *dev, uint32_t timeout) |
Sets the SX127X TX timeout. More... | |
bool | sx127x_get_iq_invert (const sx127x_t *dev) |
Checks if the SX127X LoRa inverted IQ mode is enabled/disabled. More... | |
void | sx127x_set_iq_invert (sx127x_t *dev, bool iq_invert) |
Enable/disable the SX127X LoRa IQ inverted mode. More... | |
void | sx127x_set_freq_hop (sx127x_t *dev, bool freq_hop_on) |
Sets the SX127X LoRa frequency hopping mode. More... | |
SX127X device default configuration | |
#define | SX127X_MODEM_DEFAULT (SX127X_MODEM_LORA) |
Use LoRa as default modem. | |
#define | SX127X_CHANNEL_DEFAULT (868300000UL) |
Default channel frequency, 868.3MHz (Europe) | |
#define | SX127X_HF_CHANNEL_DEFAULT (868000000UL) |
Use to calibrate RX chain for LF and HF bands. | |
#define | SX127X_RF_MID_BAND_THRESH (525000000UL) |
Mid-band threshold. | |
#define | SX127X_XTAL_FREQ (32000000UL) |
Internal oscillator frequency, 32MHz. | |
#define | SX127X_RADIO_WAKEUP_TIME (1U) |
In milliseconds [ms]. | |
#define | SX127X_TX_TIMEOUT_DEFAULT (30 * MS_PER_SEC) |
TX timeout, 30s. | |
#define | SX127X_RX_SINGLE (false) |
Single byte receive mode => continuous by default. | |
#define | SX127X_RX_BUFFER_SIZE (256) |
RX buffer size. | |
#define | SX127X_RADIO_TX_POWER (14U) |
Radio power in dBm. | |
#define | SX127X_EVENT_HANDLER_STACK_SIZE (2048U) |
Stack size event handler. | |
#define | SX127X_IRQ_DIO0 (1<<0) |
DIO0 IRQ. | |
#define | SX127X_IRQ_DIO1 (1<<1) |
DIO1 IRQ. | |
#define | SX127X_IRQ_DIO2 (1<<2) |
DIO2 IRQ. | |
#define | SX127X_IRQ_DIO3 (1<<3) |
DIO3 IRQ. | |
#define | SX127X_IRQ_DIO4 (1<<4) |
DIO4 IRQ. | |
#define | SX127X_IRQ_DIO5 (1<<5) |
DIO5 IRQ. | |
anonymous enum |
anonymous enum |
anonymous enum |
anonymous enum |
anonymous enum |
uint8_t sx127x_get_bandwidth | ( | const sx127x_t * | dev | ) |
Gets the SX127X bandwidth.
[in] | dev | The sx127x device descriptor |
uint32_t sx127x_get_channel | ( | const sx127x_t * | dev | ) |
Gets the channel RF frequency.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_coding_rate | ( | const sx127x_t * | dev | ) |
Gets the SX127X LoRa coding rate.
[in] | dev | The sx127x device descriptor |
bool sx127x_get_crc | ( | const sx127x_t * | dev | ) |
Checks if the SX127X CRC verification mode is enabled.
[in] | dev | The sx127x device descriptor |
bool sx127x_get_fixed_header_len_mode | ( | const sx127x_t * | dev | ) |
Gets the SX127X LoRa fixed header length mode.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_hop_period | ( | const sx127x_t * | dev | ) |
Gets the SX127X frequency hopping period.
[in] | dev | The sx127x device descriptor |
bool sx127x_get_iq_invert | ( | const sx127x_t * | dev | ) |
Checks if the SX127X LoRa inverted IQ mode is enabled/disabled.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_max_payload_len | ( | const sx127x_t * | dev | ) |
Gets the maximum payload length.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_op_mode | ( | const sx127x_t * | dev | ) |
Gets the SX127X operating mode.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_payload_length | ( | const sx127x_t * | dev | ) |
Gets the SX127X payload length.
[in] | dev | The sx127x device descriptor |
uint16_t sx127x_get_preamble_length | ( | const sx127x_t * | dev | ) |
Gets the SX127X preamble length.
[in] | dev | The sx127x device descriptor |
bool sx127x_get_rx_single | ( | const sx127x_t * | dev | ) |
Checks if the SX127X LoRa RX single mode is enabled/disabled.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_spreading_factor | ( | const sx127x_t * | dev | ) |
Gets the SX127X LoRa spreading factor.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_state | ( | const sx127x_t * | dev | ) |
Gets current state of transceiver.
[in] | dev | The sx127x device descriptor |
uint8_t sx127x_get_syncword | ( | const sx127x_t * | dev | ) |
Gets the synchronization word.
[in] | dev | The sx127x device descriptor |
uint32_t sx127x_get_time_on_air | ( | const sx127x_t * | dev, |
uint8_t | pkt_len | ||
) |
Computes the packet time on air in milliseconds.
[in] | dev | The sx127x device descriptor |
[in] | pkt_len | The received packet payload length |
uint8_t sx127x_get_tx_power | ( | const sx127x_t * | dev | ) |
Gets the SX127X TX radio power.
[in] | dev | The sx127x device descriptor |
int sx127x_init | ( | sx127x_t * | dev | ) |
Initializes the transceiver.
[in] | dev | The sx127x device descriptor |
void sx127x_init_radio_settings | ( | sx127x_t * | dev | ) |
Initialize radio settings with default values.
[in] | dev | The sx127x device pointer |
bool sx127x_is_channel_free | ( | sx127x_t * | dev, |
uint32_t | freq, | ||
int16_t | rssi_threshold | ||
) |
Checks that channel is free with specified RSSI threshold.
[in] | dev | The sx127x device structure pointer |
[in] | freq | channel RF frequency |
[in] | rssi_threshold | RSSI threshold |
uint32_t sx127x_random | ( | sx127x_t * | dev | ) |
Generates 32 bits random value based on the RSSI readings.
[in] | dev | The sx127x device structure pointer |
int16_t sx127x_read_rssi | ( | const sx127x_t * | dev | ) |
Reads the current RSSI value.
[in] | dev | The sx127x device structure pointer |
int sx127x_reset | ( | const sx127x_t * | dev | ) |
Resets the SX127X.
[in] | dev | The sx127x device descriptor |
void sx127x_set_bandwidth | ( | sx127x_t * | dev, |
uint8_t | bandwidth | ||
) |
Sets the SX127X bandwidth.
[in] | dev | The sx127x device descriptor |
[in] | bandwidth | The new bandwidth |
void sx127x_set_channel | ( | sx127x_t * | dev, |
uint32_t | freq | ||
) |
Sets the channel RF frequency.
[in] | dev | The sx127x device descriptor |
[in] | freq | Channel RF frequency |
void sx127x_set_coding_rate | ( | sx127x_t * | dev, |
uint8_t | coderate | ||
) |
Sets the SX127X LoRa coding rate.
[in] | dev | The sx127x device descriptor |
[in] | coderate | The LoRa coding rate |
void sx127x_set_crc | ( | sx127x_t * | dev, |
bool | crc | ||
) |
Enable/Disable the SX127X CRC verification mode.
[in] | dev | The sx127x device descriptor |
[in] | crc | The CRC check mode |
void sx127x_set_fixed_header_len_mode | ( | sx127x_t * | dev, |
bool | mode | ||
) |
Sets the SX127X to fixed header length mode (explicit mode)
[in] | dev | The sx127x device descriptor |
[in] | mode | The header mode |
void sx127x_set_freq_hop | ( | sx127x_t * | dev, |
bool | freq_hop_on | ||
) |
Sets the SX127X LoRa frequency hopping mode.
[in] | dev | The sx127x device descriptor |
[in] | freq_hop_on | The LoRa frequency hopping mode |
void sx127x_set_hop_period | ( | sx127x_t * | dev, |
uint8_t | hop_period | ||
) |
Sets the SX127X frequency hopping period.
[in] | dev | The sx127x device descriptor |
[in] | hop_period | The frequency hopping period |
void sx127x_set_iq_invert | ( | sx127x_t * | dev, |
bool | iq_invert | ||
) |
Enable/disable the SX127X LoRa IQ inverted mode.
[in] | dev | The sx127x device descriptor |
[in] | iq_invert | The LoRa IQ inverted mode |
void sx127x_set_max_payload_len | ( | const sx127x_t * | dev, |
uint8_t | maxlen | ||
) |
Sets the maximum payload length.
[in] | dev | The sx127x device descriptor |
[in] | maxlen | Maximum payload length in bytes |
void sx127x_set_modem | ( | sx127x_t * | dev, |
uint8_t | modem | ||
) |
Configures the radio with the given modem.
[in] | dev | The sx127x device descriptor |
[in] | modem | Modem to be used [0: FSK, 1: LoRa] |
void sx127x_set_op_mode | ( | const sx127x_t * | dev, |
uint8_t | op_mode | ||
) |
Sets the SX127X operating mode.
[in] | dev | The sx127x device descriptor |
[in] | op_mode | The new operating mode |
void sx127x_set_payload_length | ( | sx127x_t * | dev, |
uint8_t | len | ||
) |
Sets the SX127X payload length.
[in] | dev | The sx127x device descriptor |
[in] | len | The payload len |
void sx127x_set_preamble_length | ( | sx127x_t * | dev, |
uint16_t | preamble | ||
) |
Sets the SX127X LoRa preamble length.
[in] | dev | The sx127x device descriptor |
[in] | preamble | The LoRa preamble length |
void sx127x_set_rx | ( | sx127x_t * | dev | ) |
Sets the radio in reception mode.
[in] | dev | The sx127x device descriptor |
void sx127x_set_rx_single | ( | sx127x_t * | dev, |
bool | single | ||
) |
Enable/disable the SX127X LoRa RX single mode.
[in] | dev | The sx127x device descriptor |
[in] | single | The LoRa RX single mode |
void sx127x_set_rx_timeout | ( | sx127x_t * | dev, |
uint32_t | timeout | ||
) |
Sets the SX127X RX timeout.
[in] | dev | The sx127x device descriptor |
[in] | timeout | The RX timeout |
void sx127x_set_sleep | ( | sx127x_t * | dev | ) |
Sets the radio in sleep mode.
[in] | dev | The sx127x device descriptor |
void sx127x_set_spreading_factor | ( | sx127x_t * | dev, |
uint8_t | sf | ||
) |
Sets the SX127X LoRa spreading factor.
[in] | dev | The sx127x device descriptor |
[in] | sf | The spreading factor |
void sx127x_set_standby | ( | sx127x_t * | dev | ) |
Sets the radio in stand-by mode.
[in] | dev | The sx127x device descriptor |
void sx127x_set_state | ( | sx127x_t * | dev, |
uint8_t | state | ||
) |
Sets current state of transceiver.
[in] | dev | The sx127x device descriptor |
[in] | state | The new radio state |
void sx127x_set_symbol_timeout | ( | sx127x_t * | dev, |
uint16_t | timeout | ||
) |
Sets the SX127X LoRa symbol timeout.
[in] | dev | The sx127x device descriptor |
[in] | timeout | The LoRa symbol timeout |
void sx127x_set_syncword | ( | sx127x_t * | dev, |
uint8_t | syncword | ||
) |
Sets the synchronization word.
[in] | dev | The sx127x device descriptor |
[in] | syncword | The synchronization word |
void sx127x_set_tx | ( | sx127x_t * | dev | ) |
Sets the radio in transmission mode.
[in] | dev | The sx127x device descriptor |
void sx127x_set_tx_power | ( | sx127x_t * | dev, |
int8_t | power | ||
) |
Sets the SX127X transmission power.
[in] | dev | The sx127x device descriptor |
[in] | power | The TX power |
void sx127x_set_tx_timeout | ( | sx127x_t * | dev, |
uint32_t | timeout | ||
) |
Sets the SX127X TX timeout.
[in] | dev | The sx127x device descriptor |
[in] | timeout | The TX timeout |
void sx127x_setup | ( | sx127x_t * | dev, |
const sx127x_params_t * | params | ||
) |
Setup the SX127X.
[in] | dev | Device descriptor |
[in] | params | Parameters for device initialization |
void sx127x_start_cad | ( | sx127x_t * | dev | ) |
Start a channel activity detection.
[in] | dev | The sx127x device descriptor |