STM32F107的DAC配置

左心房为你撑大大i 提交于 2019-11-28 16:23:55

void DAC_INIT()
{
// //SystemInit();
// GPIO_InitTypeDef GPIO_InitStructure;
// DAC_InitTypeDef DAC_InitType;
// SystemInit();
//// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE ); //ʹÄÜPORTAͨµÀʱÖÓ
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE ); //ʹÄÜPORTAͨµÀʱÖÓ
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE ); //ʹÄÜDACͨµÀʱÖÓ

// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; // ¶Ë¿ÚÅäÖÃ
//// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //Ä£ÄâÊäÈë
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //Ä£ÄâÊäÈë
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
// GPIO_SetBits(GPIOA,GPIO_Pin_4) ;//PA.4 Êä³ö¸ß
//
// DAC_InitType.DAC_Trigger=DAC_Trigger_None; //²»Ê¹Óô¥·¢¹¦ÄÜ TEN1=0
// DAC_InitType.DAC_WaveGeneration=DAC_WaveGeneration_None;//²»Ê¹Óò¨Ðη¢Éú
// DAC_InitType.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;//ÆÁ±Î¡¢·ùÖµÉèÖÃ
// DAC_InitType.DAC_OutputBuffer=DAC_OutputBuffer_Disable ; //DAC1Êä³ö»º´æ¹Ø±Õ BOFF1=1
// DAC_Init(DAC_Channel_1,&DAC_InitType); //³õʼ»¯DACͨµÀ1

// DAC_Cmd(DAC_Channel_1, ENABLE); //ʹÄÜDAC1
//
// DAC_SetChannel1Data(DAC_Align_12b_R, 0); //12λÓÒ¶ÔÆëÊý¾Ý¸ñʽÉèÖÃDACÖµ

GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
// DMA_InitTypeDef DMA_InitStructure;
//??GPIOA
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
//??DAC1??
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
//dac??pa4????
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_InitStructure.DAC_Trigger = DAC_Trigger_None;//DAC_Trigger_T2_TRGO;
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);
DAC_Cmd(DAC_Channel_1, ENABLE);
//DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);

DAC_SetChannel1Data(DAC_Align_12b_R,0);//12????,??0
//DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE);
}

 

DAC_InitType.DAC_OutputBuffer这里非常重要,如果设置为关闭,则实际电路在输出里加下拉电阻会出错,这里设置成使能才不会受到接地电阻的影响

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!