2026-01-28 4:03 AM - last edited on 2026-01-28 4:49 AM by Andrew Neil
Hello,
I’m new to embedded systems and currently learning STM32 + LoRa.
I’m using two NUCLEO-F411RE boards and two RA-02 (SX1278) LoRa modules. My goal is to establish basic point-to-point communication.
I initially tried using a LoRa.h library, but I couldn’t get it working reliably. To reduce complexity, I decided to verify SPI communication first, before dealing with LoRa TX/RX logic.
However, SPI itself does not appear to work as expected, so it’s unclear whether the issue is:
Below are two minimal examples:
I would appreciate feedback on:
Minimal SPI test (RegVersion check)
#include "main.h"
#include "spi.h"
#include "gpio.h"
#define REG_VERSION 0x42
uint8_t sx1278_read_reg(uint8_t reg)
{
uint8_t tx[2] = { reg & 0x7F, 0x00 };
uint8_t rx[2] = { 0 };
HAL_GPIO_WritePin(NSS_GPIO_Port, NSS_Pin, GPIO_PIN_RESET);
HAL_SPI_TransmitReceive(&hspi1, tx, rx, 2, HAL_MAX_DELAY);
HAL_GPIO_WritePin(NSS_GPIO_Port, NSS_Pin, GPIO_PIN_SET);
return rx[1];
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_SPI1_Init();
uint8_t version;
while (1)
{
version = sx1278_read_reg(REG_VERSION); // expect 0x12
HAL_Delay(1000);
}
}
Minimal LoRa.h initialization (no TX/RX)
is in this repository: LoRa/Src/main.c at master · SMotlaq/LoRa
Edited to apply source code formatting - please see How to insert source code for future reference.