cancel
Showing results for 
Search instead for 
Did you mean: 

How to run DAC in STM32F107VC using HAL functions?

RezaMRBM
Associate II

Hello. I have written a program to run the DAC in the STM32F107VC and I have used STM32CubeMX and HAL functions. But I don't see any waveform in the DAC output (PA4 pin). I was able to run the DAC using set the DAC registers. But I don't succeed with HAL functions. I use this functions:

MX_DAC_Init(); // generated with STM32cubeMX
 
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
 
HAL_DAC_SetValue(&hdac, DAC_CHANNEL_1, DAC_ALIGN_12B_R, 1800);

With 1800 value, I should have a voltage of 1.4v at the output. Also, the DAC settings in STM32CubeMX are as follows:

Output buffer: Enable

Trigger: None

According to the training provided in this link.

Thank you for your guidance.

4 REPLIES 4
Petr DAVID
ST Employee

Hello RezaMRBM,

are you using some custom board or ST eval board for STM32F107 STM3210C-EVAL? Both cases I would recommend to take look on example for this MCU called DAC_SignalsGeneration available in STM32CubeF1 software package.

You have said you were able to run the DAC using set the DAC registers. Please check registers when they are working as you intended and compare them with the state after HAL_DAC_Start() function. You can send the state of DAC registers also here.

Let me know if you were able to solve the problem.

RezaMRBM
Associate II

Hello Mr. Petr DAVID,

Sorry for my delay. I use self-designed custom board and will work on this issue again and I will send the result for you.

Best regards

S.Ma
Principal

Sanity check: use debugger and stop the code after started running to see gpio and dac hw registers.

Pin must be analog mode (gpio.moder), clock enabled (registers can be manually read/write). Same for dac. Manually adjust the registers until your output works. Make sure the analog has supply voltage, vdda or vdd.

RezaMRBM
Associate II

Thank you for your guidance. I will definitely do that.