-
Notifications
You must be signed in to change notification settings - Fork 64
Use of Resources
The TTN library require several ESP32 resources to successfully implement the TTN and LoRaWAN protocol. These resources can be configured.
The communication between the ESP32 and the Semtech SX127x chip is mainly via SPI. As part of the initialization, the SPI bus / host (SPI_HOST
, HSPI_HOST
or VSPI_HOST
) must be configured by calling spi_bus_initialize()
. The pin numbers for SCK, MISO and MOSI are specified as part of the configuration.
The ESP32 has three SPI buses. Two can be used with ESP-IDF: HSPI
and VSPI
. Both can work with almost any pin. However, it is recommended to use the pins that can be routed through the IO MUX (instead of the GPIO matrix). They are:
Pin numbers for IO MUX routing
Pin name | HSPI | VSPI |
---|---|---|
SCLK | 14 | 18 |
MISO | 12 | 19 |
MOSI | 13 | 23 |
If the pins are already given and match one of the buses, configure the matching bus.
The pin number of NSS (the SPI chip select for the SX127x) is specified as a parameter to TheThingsNetwork::configurePins()
.
The SPI bus frequency can be changed by running make menuconfig
. The SX127x chips should work with up to 10 MHz.
The SPI bus can be used by other peripherials at the same time if they also use the official ESP-IDF SPI Master Driver. However, they should not block the bus with long SPI transactions. Otherwise, the timing for certain operations might be too far off leading to partial malfunctions.
In addition to the SPI communication, a few further connections between the SX127x and ESP32 are used. These connections are configured by calling TheThingsNetwork::configurePins()
.
The pins RXTX and RTS are optional. The chip can be used without connecting them. The pins DIO0 and DIO1 must be connected. The library requires them for proper operations. The other DIO pins are not used at all.
To implement the LoRaWAN protocol, a timer is needed. The library uses the High Resolution Timer of ESP-IDF.
Most of the LoRaWAN code is run in a background process with high priority (as the timing is crucial). The default priority is 10. It can be changed by running make menuconfig
.
The TTN library uses interrupts to listen to changes on the DIO0 and DIO1 lines. In order to install interrupt handler for individual GPIOs, ESP-IDF requires to install a GPIO ISR handler service by calling gpio_install_isr_service()
. As with any resource that can be jointly used by other parts of the app, it is left to the caller of the library to do so.
Non-volatile storage (NVS) is used to store and retrieve the provisioned keys (device EUI, app EUI and app key). Before NVS is accessed, the driver must be initialized by calling nvs_flash_init()
. Again, it is left to the caller of the library to do so.
The provisioning background task uses one of the UARTs. It can be shared with other features sending output to the UART. However, it will grab and process all input.
By running make menuconfig
it can configured. In particular, it can be configured:
- if it is enabled at all (if not, it's not even compiled)
- which UART to use
- if it should initialize the UART's baud rate and RX and TX pins or simply use the existing configuration
- the baud rate, RX and TX pins if they should be initialized