{"id":3034,"date":"2024-11-23T13:49:38","date_gmt":"2024-11-23T13:49:38","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=3034"},"modified":"2024-11-23T13:49:39","modified_gmt":"2024-11-23T13:49:39","slug":"getting-started-with-stm32h5-arm-cortex-m33-dac-in-polling-mode","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=3034","title":{"rendered":"Getting Started with STM32H5 ARM Cortex M33: DAC in Polling Mode"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"725\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-1024x725.webp\" alt=\"\" class=\"wp-image-3035\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-1024x725.webp 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-300x212.webp 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-768x544.webp 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-750x531.webp 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-400x283.webp 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4-250x177.webp 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/STM32-u5-1-1-4.webp 1141w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>In this guide on DAC (Digital to Analog Converter), we shall see the feature of the DAC on STM32H5, the functional block diagram and how to develop the driver using STM32CubeMX.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What is DAC.<\/li>\n\n\n\n<li>Configure DAC.<\/li>\n\n\n\n<li>Firmware development.<\/li>\n\n\n\n<li>Results.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p>In&nbsp;electronics, a&nbsp;<strong>digital-to-analog converter<\/strong>&nbsp;(<strong>DAC<\/strong>,&nbsp;<strong>D\/A<\/strong>,&nbsp;<strong>D2A<\/strong>, or&nbsp;<strong>D-to-A<\/strong>) is a system that converts a&nbsp;digital signal&nbsp;into an&nbsp;analog signal. An&nbsp;analog-to-digital converter&nbsp;(ADC) performs the reverse function.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>STM32 DAC Brief&nbsp; &nbsp;<\/strong><\/h3>\n\n\n\n<p>In STM32H563, the DAC module is a 12-bit, voltage-output digital-to-analog converter. The DAC can be configured in 8- or 12-bit mode and may be used in conjunction with the DMA controller. In 12-bit mode, the data could be left- or right-aligned. The DAC features up to two output channels, each with its own converter. In dual DAC channel mode, conversions could be done independently or simultaneously when both channels are grouped together for synchronous update operations.<\/p>\n\n\n\n<p>The DAC_OUTx pin can be used as general-purpose input\/output (GPIO) when the DAC output is disconnected from the output pad and connected to on-chip peripherals. The DAC output buffer can be optionally enabled to allow a high drive output current. An individual calibration can be applied to each DAC output channel. The DAC output channels support a low power mode, the Sample and Hold mode.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">DAC Features:<\/h3>\n\n\n\n<p>The two 12-bit buffered DAC channels can be used to convert two digital signals into two analog voltage signal outputs.<\/p>\n\n\n\n<p>This dual digital Interface supports the following features:<\/p>\n\n\n\n<p>One DAC interface, maximum two output channels<\/p>\n\n\n\n<p>Input voltage reference from VREF+ pin or internal VREFBUF reference<\/p>\n\n\n\n<p>Left or right data alignment in 12-bit mode<\/p>\n\n\n\n<p>Synchronized update capability<\/p>\n\n\n\n<p>Noise-wave and Triangular-wave generation<\/p>\n\n\n\n<p>Dual DAC channel for independent or simultaneous conversions<\/p>\n\n\n\n<p>DMA capability for each channel including DMA underrun error detection<\/p>\n\n\n\n<p>Double data DMA capability to reduce the bus activity<\/p>\n\n\n\n<p>External triggers for conversion<\/p>\n\n\n\n<p>DAC output channel buffered\/unbuffered modes<\/p>\n\n\n\n<p>Buffer offset calibration<\/p>\n\n\n\n<p>Sample and hold mode for low power operation in Stop mode<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Functional Block Diagram:<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"933\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-933x1024.png\" alt=\"\" class=\"wp-image-3036\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-933x1024.png 933w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-273x300.png 273w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-768x843.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-1399x1536.png 1399w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-1150x1263.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-750x824.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-400x439.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM-250x275.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.25.06\u202fPM.png 1550w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>The DAC includes up to two separate output channels. Each output channel can be connected to on-chip peripherals such as comparator, operational amplifier, and ADC (if available). In this case, the DAC output channel can be disconnected from the DAC_OUTx output pin and the corresponding GPIO can be used for another purpose. The DAC output can be buffered or not.<\/p>\n\n\n\n<p>Each DAC channel can be powered on by setting its corresponding ENx bit in the DAC_CR register. The DAC channel is then enabled after a t<sub>WAKEUP<\/sub>&nbsp;startup time.<\/p>\n\n\n\n<p><strong>STM32 DAC Data Format<\/strong><\/p>\n\n\n\n<p>Depending on the selected configuration mode, the data have to be written into the specified register as described below:<\/p>\n\n\n\n<p><strong>Single DAC channel<\/strong><\/p>\n\n\n\n<p>There are three possibilities:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>8-bit right alignment: the software has to load data into the DAC_DHR8Rx[7:0] bits (stored into the DHRx[11:4] bits)<\/li>\n\n\n\n<li>12-bit left alignment: the software has to load data into the DAC_DHR12Lx [15:4] bits (stored into the DHRx[11:0] bits)<\/li>\n\n\n\n<li>12-bit right alignment: the software has to load data into the DAC_DHR12Rx [11:0] bits (stored into the DHRx[11:0] bits)<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/deepbluembedded.com\/wp-content\/uploads\/2020\/06\/STM32-DAC-Tutorial-DAC-Data-Alignment-And-Format.jpg?ezimgfmt=rs:699x206\/rscb6\/ngcb6\/notWebP\" alt=\"\" class=\"wp-image-4888\" \/><\/figure>\n\n\n\n<p>Depending on the loaded DAC_DHRyyyx register, the data written by the user is shifted and stored into the corresponding DHRx (data holding registerx, which are internal non-memory mapped registers). The DHRx register is then loaded into the DORx register either automatically, by software trigger, or by an external event trigger.<br><strong>STM32 DAC Conversion<\/strong><\/p>\n\n\n\n<p>The DAC_DORx cannot be written directly and any data transfer to the DAC channelx must be performed by loading the DAC_DHRx register (write operation to DAC_DHR8Rx, DAC_DHR12Lx, DAC_DHR12Rx, DAC_DHR8RD, DAC_DHR12RD or DAC_DHR12LD).<\/p>\n\n\n\n<p>Data stored in the DAC_DHRx register are automatically transferred to the DAC_DORx register after one APB1 clock cycle if no hardware trigger is selected (TENx bit in DAC_CR register is reset). However, when a hardware trigger is selected (TENx bit in DAC_CR register is set) and a trigger occurs, the transfer is performed three APB1 clock cycles after the trigger signal.<\/p>\n\n\n\n<p>When DAC_DORx is loaded with the DAC_DHRx contents, the analog output voltage becomes available after a time t<sub>SETTLING<\/sub>&nbsp;that depends on the power supply voltage and the analog output load.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"418\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-1024x418.png\" alt=\"\" class=\"wp-image-3037\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-1024x418.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-300x122.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-768x314.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-1536x627.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-1150x470.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-750x306.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-400x163.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM-250x102.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/Screenshot-2024-11-23-at-4.26.31\u202fPM.png 1548w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>STM32 DAC Output Voltage Equation (Formula)<\/strong><\/p>\n\n\n\n<p>Digital inputs are converted to output voltages on a linear conversion between 0 and V<sub>REF<\/sub>+. The analog output voltages on each DAC channel pin are determined by the following equation:<\/p>\n\n\n\n<p>DACoutput = (V<sub>REF<\/sub>+) x (DOR\/4096)<\/p>\n\n\n\n<p><strong>STM32 DAC Channel Modes of Operation&nbsp;<\/strong><\/p>\n\n\n\n<p>Each DAC channel can be configured in Normal mode or Sample and Hold mode. The output buffer can be enabled to allow a high drive capability. Before enabling the output buffer, the voltage offset needs to be calibrated. This calibration is performed at the factory (loaded after reset) and can be adjusted by software during application operation.<\/p>\n\n\n\n<p><strong>Normal Mode<\/strong><\/p>\n\n\n\n<p>In Normal mode, there are four combinations, by changing the buffer state, and by changing the DAC_OUTx pin interconnections.<\/p>\n\n\n\n<p>To enable the output buffer, the MODEx[2:0] bits in DAC_MCR register should be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>000: DAC is connected to the external pin<\/li>\n\n\n\n<li>001: DAC is connected to the external pin and to on-chip peripherals<\/li>\n<\/ul>\n\n\n\n<p>To disable the output buffer, the MODEx[2:0] bits in DAC_MCR register should be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>010: DAC is connected to the external pin<\/li>\n\n\n\n<li>011: DAC is connected to on-chip peripherals<\/li>\n<\/ul>\n\n\n\n<p><strong>Sample And Hold Mode<\/strong><\/p>\n\n\n\n<p>In sample and Hold mode, the DAC core converts data on a triggered conversion, then, holds the converted voltage on a capacitor. When not converting, the DAC cores and buffer are completely turned off between samples and the DAC output is tri-stated, therefore reducing the overall power consumption. A new stabilization period, which value depends on the buffer state, is required before each new conversion.<\/p>\n\n\n\n<p>In this mode, the DAC core and all corresponding logic and registers are driven by the low-speed clock (LSI) in addition to the APB1 clock, allowing to use the DAC channels in deep low power modes such as Stop mode.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. DAC Configuration:<\/h2>\n\n\n\n<p>We start of by creating new project with name of DAC, for how to create new project, please refer to this guide <a href=\"https:\/\/blog.embeddedexpert.io\/?p=2789\" data-type=\"link\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=2789\">here<\/a>.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>After the project creation, we shall enable the DAC as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"862\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-1024x862.jpg\" alt=\"\" class=\"wp-image-3038\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-1024x862.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-300x253.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-768x647.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-1150x969.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-750x632.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-400x337.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39-250x211.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-30-39.jpg 1534w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-medium-font-size\">From left menu, select Analog, then DAC1. After that, OUT1 is connected to only external pin. This will enable PA4 since it is the only pin that supports DAC out and PA5 for channel 2.<\/p>\n\n\n\n<p>From parameter Settings:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>DAC high frequency mode to disabled for now.<\/li>\n\n\n\n<li>Mode to normal mode.<\/li>\n\n\n\n<li>Enable output buffer.<\/li>\n\n\n\n<li>DMA to disabled.<\/li>\n\n\n\n<li>Singed format to disabled.<\/li>\n\n\n\n<li>Trigger to none since we shall trigger the DAC using software.<\/li>\n\n\n\n<li>User trimming to factory trimming.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"936\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-1024x936.jpg\" alt=\"\" class=\"wp-image-3039\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-1024x936.jpg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-300x274.jpg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-768x702.jpg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-1150x1051.jpg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-750x686.jpg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-400x366.jpg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06-250x229.jpg 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/2024-11-23_16-34-06.jpg 1166w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Thats all for the configuration. Save the project and this shall generate the code.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. Firmware Development:<\/h2>\n\n\n\n<p>In main.c file, in user code begin 2 in the main function, we shall start the DAC as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_DAC_Start(&amp;hdac1, DAC_CHANNEL_1);<\/pre><\/div>\n\n\n\n<p>The function shall take two parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Instant to the DAC, hdac1 in this case.<\/li>\n\n\n\n<li>The channel of the DAC, DAC_CHANNEL_1.<\/li>\n<\/ul>\n\n\n\n<p>In user code begin 3 in while loop, we can vary the voltage as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  for (int i=0;i&lt;4095;i++)\n\t  {\n\t\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, i);\n\t  }\n\n\t  for (int i=4095;i&gt;0;i--)\n\t  {\n\t\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, i);\n\t  }<\/pre><\/div>\n\n\n\n<p>The following function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, i);<\/pre><\/div>\n\n\n\n<p>Take four parameters as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Instant to DAC, hdac1 in this case.<\/li>\n\n\n\n<li>Channel of the DAC, Channel 1 in this case.<\/li>\n\n\n\n<li>Alignment, you have the following three options: 12bit both left and right and 8-bit right alignment. In this case, we shall use 12bit right alignment.<\/li>\n\n\n\n<li>Value to set (0 to 4095).<\/li>\n<\/ul>\n\n\n\n<p>This will vary the voltage from 0 to 3.3V and from 3.3V to 0.<\/p>\n\n\n\n<p>In case you don&#8217;t have oscilloscope, you could use the following with basic multimeter:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 0);\n\t  HAL_Delay(3000);\n\n\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 128);\n\t  HAL_Delay(3000);\n\n\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 256);\n\t  HAL_Delay(3000);\n\n\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 512);\n\t  HAL_Delay(3000);\n\n\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 1024);\n\t  HAL_Delay(3000);\n\n\t  HAL_DAC_SetValue(&amp;hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 4095);\n\t  HAL_Delay(3000);<\/pre><\/div>\n\n\n\n<p>This will vary the voltage every 3 seconds so it can be observed by the multimeter.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Save the project, build it and run it on your STM32H563Zi board.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/07\/2024-07-12_15-03-3.jpg\" alt=\"\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Results:<\/h2>\n\n\n\n<p>By probing PA4 using oscilloscope, you should get this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"480\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4.png\" alt=\"\" class=\"wp-image-3041\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4.png 800w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4-300x180.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4-768x461.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4-750x450.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4-400x240.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2024\/11\/DS1Z_QuickPrint4-250x150.png 250w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>We have successfully generated a variable voltage from 0 to 3v3 and vice versa.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Happy coding \ud83d\ude09<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide on DAC (Digital to Analog Converter), we shall see the feature of the DAC on STM32H5, the functional block diagram and how to develop the driver using STM32CubeMX. In this guide, we shall cover the following: In&nbsp;electronics, a&nbsp;digital-to-analog converter&nbsp;(DAC,&nbsp;D\/A,&nbsp;D2A, or&nbsp;D-to-A) is a system that converts a&nbsp;digital signal&nbsp;into an&nbsp;analog signal. An&nbsp;analog-to-digital converter&nbsp;(ADC) performs [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,11,12],"tags":[],"class_list":["post-3034","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3034"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3034"}],"version-history":[{"count":2,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3034\/revisions"}],"predecessor-version":[{"id":3042,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/3034\/revisions\/3042"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}