学前班
最后登录1970-1-1
在线时间 小时
注册时间2015-1-13
|
利用DAC的DMA方式输出电压值,发现输出不了,麻烦看看下面程序,求指导一下,谢谢!
DAC函数dac.c
#include "dac.h"
#define DAC_DHR12R1_Address 0x40007408 //
u16 DAC_tablevalue[32];
void DMA2_Init(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);//
DMA_DeInit(DMA2_Channel3);
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12R1_Address;//
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&DAC_tablevalue;//
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;//
DMA_InitStructure.DMA_BufferSize = 32;//
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
//DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; //
//DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//·
DMA_Init(DMA2_Channel3, &DMA_InitStructure);//
DMA_Cmd(DMA2_Channel3, ENABLE);//
}
//DAC配置
void Dac1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitType;
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);
GPIO_SetBits(GPIOA,GPIO_Pin_4) ;//PA.4置高
DAC_InitType.DAC_Trigger=DAC_Trigger_None; //
DAC_InitType.DAC_WaveGeneration=DAC_WaveGeneration_None;//
DAC_InitType.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0;//
DAC_InitType.DAC_OutputBuffer=DAC_OutputBuffer_Disable ; //
DAC_Init(DAC_Channel_1,&DAC_InitType); //
DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC1
DAC_DMACmd(DAC_Channel_1, ENABLE);//使能DAC1的DMA
}
void DAC_Mode_Init(void)
{
Dac1_Init(); //DAC初始化
DMA2_Init();
DAC_tablevalue[0] = 2048;//DAC输出一个固定电压值
}
主函数main.c
int main(void)
{
DAC_Mode_Init();
while(1);
}
|
|