2020-06-16 03:22 AM
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.
2020-06-16 05:02 AM
Make sure you’re using software trigger.
2020-06-16 06:03 AM
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?
2020-06-16 09:20 PM
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