Skip to main content
Bench
Associate III
April 12, 2018
Question

STM32 DAC with DMA constant value

  • April 12, 2018
  • 9 replies
  • 2860 views
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:

 HAL_DAC_Start_DMA(&hdac1,DAC_CHANNEL_1,(uint32_t*)dacVal,1,DAC_ALIGN_12B_R);

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

  DAC1->SWTRIGR=DAC_SWTRIGR_SWTRIG1;

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,

Bene

    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    April 12, 2018
    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;

    HAL_DAC_Start_DMA(&hdac1,DAC_CHANNEL_1,(uint32_t*)dacVal,1,DAC_ALIGN_12B_R);

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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Bench
    BenchAuthor
    Associate III
    April 12, 2018
    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!

    Bene

    Tilen MAJERLE
    ST Employee
    April 13, 2018
    Posted on April 13, 2018 at 07:17

    benedict.scheiner

    ‌,

    HAL_DAC_Start_DMA

    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,

    Tilen

    Bench
    BenchAuthor
    Associate III
    April 17, 2018
    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,

    Bene

    AAlam
    Visitor II
    February 14, 2019

    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,

    Arturo.

    waclawek.jan
    Super User
    February 15, 2019

    Start a new thread stating your problem.

    JW