采用STM32F103VET6单片机,DAC+DMA+TIM2触发方式,通道1输出正弦波,参考例程配置,但是没有信号输出,硬件检查了正常。求助
#include "stm32f10x.h"
u16 Dac1_Data[101]={
2048,2177,2305,2432,2557,2681,2802,2920,3034,3145,3251,3353,3449,3540,3625,3704,3777,3842,3901,3952,
3995,4031,4059,4080,4092,4095,4092,4080,4060,4032,3996,3953,3902,3844,3778,3706,3628,3543,3452,3355,
3254,3148,3037,2923,2805,2684,2560,2435,2308,2180,2051,1923,1795,1668,1542,1419,1297,1179,1065,954,
847,746,649,558,473,394,321,255,197,145,102,65,37,17,4,0,4,16,35,63,
99,142,193,251,316,388,466,551,642,738,839,946,1056,1171,1288,1409,1533,1658,1785,1913,
2041};
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus;
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSEStartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2);
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2,ENABLE);
RCC_APB1PeriphClockCmd(
RCC_APB1Periph_TIM2 |
RCC_APB1Periph_DAC,ENABLE);
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks 72M*/
RCC_APB2PeriphClockCmd(
RCC_APB2Periph_AFIO |
RCC_APB2Periph_GPIOA |
RCC_APB2Periph_TIM8, ENABLE);
}
/**ÍâΧµ×²ãÇý¶¯¡¢IO¿ÚģʽµÄÉèÖÃ**/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//DAC1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;//GPIO_Mode_AIN;//Ä£ÄâÊäÈë
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
/* DAC channel1 Configuration */
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO; // T2´¥·¢¹¦ÄÜ
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; // ²»Ê¹Óò¨Ðη¢ÉúÆ÷
DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bit0; // Êä³ö»º´æ¹Ø±Õ
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; // Êä³ö»º´æ¹Ø±Õ
DAC_Init(DAC_Channel_1, &DAC_InitStructure); // Æô¶¯ADCת»»
}
void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA2_Channel3);
/* DMA2 Configuration */
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)&(DAC->DHR12R1); // DAC1µØÖ·
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&Dac1_Data; // ÄÚ´æµØÖ·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; // ÄÚ´æÊä³öÊý¾Ýµ½ÍâÉè
DMA_InitStructure.DMA_BufferSize = 101; // ¼Ä´æÆ÷´óС
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_PeripheralDataSize_HalfWord; // ¿í¶È°ë×Ö
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; // ¹¤×÷ÔÚÑ»·»º´æģʽ
DMA_InitStructure.DMA_Priority = DMA_Priority_High; // Êý¾ÝÓÅÏȼ¶
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; // ûÓÐÉèÖÃÄÚ´æµ½ÄÚ´æ´«Êä
DMA_Init(DMA2_Channel3,&DMA_InitStructure); // DAC1¶ÔÓ¦DMA2ͨµÀ3
/* Enable DAC Channel1 */
DMA_Cmd(DMA2_Channel3,ENABLE);//ʹÄÜDAC1
DAC_Cmd(DAC_Channel_1,ENABLE);//ʹÄÜDAC1
DAC_DMACmd(DAC_Channel_1,ENABLE);//ʹÄÜDAC1µÄDMA
TIM_Cmd(TIM2,ENABLE);//ʹÄÜTIM2
}
void TIM_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* TIM2 Configuration */
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 0x19; //ÉèÖÃÊä³öƵÂÊ Value=72000000/(101*F)
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; //²»Ô¤·ÖƵ
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //²»Ô¤·ÖƵ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
/* TIM2 TRGO selection */
TIM_SelectOutputTrigger(TIM2,TIM_TRGOSource_Update);
}
int main(void)
{
RCC_Configuration(); //ÅäÖÃʱÖÓ
GPIO_Configuration(); //ÅäÖÃIO¿Ú
TIM_Configuration();
DAC_Configuration();
DMA_Configuration();
while(1)
{
}
} |
|