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.
| 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 | — |
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.
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.
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 |
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.
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:
lorawan.bin, is located in the gcc/build directory.certification-otaa, certification-abp, class_b, multicast, and fuota.JOINED.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.
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:
MODEM_E_LORAWAN_REGION_AS923_GRP1MODEM_E_LORAWAN_REGION_AS923_GRP2MODEM_E_LORAWAN_REGION_AS923_GRP3MODEM_E_LORAWAN_REGION_AS923_GRP4MODEM_E_LORAWAN_REGION_AU915MODEM_E_LORAWAN_REGION_CN470MODEM_E_LORAWAN_REGION_EU868 (default)MODEM_E_LORAWAN_REGION_IN865MODEM_E_LORAWAN_REGION_KR920MODEM_E_LORAWAN_REGION_RU864MODEM_E_LORAWAN_REGION_US915MODEM_E_LORAWAN_REGION_WW2G4The 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.
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.
The application implements a relatively simple state machine based on received events:
Pressing the blue button immediately sends one uplink frame on port 102.