esp-idf driver for SX1276
Find a file
2020-02-26 20:30:10 -08:00
include include DIO0 mode for CAD 2020-02-22 08:33:50 -08:00
main remove some over the top verbose logging 2020-02-26 20:30:10 -08:00
test large changeset 2020-02-20 22:05:24 -08:00
.gitlab-ci.yml no tests at the moment 2020-02-22 13:49:05 -08:00
component.mk initial commit.... after 6 months 2018-07-28 11:33:15 -07:00
Kconfig default lora to enabled 2018-07-28 13:43:05 -07:00
Makefile initial commit.... after 6 months 2018-07-28 11:33:15 -07:00
README.md update README 2020-02-23 11:47:08 -08:00

ESP32 LoRa (SX127*)

Provides SPI driver for SX1276/SX1278 LoRa radio

Install

Designed to be used as an esp-idf component. Suggested usage is with git submodule

git submodule add https://gitlab.com/morganrallen/esp32-lora.git components/esp32-lora/
git submodule init
git submodule update

Configure

Uses built in KConfig for configuration. Run make menuconfig and find config under Component config -> LORA32. Defaults targeted to TTGO LoRa OLED boards.

Use

This is the most basic usage. Setting up the LoRa instance, setting it's receive handler, running init then sending a message.

  #include <stdio.h>
  #include <string.h>

  #include "esp32-lora.h";

  lora32_cfg_t lora;

  static void handle_lora_receive(uint8_t size) {
    char *message = malloc(size+1);

    lora32_read_data(&lora, message);

    // ensure null termination
    message[size] = '\0';
    
    printf("msg: %s\n", message);
  }

  void app_main() {
    lora = lora32_create();
    lora.receive = &handle_lora_receive;

    lora32_init(&lora);

    lora32_send(&lora, "Hello, LoRa", 11);
  }

API

static lora32_cfg_t lora32_create()

Creates a new LoRa instance.

uint8_t lora32_init(lora32_cfg_t *config)

Initialized LoRa instance. This configures GPIOs, SPI, LoRa radio and receive handlers.

Returns 1 on success.

void lora32_set_coding_rate(lora32_cfg_t *lora, uint8_t d)

Set Coding Rate.

Accepts 5-8.

uint8_t lora32_data_available(lora32_cfg_t *lora)

Returns number of bytes available in FIFO buffer.

void lora32_send(lora32_cfg_t *config, uint8_t *data, uint8_t len)

Transmits data over the LoRa radio. Puts DIO0 into TXDONE mode.

void lora32_set_spreadfactor(lora32_cfg_t *lora, uint8_t factor)

Sets LoRa Spread Factor.

Accepts 6-12.

void lora32_dump_regs(lora32_cfg_t *lora)

Dumps all registers from SX1276.

void lora32_read_data(lora32_cfg_t *lora, uint8_t *data)

Reads data out of FIFO buffer. This would typically be called after the callback received is triggered.

void lora32_enable_continuous_rx(lora32_cfg_t *lora)

Enables continuous receive mode. If a receive callback has been setup, it will be trigger on any incoming data until either an OP_MODE or DIO0 mode are change.

void lora32_enable_single_rx(lora32_cfg_t *lora)

  • NOTE This requires DIO1 for complete functionality.
  • NOTE Implenentation incomplete.

Enables single receive mode. Will either trigger RXDONE on DIO0 or RXTIMEOUT on DIO1

void lora32_enable_cad(lora32_cfg_t *lora)

Enables Channel Activity Detection. Will trigger callback cad_done with bool detected on completion. If activity was detected, it will also trigger cad_detected

Callbacks

lora32_cfg_t provides several callbacks based on DIO0 interrupts. Most functionality is provided through these, favoring async operations over syncronous polling.

lora32_cfg_t->receive(uint8_t size)

Triggered from RXCONTINUOUS and RXSINGLE modes. Provides the number of bytes available. Should be followed up with a call to lora32_read_data to retrieve data from FIFO buffer.

lora32_cfg_t->tx_done()

Triggers after call to lora32_send completes, as long as DIO0 mode has not been changed.

lora32_cfg_t->cad_done(bool detected)

Triggers after call to lora32_enable_cad completes (ie times out) or channel activity is detected. bool detected will reflect these two states.

lora32_cfg_t->cad_detected()

Triggers after call to lora32_enable_cad successfully detects channel activity.