void DAC_GPIO_Config( void )
{
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init( GPIOA, &GPIO_InitStruct );
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init( GPIOA, &GPIO_InitStruct );
}
void DAC_RCC_Config( void )
{
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE );
RCC_APB1PeriphClockCmd( RCC_APB1Periph_DAC, ENABLE );
}
void DAC_Init_Config( void )
{
DAC_InitTypeDef DAC_InitStruct;
DAC_InitStruct.DAC_Trigger = DAC_Trigger_Software;
DAC_InitStruct.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStruct.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
DAC_InitStruct.DAC_OutputBuffer = DAC_OutputBuffer_Enable;
DAC_Init( DAC_Channel_1, &DAC_InitStruct );
DAC_Init( DAC_Channel_2, &DAC_InitStruct );
DAC_Cmd( DAC_Channel_1, ENABLE );
DAC_Cmd( DAC_Channel_2, ENABLE );
DAC_SetChannel1Data( DAC_Align_12b_R, 0X07FFF );
DAC_SoftwareTriggerCmd( DAC_Channel_1, ENABLE );
DAC_SetChannel1Data( DAC_Align_12b_R, 0X03FFF );
DAC_SoftwareTriggerCmd( DAC_Channel_2, ENABLE );
}
void DAC_Config( void )
{
DAC_RCC_Config();
DAC_GPIO_Config();
DAC_Init_Config();
}
上面是全部的代码了。至于DAC的引脚配置,我参考了ST的官方例程,就是AIN这个模式。但是还是不行。 |