STM32F107的DAC配置

Posted PacexDong

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了STM32F107的DAC配置相关的知识,希望对你有一定的参考价值。

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这里非常重要,如果设置为关闭,则实际电路在输出里加下拉电阻会出错,这里设置成使能才不会受到接地电阻的影响

以上是关于STM32F107的DAC配置的主要内容,如果未能解决你的问题,请参考以下文章

STM32F107移植LWIP

嵌入式22STM32F1C8T6音频数据的Flash读取与DAC播放

STM32f107 usb重枚举

STM32F107VC 使用 TCP 运行 FreeRTOS

如何在 stm32f107 芯片上禁用/启用中断?

STM32F103(二十)DAC(贼详细)