2018-04-12 11:07 AM
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
2018-04-12 12:42 PM
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 ??
2018-04-12 03:08 PM
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
2018-04-13 12:17 AM
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
2018-04-13 12:53 AM
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!
Bene
2018-04-13 01:33 AM
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 ...
2018-04-13 03:31 AM
Hello,
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.
2018-04-16 10:06 PM
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
2019-02-14 11:46 AM
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.
2019-02-15 11:37 AM
Start a new thread stating your problem.
JW