Showing results for 
Search instead for 
Did you mean: 

STM32 DAC with DMA constant value

Associate III
Posted on April 12, 2018 at 20:07

Hi to all,

I am encountering a problem, concerning the DAC of the stm32L476. I only want to use the DAC with a constant value but with DMA, so that I can use the CPU during that operation. Without DMA the DAC works as desired.

Now my question is: How can I start the DAC with DMA without a Timer? The function we used is:


and since we want to use a software trigger, we added


afterwards, to start the DAC-conversion. Nevertheless, we cannot measure any voltage. In CubeMX we configured the DAC with a Software trigger and the DMA as Normal and Half Word.

Can anyone help us out?

We just don't know what else we can do.

Thank you a lot in advance,


Posted on April 12, 2018 at 21:42

Don't really understand the point of the exercise surely it is just a register you write and forget. ie DAC1->DHR12R1 = value;


And how is dacVal defined? Should you be using (uint32_t*)&dacVal ??

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on April 12, 2018 at 22:08

Hi Clive!

Thanks a lot for your answer. I will try this out tomorrow! 

dacVal in our case is defined as 

uint32_t dacVal = 5000;

I thought the value is written in the register in the used HAL function. 

And why do you think we have to add the & before dacVal?

Thank you!


Posted on April 13, 2018 at 07:17




accepts pointer to array but you tried to pass value as pointer => undefined behavior. As mentioned by Clive One, you don't need DMA if you want to have single value on the output. Writing to output register for DAC is enough in your case.

Best regards,


Posted on April 13, 2018 at 07:53

Hi Tilen,

thank you very much for your answer. Ah okay I understand. The problem is, that if we for example use the HAL-Functions DAC_Start and SetValue, which are without the use of DMA, the µC is not able to perform any task eg simple bitshift operations. So it seems like the DAC is blocking the CPU completely.

What we want to do is applying a constant value to an external OPamp input and changing this to another value after performing some other operations where we have to use the CPU. That is why we tried this simple operation with DMA.

So if I define dacVal like:

uint32_t dacVal[2] = {2000,3000}

and I want to swich between these two values, but using a software trigger not a timer. How can this be done? In this case I have an array, so this should work?

Thanks a lot in advance!


Posted on April 13, 2018 at 08:33

As said - once enabled and set, the DAC keeps the last value, and thus the output voltage.

uint32_t dacVal = 5000;

However, that seems a bit much for 12 bits ...

Posted on April 13, 2018 at 10:31


HAL_DAC_Start function does not block (no while loop or event wait) therefore it should work normally to start DAC itself. Once started, you may use HAL_DAC_SetValue to update value on the output.

Associate III
Posted on April 17, 2018 at 07:06

Thanks to all!

The problem was, that I put the DMA Channel not to normal but to cycle... That is why it blocked the CPU with the HAL-Functions.

Best regards,


Hello Ben,

Did you find a solution to start the DAC and DMA without a timer? I have the same problem now with the STM32F446RE.

Will be awaiting for your responses.

Best Regards,


Start a new thread stating your problem.