#include "dac.h"
#include "stm32f10x.h"
void DAC_CH_CONFIG(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_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_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_DeInit();
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software ; //软件触发
//以下两句的作用为关闭DAC端口的输出三角波形功能以及关闭其输出波形的电压幅值
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;
//关闭缓存,DAC端口不接负载时可不用缓存
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable;
DAC_Init( DAC_Channel_1, &DAC_InitStructure ); //初始化
DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC1 通
DAC_SetChannel1Data(DAC_Align_12b_R, 0x0000); //写入初始值0
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE); ///软件触发转换
}
void DAC_SET(void)
{
DAC_SetChannel1Data(DAC_Align_12b_R, 0x5ff);
DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);
}
int main(void)
{
DAC_CH_CONFIG();
DAC_SET();
while(1)
{
}
}
使用的CPU 是stm32f103vet6 在开发板的PA4口测量的输出电压始终是3.26V(实测DAV的参考电压为3.26V),改变DAC_SetChannel1Data(DAC_Align_12b_R, 0x5ff);中的值 ,输出 电压值 不变! 求各位帮忙看下,不盛感激! |