STM32CubeIDE -  DAC Block Diagram
Figure 1: STM32F429xx Block Diagram

The Digital to Analog converter (DAC) is a device, that is widely used for converting digital pulses to analog signals. There are two methods of converting digital signals to analog signals. These two methods are binary weighted method and R/2R ladder method. DACs are judged by its resolution. The resolution is a function of the number of binary inputs. The most common input counts are 8, 10, 12 etc. Number of data inputs decides the resolution of DAC. So if there are n digital input pin, there are 2n analog levels. So 8 input DAC has 256 discrete voltage levels.

The applications of Digital to Analog Converter include:

  • DAC’s are used in Digital Signal Processing.
  • They are also used in digital power supplies for Micro-controller.
  • DAC’s are used in digital potentiometers.
  • They are used in all digital data acquisition systems.
  • Used to tune RF Component’s such as TCXO

DAC Channels (STM32F429xx)
The device integrates two 12-bit Digital Analog Converters that can be used independently or simultaneously
(dual mode):
1. DAC channel1 with DAC_OUT1 (PA4) as output
2. DAC channel2 with DAC_OUT2 (PA5) as output

DAC data format
The DAC data format can be:
1. 8-bit right alignment using DAC_ALIGN_8B_R
2. 12-bit left alignment using DAC_ALIGN_12B_L
3. 12-bit right alignment using DAC_ALIGN_12B_R

DAC data value to voltage correspondence
The analog output voltage on each DAC channel pin is determined by the following equation: DAC_OUTx = VREF
+ * DOR / 4095 with DOR is the Data Output Register VEF+ is the input voltage reference (refer to the device
datasheet) e.g. To set DAC_OUT1 to 0.7V, use Assuming that VREF+ = 3.3V, DAC_OUT1 = (3.3 * 868) / 4095 =

Figure 2: DAC Formula for 12 bit DAC

For this blog we are going to use ADC in polling mode without averaging to demonstrate DAC functionality

Creating STM32 executable projects steps are available on this link , please follow steps 1 to 10 as per blog, here we will start from step 11. PA9 & PA10 Pin used for debugging purpose as UART Tx & UART Rx respectively.

11. Enable DAC Functionality

Go to System mode > Analog > DAC > Enable Out1 Configuration > keep all other settings as its

STM32CubeIDE - DAC  Functionality
Figure 3: DAC Functionality

12. Enable ADC Functionality

Go to System mode > Analog > ADC > Enable IN0 > keep all other settings as its

STM32CubeIDE - ADC  Functionality
Figure 3: ADC Functionality

13. Press below icon for code generation

STM32CubeIDE - Code generation
Figure 13: Code generation

14.For code demonstration we will connect DAC Output to ADC Input , already we have configured UART1 for debugging purpose.

15. Sample Code

  HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
  /* USER CODE END 2 */

  /* Infinite loop */
  while (1)

    /* USER CODE BEGIN 3 */

	  HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, dac_data);
	  HAL_Delay(500);	//2000 ms delay

	   if(HAL_ADC_PollForConversion(&hadc3, 50) == HAL_OK)
	 	  adcvalue = HAL_ADC_GetValue(&hadc3);
  /* USER CODE END 3 */

Software Tools:

  1. STM32CubeIDE
  2. STM32CubeMx
  3. Teraterm

Hardware Setup;

  1. STM32F429IDISCOVERY board
  2. Mini USB Cable
  3. Jumper wire


Successfully demonstrated DAC functionality with default configuration, for testing purpose we have used ADC in polling mode


  1. STM32 HAL Library
  2. STM32 UM1718 document

Similar topics:


Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: