Question
STM32F4DISCOVERY using DAC pins A4 & A5 without the codec
Posted on April 10, 2013 at 15:44
Hello,
I'm using a STM32F4DISCOVERY to program the firmware of my future board. I want to use the integrated 12 bit DAC of the board to generate analog simple signals on the A4 and A5 pins, but I don't want to use the external audio codec CS43L22 of the discovery board. On theSTM32F4DISCOVERY board A4 and A5 are connected to the LIS30 and the CS43L22 but I think it's OK to use these pins for generate analog signals. Am I right ? So I try to program with this code I found on a forum:
int
main(
void
)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* Enable DAC and GPIOC clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC | RCC_APB1Periph_TIM2, ENABLE);
/* Configure PA.04/05 (DAC) as output -------------------------*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_None;
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* Enable DAC Channel2: Once the DAC channel2 is enabled, PA.05 is
automatically connected to the DAC converter. */
DAC_Cmd(DAC_Channel_2, ENABLE);
while
(1)
{
int
i;
for
(i=0; i<4096; i++)
DAC_SetChannel2Data(DAC_Align_12b_R, i);
}
/* does not exit - kind of important */
return
(1);
}
This code works on STM32F3xx but there is some problems with STM32F4xxcompactibility. Line 8, ''RCC_APB2Periph_AFIO'' and ''RCC_APB2Periph_GPIOA'' are not declared in librairies.
Is anyone know what are the RCC_APB2Periph_AFIO andRCC_APB2Periph_GPIOA equivalent in STM32F4xx ? Thanks for your help !
note: I'm using the latest STM32F4xx librairies, but not thestm32f4_discovery librairy.
#dac #stm32f407 #stm32f4discovery