STM32 HAL driver for the AD7124 24-bit Sigma-Delta ADC using SPI communication.
- Fully STM32 HAL compatible — supports all STM32 MCU series (F0–F7, G0/G4, H7, L0–L5, U0/U5)
- Interrupt-driven — uses an external interrupt on DOUT/RDY to read samples instead of polling mode
- Full register access & calibration — supports reading/writing all registers, including internal calibration
- MISRA-C-inspired design — clean, safe, and portable code for embedded and safety-critical applications
- Modular and portable — compatible with STM32CubeIDE, Keil, IAR, and Makefile-based workflows
- Easy integration — minimal dependencies and simple setup
Set the following parameters:
- Mode: Full-Duplex Master
- Data Size: 8-bit
- First Bit: MSB First
- Clock Polarity (CPOL): High
- Clock Phase (CPHA): 2nd Edge
- Add a GPIO Output pin for the CS signal.
- GPIO Mode: External Interrupt on Falling Edge
- Pull Configuration: Pull-Up
- Enable the EXTI line in NVIC settings
- Include
ad7124.h
in your application code - Add
ad7124.c
andad7124_config.c
to your compiler sources - Define the STM32 MCU series macro in
ad7124_config.h
- Add the library folder to your compiler's include paths
In your application code, extern
the following global variables:
extern AD7124_ConfigTypeDef AD7124_Handler;
extern uint32_t AD7124_ChannelSamples[AD7124_ENABLED_CHANNELS];
extern AD7124_RegisterTypeDef configA;
Also, define a flag for DOUT/RDY readiness:
volatile uint8_t ad7124_rdy_flag = 0U;
Then, in your stm32yyxx_it.c interrupt handler, do the following:
extern volatile uint8_t ad7124_rdy_flag;
void EXTI_IRQHandler(void)
{
ad7124_rdy_flag = 1U;
}
Each function returns an AD7124_StatusTypeDef status code.
Reads a register from the AD7124 via SPI
Writes a value to a register on the AD7124
Performs a software reset of the AD7124 over SPI
Initializes and applies a full configuration to the AD7124
Reads conversion results and updates the AD7124_ChannelSamples array
Checks and returns AD7124 error status
Executes internal gain and offset calibration routines
A complete working example is available in the example folder.
This project is licensed under the MIT License.
Amirhossein Askari
📧 theamiraskarii@gmail.com
🔗 GitHub Profile