This project demonstrates how to interface the AD5621 12-bit Digital-to-Analog Converter (DAC) with an STM32F103C6 microcontroller via SPI communication to generate precise sinusoidal waveforms.
Generating analog signals from digital data is crucial in applications like audio processing, sensor simulation, and control systems.
The DAC provides high precision, low power consumption, and rail-to-rail output, making it ideal for portable or battery-powered devices. By integrating it with STM32, the system can output accurate and stable sinusoidal voltages for testing, simulation, or control purposes.
Overview of the AD5621 DAC
- The AD5621 is a nanoDAC® family member featuring:
- 12-bit resolution
- Buffered rail-to-rail output (0V → VDD)
- Low power consumption with a power-down mode (0.2 µA)
- Operating voltage range: 2.7V – 5.5V
- Power-on reset to 0V
- 3-wire SPI-compatible serial interface (up to 30 MHz)
Its on-chip precision output amplifier ensures smooth analog signal generation, and the fast SPI interface allows real-time waveform updates.
STM32CubeMX Setup- MCU Selection: STM32F103C6 (72 MHz clock)
- SPI1 Configuration:
-Mode: Full-Duplex Master-Prescaler: 8 (9 MHz SPI clock)-CPOL: Low, CPHA: 1 Edge
- GPIO Configuration:
-PA4 → SYNC-PA6 → LDAC (optional)
- Generate initialization code in STM32CubeIDE.
Key Functions
- DAC Initialization:
-ad5621_Init(&hspi1, GPIO_PIN_4, GPIOA);-Initialize the AD5621 DAC by specifying the SPI handle, chip select pin, and GPIO port.
- Generate Sine Wave Table:
-ad5621_GenerateSineTable(sine_table, SINE_POINTS);-Precompute digital values representing points of a sine wave for smooth analog output.
- Send Value to DAC:
-ad5621_SendToDAC(sine_table[i]); // Send ith sine point to DAC-Transmit a 16-bit digital value to the DAC over SPI to produce the corresponding analog voltage.
- Main Loop (Generate Sine Wave):
-Iterate through the sine table continuously, sending each value to the DAC with a short delay to create a smooth waveform.
while (1)
{
for (int i = 0; i < SINE_POINTS; i++)
{
ad5621_SendToDAC(sine_table[i]);
HAL_Delay(1); // Adjust delay to set waveform frequency
}
}Components
- STM32F103C6 microcontroller
- AD5621 DAC
- Oscilloscope
Connections
- Match SPI pins: PA5 → SCLK, PA6 → MISO, PA7 → MOSI, PA4 → SYNC
- Connect VREF to 2.5V source
Simulation Steps
- Load the generated.hex file into STM32 in Proteus.
- Observe a sinusoidal waveform on the oscilloscope: 1 Vpp @ 50 Hz.
If you have any questions or suggestions, don’t hesitate to leave a comment below.





Comments