step by step to interface your lorawan for any STM32 mcu & SX1276
go to Clock Configuration, set LSE 32.768 source for RTC
Hour Format = 24H, AsynchPrediv = 3, SynchPrediv = 3; Calender time Format = BIN data, DaylightSaving OFF, Storeoperation RESET; no alarm
LORA_D0
, LORA_D1
, LORA_D2
, LORA_D3
,
go to NVIC, check related interrupt EXT line, make sure all EXT lines are not enabled
LORA_RST
, spi nss pin LORA_NSS
, to OUTPUT, PUSH-PULL, output HIGHuse default 8-bit, MSB first, CPOL = LOW, CPHA = 1 Edge, use software NSS change prescaller, set baudrate to 2 Mbits/s
Generate peripheral initialization as a pair of ".c/.h" ...
mac
, board
, sx1276
to project root folder, copy lorawan.h
to Core/inc
, copy lorawan.c
to Core/src
C/C++ general
-> path and symbols
,
go to
includes
, add -> inputmac
, then addmac/crypto
,board
andsx1276
go toSource location
, add folder -> selectmac
,board
andsx1276
go toSymbols
, add nameUSE_BAND_915
, the value just leave empty apply, apply and close
board.h
, check line #include "stm32l1xx_hal.h"
, make sure it fits your stm32 mcu series, otherwise change it.main.c
#include "board.h"
#include "lorawan.h"
addstatic Gpio_t led1;
before main()
14, change board.h
gpio pin definitions based on your demo board
#define RADIO_DIO_0 PB_10
#define RADIO_DIO_1 PB_2
#define RADIO_DIO_2 PB_0
#define RADIO_DIO_3 PB_1
#define RADIO_RESET PB_11
#define RADIO_NSS PA_4
#define RADIO_SCLK PA_5
#define RADIO_MISO PA_6
#define RADIO_MOSI PA_7
add
GpioInit( &led1, PB_8, PIN_OUTPUT, PIN_PUSH_PULL, PIN_NO_PULL, 0 );
before main while, (assume PB_8 control LED of your demo board) addGpioWrite(&led1, 1);
compile and run the code, if the LED got light up, congratilations! go to step 15, otherwise fix errors possible compile error issue:GpioMcuSetInterrupt()
-> exi irq name andBoard_Init()
-> alarm irq name, different series of mcu got different interrupt definition, refer the stm32 header file.
led1
definition,
static void keyCallback(void){
GpioToggle(&led1);
}
static Gpio_t key;
DioIrqHandler *keyHandler = keyCallback;
add code after led1
initialization, assume PA_12 pin is input of your demo board
GpioInit( &key, PA_12, PIN_INPUT, PIN_PUSH_PULL, PIN_PULL_UP, 0 );
GpioSetInterrupt( &key, IRQ_FALLING_EDGE, IRQ_HIGH_PRIORITY, keyHandler );
compile and run the code, if short pin PA_12 to GND, you will see led light flip, congratilations! go to step 16, otherwise fix errors possible miss interrupt error issue:
board-gpio.c
,EXTI0_1_IRQHandler
,HAL_GPIO_EXTI_Callback
, different series mcu might have different default names
led1
initialization,
Board_Init();
uint32_t t = Board_Timer_Test(2000);
if((t>2000 && t-2000<5)||(t<2000 && 2000-t<5)||(t==2000)){
GpioWrite(&led1, 0);
}
compile and run the code, if the led flip, congratilations! go to step 17, otherwise fix errors possible miss interrupt error issue:
board-timer.c
,RTC_Alarm_IRQHandler
, different series mcu might have different default names, such asRTC_IRQHandler
possible timer does't match ticker issue: external clock frequency definition error, check Clock Configuration,
add
LoraWAN_Init();
afterBoard_Init();
addLoraWAN_Loop();
inside main while loop start debugging LORAWAN now!!! most common issues: interrupt level, rx windows mismatch with the tx for Class Afinish