初始化后,每次写入2900的数据,示波器测量输出为0,代码如下:
DAC_InitTypeDef dactype;
GPIO_InitTypeDef gpioinit;
/* GPIOA clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Configure PA.04 (DAC_OUT1) as analog */
gpioinit.GPIO_Pin = GPIO_Pin_4;
gpioinit.GPIO_Mode = GPIO_Mode_AN;
gpioinit.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &gpioinit);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
dactype.DAC_Trigger = DAC_Trigger_Software;
dactype.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
dactype.DAC_WaveGenera
tion = DAC_WaveGeneration_None;
dactype.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0;
DAC_Init(DAC_Channel_1, &dactype);
DAC_Cmd(DAC_Channel_1, ENABLE);
上面是初始化dac部分,
DAC_SetChannel1Data(DAC_Align_12b_R, 2900);
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
上面是写入部分
请问各位大神,代码有什么问题没有呢?
刚看了STM32F0的固件库,DAC样例非常简单。只不过触发方式为 DAC_Trigger_None,初始化完成后,随时刷DAC_SetChannel1Data(DAC_Align_12b_R, ADCVal);,DAC立即输出。
总之,先跑个样例程序,排除管脚或其它硬件故障,然后再自己发挥。
一周热门 更多>