Skip to main content
AKerp.1
Associate
June 16, 2020
Question

HAL DAC output problem

  • June 16, 2020
  • 3 replies
  • 2787 views

Hello all,

I need to use DAC on STM32F091 MCU. I have configured it in cubemx - Channel1 - output PIN PA4, output buffer enabled, no trigger.,

in Main.c is next:

static char dac_tmp=200;

set_DAC_output(dac_tmp);

 if (HAL_DAC_Start (&hdac, DAC_CHANNEL_1 ) != HAL_OK)

 {

 HAL_Delay(1000);//TODO ADC CALL ERROR HANDLING

 }

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

set_DAC_output(dac_tmp);

}

void set_DAC_output(char DAC_VAL)

{

if (HAL_DAC_SetValue (&hadc, DAC_CHANNEL_1, DAC_ALIGN_8B_R, DAC_VAL) != HAL_OK)

{

HAL_Delay(1000); // TODO ADC CALL ERROR HANDLING

}

}

This is execution code regarding DAC. Currently it is only to check, if it is work good. But on the PA4 pin is no relevant voltage.

Until DAC start function has PA4 pin output voltage 0.00V, after DAC start has 0.06 V appeared. But this value has not been changed after writting anything with HAL_DAC_SetValue function. The same results on two boards.

DAC looks that is pretty simple to use, but not.

PS: on the same boad I use ADC too with no problem (that shares the same reference voltage).

I thank you for any idea.

I use CUBEIDE 1.3.1 with newest HAL library.

This topic has been closed for replies.

3 replies

MMoon.1
Visitor II
June 16, 2020

Make sure you’re using software trigger.

TDK
Super User
June 16, 2020

Your code writes 200 to the DAC, and then it writes it again and again. The value never changes. Why are you expecting the output to change?

"If you feel a post has answered your question, please click ""Accept as Solution""."
AKerp.1
AKerp.1Author
Associate
June 17, 2020

Thank you all for reply. I have fixed it. I have called "HAL_DAC_SetValue (&hadc, DAC_CHANNEL_1, DAC_ALIGN_8B_R, DAC_VAL)" instead "HAL_DAC_SetValue (&hdac, DAC_CHANNEL_1, DAC_ALIGN_8B_R, DAC_VAL)" which has leaded to bad peripheral memory address assign (0x40012400 instead 0x40007400). So stupid fault. Sorry for dummy questions and flooding.

Andrej