2014-03-17 10:51 AM
Dear All,
I have tested the DAC example on the STM32F429 and I have understood the way using / driving the DAC on the STM32F4. I have tried to create my sample code using the STM32F429 Discovery template, but nothing happened.Here below the code:RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;GPIO_Init(GPIOA, &GPIO_InitStructure); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);TIM_TimeBaseStructure.TIM_Period = 0xFF;TIM_TimeBaseStructure.TIM_Prescaler = 0;TIM_TimeBaseStructure.TIM_ClockDivision = 0;TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);TIM_Cmd(TIM6, ENABLE); DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;DAC_Init(DAC_Channel_1, &DAC_InitStructure);DAC_Cmd(DAC_Channel_1, ENABLE);DAC_SetChannel1Data(DAC_Align_12b_R, 500);I Have checked with the oscilloscope, but nothing changes.Then I have tested the DAC_SignalGeneration and it run correctly.Then I have tried to modify the DAC_SignalGeneration example and I have only changed this piece of code:while (1) { /* If the User Button is pressed */ if (KeyPressed == RESET) { DAC_DeInit(); /* select waves forms according to the Key Button status */ if (SelectedWavesForm == 1) { /* The sine wave and the escalator wave has been selected */ /* Escalator Wave generator ------------------------------------------*/ DAC_Ch1_EscalatorConfig(); /* Sine Wave generator -----------------------------------------------*/ DAC_Ch2_SineWaveConfig(); } else { /* The triangle wave and the noise wave has been selected */ /* Noise Wave generator ----------------------------------------------*/ DAC_Ch1_NoiseConfig(); /* Triangle Wave generator -------------------------------------------*/ DAC_Ch2_TriangleConfig(); } KeyPressed = SET; } } In the following way:while (1) { /* If the User Button is pressed */ if (KeyPressed == RESET) { DAC_DeInit(); /* select waves forms according to the Key Button status */ if (SelectedWavesForm == 1) { /* The sine wave and the escalator wave has been selected */ /* Escalator Wave generator ------------------------------------------*/ //DAC_Ch1_EscalatorConfig(); /* Sine Wave generator -----------------------------------------------*/ DAC_Ch2_SineWaveConfig(); } else { /* The triangle wave and the noise wave has been selected */ /* Noise Wave generator ----------------------------------------------*/ //DAC_Ch1_NoiseConfig(); /* Triangle Wave generator -------------------------------------------*/ //DAC_Ch2_TriangleConfig(); } KeyPressed = SET; } }Sincerly I do not understand where is the problem, I have read a lot of things on internet and I have tried to do all the possible changes, but the DAC does not run with and without DMA.Could someone help me about this problem?Thanks!2014-03-18 02:23 AM
Hi
A quick glance through your code : ''GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;'' I think this should be : GPIO_Mode_AF for alternate function mode. Also, there should be some code to select the Alternate Function for thise pins.2014-03-18 04:53 AM
Hello,
thank you very much for the answer.I have checked many examples and they configure the pin AN (Analog) not AF.In the STM32F4XX PINA4 is the DAC 1 and PINA5 is the DAC 2.Let me know!Best regards2014-03-18 05:27 AM
In the STM32F4XX PINA4 is the DAC 1 and PINA5 is the DAC 2.
Are you sure ? Better check the datasheet of your F4xx derivate. And when about it, check that nothing else is connected to the DAC out pins. The DAC has a rather high output impedance even in buffered mode, and is easily overdriven by other peripherals attached to the line.
2014-03-18 06:40 AM
Definitely want to check the STM32F429I-DISCO schematic/manual, only PA5 is free on the board.
For the STM32F4-DISCO I had an [DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Help%20with%20simple%20ADC%20on%20STM32F4&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=593]example about 80% down this thread.2014-03-19 10:55 AM
Thank you very much for the support!
Now it works fine on the EVAL board.Best regards2014-03-19 12:06 PM
Aloisini.,
What did you change to get this to work? I am facing a similar issue and would like to know the details. Thanks. -Mike.