LoRaWAN Class A Application for the Ra-11 Module

This example demonstrates how to use an STM32L476RG to drive the Ra-11 module and configure it to join a LoRaWAN network in Class A mode. After the device successfully joins the network, uplink data can be reported by pressing a button.

1. Hardware Preparation

1.1. Required Hardware

No. Hardware Description Purchase Link
1 MCU development board STM32L476RG, NUCLEO-L476RG recommended
2 Ra-11 module LoRa Modem-E module to be driven Taobao link
3 TTL module Ai-Thinker FT232TTL, used for serial port log Taobao link
4 Button User button, or use the on-board blue button PC13 on the NUCLEO board
5 Dupont wires / power supply 3.3V power supply, common ground

1.2. Wiring Between MCU and Ra-11

See Inc/boards/board-config.h for pin definitions.

MCU (STM32L476RG) Signal Ra-11 Module Description
PA5 SCLK SCK / SCLK SPI clock
PA6 MISO MISO SPI master input / slave output
PA7 MOSI MOSI SPI master output / slave input
PA8 NSS NSS / CS SPI chip select, active low
PA0 RESET RESET / NRESET Module reset
PB3 BUSY BUSY SPI busy indicator
PB4 EVENT EVENT / DIO Event interrupt (network join, downlink, etc.)
3V3 VCC VCC / 3V3 3.3V power supply
GND GND GND Common ground

If the module has an antenna connector, connect the antenna before powering on and transmitting.

1.3. Wiring Between MCU and TTL (FT232)

The serial port is used to print logs. (The baud rate is 921600, 8N1.) The MCU-side pins are UART_TX=PA2 and UART_RX=PA3.

MCU(STM32L476RG) Signal FT232 TTL Module Description
PA2 UART_TX RXD MCU transmit → TTL receive
PA3 UART_RX TXD TTL transmit → MCU receive
GND GND GND Common ground
USB Connect to a PC for viewing logs with a serial terminal tool

Connect TX and RX crosswise. Do not connect TX to TX on both ends.

1.4. Button Wiring

In the application, the button is defined as EXTI_BUTTON = PC_13, triggered on the falling edge.

MCU (STM32L476RG) Signal Button Description
PC13 EXTI_BUTTON One end of the button Immediately sends an uplink on port 102 when pressed
GND GND The other end of the button Active low

2. Obtaining and Using the Driver Resources

2.1. Obtaining the Resources

This SDK is used to drive the Ra-11 module to join a LoRaWAN network. The source repository is:

Example for obtaining the code:

git clone https://github.com/Ai-Thinker-Open/Ra-11_modem-e.git
cd Ra-11_modem-e

For repository documentation and more example descriptions, refer to the GitHub page above.

2.2. Build and Program

Install the ARM GCC toolchain first. (The project is based on the GNU Arm Embedded Toolchain.) Build in the gcc directory:

cd gcc
make clean
make APP=lorawan

Example for specifying a region:

make clean
make APP=lorawan EXTRAFLAGS='-DLORAWAN_REGION_USED=MODEM_E_LORAWAN_REGION_AS923_GRP1'

Notes:

2.3. Serial Port and Runtime

  1. Complete the hardware wiring according to Chapter 1, then power on the device.
  2. Open a serial tool with the following parameters: 921600 / 8 / 1 / None.
  3. If the credential triplet has already been registered on the gateway/platform, the device will automatically join the network after startup. Wait for JOINED.
  4. By default, an uplink is sent approximately every 30 seconds. Pressing the PC13 button immediately sends one uplink frame.

3. Program Runtime Description

After startup, the device automatically sends a Join-Request to the LoRaWAN network server.

After receiving a Join-Accept, it sends uplinks periodically.

Pressing the PC13 button immediately sends one uplink frame on port 102.

4. Configuration

4.1. LoRaWAN Configuration

Several constants are defined at the beginning of main_lorawan.c, common_app_configuration.h, or lorawan_commissioning.h. You can configure the LoRaWAN parameters of the application by setting these values.

Constant Description
PERIODICAL_UPLINK_DELAY_S Periodic uplink alarm delay, in seconds.
EXTI_BUTTON Pin name corresponding to the button.
LORAWAN_APP_DATA_MAX_SIZE User application data buffer size.
LORAWAN_REGION_USED LoRaWAN regulatory region.

Supported values of LORAWAN_REGION_USED:

4.2. Join Configuration

The LR1121 is preconfigured with ChipEUI/DevEUI and JoinEUI. If USE_LR11XX_CREDENTIALS in lorawan_commissioning.h is set to true, the application will use these identifiers.

You can also configure them manually: set USE_LR11XX_CREDENTIALS to false, and modify LORAWAN_DEVICE_EUI, LORAWAN_JOIN_EUI, LORAWAN_NWK_KEY, and LORAWAN_APP_KEY in Inc/apps/lorawan_commissioning/lorawan_commissioning.h.

5. Usage

5.1. Serial Console

After completing the static configuration, the application can run without manual intervention.

Information is output to the serial console. The initial output includes DevEUI, AppEUI/JoinEUI, and PIN, which can be used to register the device in the LoRa Cloud Device Join service.

6. Additional Notes

6.1. Application Main Loop

The application implements a relatively simple state machine based on received events:

Pressing the blue button immediately sends one uplink frame on port 102.