初中生
最后登录1970-1-1
在线时间 小时
注册时间2016-1-25
|
大家好,我用DMA,DAC输出固定电压,可是始终为0,不知道为什么?先上代码把
#include "bsp_dac.h"
#define DAC_DHR12RD_Address 0x40007420 //0x40007420
const uint16_t Sine12bit = 3000;
uint32_t DualSine12bit;
static void DAC_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DAC_InitTypeDef DAC_InitStructure;
/* ê1ÄüGPIOAê±Öó */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
/* ê1ÄüDACê±Öó */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
/* DACμÄGPIOÅäÖã¬Ä£Äaêäèë */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; //èí¼t′¥·¢1|Äü
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //2»ê1óÃ2¨Dη¢éúÆ÷
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //2»ê1óÃDACêä3ö»o3å
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
// ÅäÖÃDAC í¨μà1£¬2
DAC_Init(DAC_Channel_1, &DAC_InitStructure);
DAC_Init(DAC_Channel_2, &DAC_InitStructure);
/* ê1Äüí¨μà1 óéPA4êä3ö ê1Äüí¨μà2 óéPA5êä3ö */
DAC_Cmd(DAC_Channel_1, ENABLE);
DAC_Cmd(DAC_Channel_2, ENABLE);
/* ê1ÄüDACμÄDMAÇëÇó */
DAC_DMACmd(DAC_Channel_2, ENABLE);
}
/**
* @brief ÅäÖÃDMA
* @param ÎT
* @retval ÎT
*/
static void DAC_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* ê1ÄüDMA2ê±Öó */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
/* ÅäÖÃDMA2 */
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_Address; //íaéèêy¾YμØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&DualSine12bit ; //Äú′æêy¾YμØÖ· DualSine12bit
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; //êy¾Y′«êä·½ÏòÄú′æÖáíaéè
DMA_InitStructure.DMA_BufferSize = 1; //»o′æ′óD¡Îa1×Ö½ú
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //íaéèêy¾YμØÖ·1춨
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; //Äú′æêy¾YμØÖ·1춨
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; //íaéèêy¾YòÔ×ÖÎaμ¥λ
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word ; //Äú′æêy¾YòÔ×ÖÎaμ¥λ
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //Õy3£Ä£ê½
DMA_InitStructure.DMA_Priority = DMA_Priority_High; //¸ßDMAí¨μàóÅÏ輶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //·ÇÄú′æÖáÄú′æÄ£ê½
DMA_Init(DMA2_Channel4, &DMA_InitStructure);
/* ê1ÄüDMA2-4í¨μà */
DMA_Cmd(DMA2_Channel4, ENABLE);
}
/**
* @brief DAC3õê¼»ˉoˉêy
* @param ÎT
* @retval ÎT
*/
void DAC_Mode_Init(void)
{
DAC_Config();
DAC_DMA_Config();
DualSine12bit = (Sine12bit << 16) + (Sine12bit);
DAC_SoftwareTriggerCmd (DAC_Channel_1,ENABLE);
DAC_SoftwareTriggerCmd (DAC_Channel_2,ENABLE);
}
望大家可以帮忙分析一下,哪儿出问题了!
谢谢···
|
|