This project implements a diversity gain engine for an embedded system using STM32 microcontrollers. It involves initializing and configuring several peripherals, such as ADC, UART, SPI, and LoRa modules, to implement a diversity gain engine algorithm with three different combining techniques: Equal Gain Combining (EGC), Maximum Likelihood Combining (MLC), and Selection Combining (SC).
-
System Clock Configuration (
SystemClock_Config
):- Configures the system clock for the microcontroller.
-
Peripheral Initialization:
- ADC Initialization (
MX_ADC1_Init
): Configures the ADC1 to read three channels using DMA. - SPI Initialization (
MX_SPI3_Init
): Configures the SPI3 interface for communication with the LoRa module. - UART Initialization (
MX_USART1_UART_Init
): Configures USART1 for serial communication. - DMA Initialization (
MX_DMA_Init
): Configures the DMA for handling ADC data transfers. - GPIO Initialization (
MX_GPIO_Init
): Configures the general-purpose I/O pins.
- ADC Initialization (
-
Initialization:
HAL_Init()
: Initializes the HAL library.SystemClock_Config()
: Configures the system clock.- Peripheral initialization functions.
LoRa_Module_Setting()
: Configures the LoRa module.
-
ADC Start:
HAL_ADC_Start_DMA(&hadc1, (uint32_t *) rawValues, 3)
: Starts the ADC in DMA mode to read values intorawValues
.
-
Main Loop:
- Continuously calls
DiversityGainEngineInit()
to execute the diversity gain engine logic.
- Continuously calls
-
DiversityGainEngineInit():
- Collects ADC readings and estimates threshold voltage.
- Selects the combining technique based on the estimated threshold voltage.
-
Combining Techniques:
ThresholdVoltageEstimator()
: Estimates the threshold voltage.CombiningTechniqueSelection()
: Selects the appropriate combining technique (EGC, MLC, SC) and performs data transmission using the selected technique.EGC_Engine()
: Implements Equal Gain Combining.MLC_Engine()
: Implements Maximum Likelihood Combining.SC_Engine()
: Implements Selection Combining.SC_EngineReception()
: Handles reception for the SC technique.
-
LoRa_Module_Setting():
- Initializes the LoRa module with specified parameters.
- Starts continuous receiving mode.
-
LoRa_Transceiver_Init():
- Demonstrates sending and receiving data using the LoRa module.
-
HAL_ADC_ConvCpltCallback():
- Sets a flag
convCompleted
when ADC conversion is complete.
- Sets a flag
-
Error_Handler():
- Infinite loop to indicate an error state.
- USE_FULL_ASSERT:
- Provides assertion handling for debugging purposes.
-
Stm32:
- STM32 Nucleo-32 development board with STM32L432KC MCU.
- Link
-
LoRa Module:
- Ra-02 LoRa module with SX1278 chip.
- link
- Github-LoRa:
- Ra-02 LoRa module (SX1278) library for STM32 (ARM processors) using HAL drivers.
- Link
- Github-VLC:
- Diversity-Gain-VLC
- link
This code provides a complete implementation of a diversity gain engine for an embedded system using STM32 microcontrollers. It includes the initialization and configuration of several peripherals such as ADC, UART, SPI, and LoRa modules. The diversity gain engine algorithm implements three combining techniques (EGC, MLC, SC) and continuously processes and transmits sensor data. Each function can be customized based on specific requirements or hardware specifications.