DAC+DMA生成正弦波出现问题,求大神帮忙

2019-08-22 15:05发布

芯片:stm32f205ze
想要实现DAC+DMA生成正弦波的功能,参考了网上的一些程序,改完之后DAC1还是没有输出。
主要代码如下:
[mw_shl_code=c,true]#include "WaveOut.h" u16 SineWave1_Dt[SAMPLE_NUM]; u16 SineWave2_Dt[SAMPLE_NUM]; /** * * ?ú???????¨??????±í * Wave_Amp ?? ?????¨·ù??(mV) * Dt_num : ?????????ù???? * Dt ?? ???ù????????×é * */ void SineWave_Data(u16 Wave_Amp, u16 Dt_num ,u16 *Dt) { u16 i; for( i=0;i<Dt_num;i++) { Dt=(u16)((Wave_Amp*sin(( 1.0*i/(Dt_num-1))*2*PI)+Wave_Amp)*4095/3300); } } /** * GPIO???? * */ void SineWave_GPIO_Config() { GPIO_InitTypeDef GPIO_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOA, &GPIO_InitStructure); } /** * ?¨?±?÷????* * Wave1_Per : ?¨??1?ù±????? * Wave2_Per ???¨??2?ù±????? * **/ void SineWave_TIM_Config( u32 Wave1_Per ,u32 Wave2_Per) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);//???±?? // RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);//???±?? TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Prescaler = 0x0; //???¤·??? TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //??·??? TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//?ò?????????? TIM_TimeBaseStructure.TIM_Period = Wave1_Per; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);//?è??TIM2??????·????ü?????? // TIM_TimeBaseStructure.TIM_Period = Wave2_Per; //?è?????????? // TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure); //?????? // TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update); } /** * DAC???? * */ void SineWave_DAC_Config() { DAC_InitTypeDef DAC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);//??DAC?±?? /**************DAC?á??????????????????·??ò???¨??*******************/ DAC_StructInit(&DAC_InitStructure); DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;//???ú?ú?¨?? DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude=DAC_LFSRUnmask_Bit0; DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //?????????????? DAC_SoftwareTriggerCmd(DAC_Channel_1,ENABLE); DAC_InitStructure.DAC_Trigger = DAC_Trigger_T2_TRGO;//????DAC??·?????TIM2 DAC_Init(DAC_Channel_1, &DAC_InitStructure);//?????? DAC_Cmd(DAC_Channel_1, ENABLE); //????DAC?¨??1 DAC_DMACmd(DAC_Channel_1, ENABLE); //????DAC?¨??1??DMA // DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;//????DAC??·?????TIM6 // DAC_Init(DAC_Channel_2, &DAC_InitStructure);//?????? // DAC_Cmd(DAC_Channel_2, ENABLE); //????DAC?¨??2 // DAC_DMACmd(DAC_Channel_2, ENABLE); //????DAC?¨??2??DMA } /** * * DMA???? * * Wave1_Mem ?? ?¨??1?ù±???×é * Wave2_Mem ?? ?¨??2?ù±???×é * * */ void SineWave_DMA_Config(u16* Wave1_Mem, u16* Wave2_Mem) { DMA_InitTypeDef DMA_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);//??DMA1???±?? DMA_StructInit( &DMA_InitStructure); //DMA?á???????? DMA_InitStructure.DMA_Channel = DMA_Channel_7; DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//???????÷?????? DMA_InitStructure.DMA_BufferSize = 256;//?????ó??????°???256?? 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_Priority = DMA_Priority_VeryHigh;//????????·????? // DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//??±??????????????? DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//???··??????? // DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //// DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_DACC1DHR;//???è???·??DAC?¨??1?????????÷ DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)Wave1_Mem;//???????·???????¨????????×é DMA_Init(DMA1_Stream5, &DMA_InitStructure);//?????? DMA_Cmd(DMA1_Stream5, ENABLE); //????DMA?¨?? // DMA_InitStructure.DMA_PeripheralBaseAddr = DAC_DHR12RD_DACC2DHR;//?è?????è???·??DAC?¨??1?????????÷ // DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)Wave2_Mem;//???????·???????¨????????×é // DMA_Init(DMA1_Stream6, &DMA_InitStructure);//?????? // DMA_Cmd(DMA1_Stream6, ENABLE); //????DMA?¨??4 } /** * ???????????¨ * Wave1_Fre ???¨??1????(Hz) * Wave1_Amp ???¨??1??·ù(mV) * Wave2_Fre ???¨??2????(Hz) * Wave2_Amp ???¨??2??·ù(mV) */ void SineWave_Init(u16 Wave1_Fre, u16 Wave1_Amp, u16 Wave2_Fre, u16 Wave2_Amp) { u16 f1 = (u16)(60000000/SAMPLE_NUM*2/Wave1_Fre); //???????? u16 f2 = (u16)(60000000/SAMPLE_NUM*2/Wave2_Fre); SineWave_Data(Wave1_Amp, SAMPLE_NUM, SineWave1_Dt); //?ú???¨??±í1 SineWave_DAC_Config(); //??????DAC SineWave_GPIO_Config(); //?????????? SineWave_TIM_Config(f1 ,f2); //???????¨?±?÷ SineWave_DMA_Config(SineWave1_Dt ,SineWave2_Dt); //??????DMA } [/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。