void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //
GPIO_Init(GPIOA, &GPIO_InitStructure); //A¶Ë¿Ú
//DAC_DeInit();
// DAC_Cmd(DAC_Channel_1,ENABLE); //
DAC_StructInit(&DAC_InitStructure);//½«DAC_StructµÄÖµÉèΪĬÈÏ
DAC_InitStructure.DAC_Trigger=DAC_Trigger_Software;//ÓÉÈí¼þ´¥·¢
DAC_InitStructure.DAC_WaveGeneration=DAC_WaveGeneration_None;//¹Ø±Õ²¨ÐÎÉú³É
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_TriangleAmplitude_4095;
DAC_InitStructure.DAC_OutputBuffer=DAC_OutputBuffer_Enable;//ʹÄÜDACͨµÀ»º´æ
DAC_Init(DAC_Channel_1,&DAC_InitStructure);
/* Enable DAC Channel1 */
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_SetChannel1Data(DAC_Align_12b_R,4085);
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
while(1)
{
DAC_SetChannel1Data(DAC_Align_12b_R,4085);
DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}
源代码如上,输出电压不对,试过其他数值也不对,代码之前是用在ST上的
|