cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F334C8 DAC1 CH1

ASSAAD.ASSAAD
Associate II
Posted on February 11, 2016 at 20:43

Hello ;

I have problem to get analog output on PA4 ( DAC1 , ch1) ; Here down my code to set the DAC1 could you tell me what is missing here ? I m getting some few mv even when I set the a full scale 4096 :

DAC_SetChannel1Data(DAC1, DAC_Align_12b_R, 4096);

Thank you inadvanced

/* DAC Periph clock enable ----------------------------------------*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* SYSCFG Periph clock enable -------------------------------------*/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
/* Enable GPIOA Periph clock --------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA.04 (DAC1_OUT1),as analog */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC deinitialize */
DAC_DeInit(DAC1);
/* Fill DAC InitStructure */
DAC_InitStructure.DAC_Trigger =DAC_Trigger_None;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits2_0; 
DAC_InitStructure.DAC_Buffer_Switch = DAC_BufferSwitch_Enable;
/* DAC channel1 Configuration */
DAC_Init(DAC1, DAC_Channel_1, &DAC_InitStructure);
/* Enable DAC Channel1: Once the DAC channel1 is enabled, PA.04 is 
automatically connected to the DAC converter. */
DAC_Cmd(DAC1, DAC_Channel_1, ENABLE);
/* Set DAC Channel1 DHR register: DAC1_OUT */
DAC_SetChannel1Data(DAC1, DAC_Align_12b_R, 0);

3 REPLIES 3
ASSAAD.ASSAAD
Associate II
Posted on February 12, 2016 at 18:17

Still I could not solve it ; 

Can it be a library bug ? 

Posted on February 12, 2016 at 19:45

Still I could not solve it ; Can it be a library bug ?

I'd suspect the board/hardware first. Check schematic, solder bridges, and VREF

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ASSAAD.ASSAAD
Associate II
Posted on February 14, 2016 at 20:28

Thank you clive ; 

Tha hardware is ok ; 

but when I disabled the buffer it works ; but I could not understand why ; the datasheet says that for DAC1 CH1 it is connected to a buffer so it should be enable .