请高手帮我看看,我想用
STM32F207的DMA+DAC+
tiM6输出正玄波,现在遇到问题,不知道哪里不对,总是没有预期结果出来。有知道的请加我微信:18123784178,谢谢。代码如下:
#define DAC1_DMA_ADDR 0x40007408 //这个是DMA初始化要用的外设地址。是DAC_DHR12R1的地址
以下数组为余弦函数的数据 ,标题写的正玄波,不严谨,这里关系不大。
uc32 DAC_cosTAB[] = {
4000 ,3998 ,3990 ,3978 ,3962 ,3940 ,3914 ,3883 ,
3848 ,3808 ,3764 ,3715 ,3663 ,3606 ,3546 ,3482 ,
3414 ,3343 ,3269 ,3191 ,3111 ,3028 ,2943 ,2855 ,
2765 ,2674 ,2581 ,2486 ,2390 ,2293 ,2196 ,2098 ,
2000 ,1902 ,1804 ,1707 ,1610 ,1514 ,1419 ,1326 ,
1235 ,1145 ,1057 ,972 ,889 , 809 ,731 ,657 ,
586 ,518 ,454 ,394 ,337 ,285 , 236 ,192 ,
152 ,117 , 86 , 60 , 38 , 22 , 10 , 2 ,
0 , 2 , 10 , 22 , 38 , 60 , 86 ,117 ,
152 ,192 ,236 ,285 ,337 ,394 ,454 ,518 ,
586 ,657 ,731 ,809 ,889 ,972 ,1057 ,1145 ,
1235 ,1326 ,1419 ,1514 ,1610 ,1707 ,1804 ,1902 ,
2000 ,2098 ,2196 ,2293 ,2390 ,2486 ,2581 ,2674 ,
2765 ,2855 ,2943 ,3028 ,3111 ,3191 ,3269 ,3343 ,
3414 ,3482 ,3546 ,3606 ,3663 ,3715 ,3764 ,3808 ,
3848 ,3883 ,3914 ,3940 ,3962 ,3978 ,3990 ,3998 ,
4000
};
说明:管脚时钟,TIM时钟,DMA时钟都已经开了。
引脚配置代码段如下:
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_Init(GPIOA, &GPIO_InitStructure);
DMA的配置如下:
void DAC_DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
DMA_DeInit(DMA1_Stream5);
//DMA_StructInit( &DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_7;
DMA_InitStructure.DMA_PeripheralBaseAddr = DAC1_DMA_ADDR;
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)DAC_cosTAB;
DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure.DMA_BufferSize = 128;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_PeripheralDataSize_HalfWord;// DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_FIFOMode=DMA_FIFOMode_Disable;
DMA_InitStructure.DMA_FIFOThreshold=DMA_FIFOThreshold_1QuarterFull;
DMA_InitStructure.DMA_MemoryBurst=DMA_MemoryBurst_Single;
DMA_InitStructure.DMA_PeripheralBurst=DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream5, &DMA_InitStructure);
DMA_Cmd(DMA1_Stream5, ENABLE);
//DMA_ITConfig(DMA1_Stream5, DMA_IT_TC|DMA_IT_TE,ENABLE);
}
DAC的配置如下:
void DAC_Configuration(void)
{
DAC_InitTypeDef DAC_InitStructure;
DAC_DeInit();
DAC_StructInit(&DAC_InitStructure);
DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;//²»²úÉú²¨ÐÎ
DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Disable; //²»Ê¹ÄÜÊä³ö»º´æ
DAC_InitStructure.DAC_Trigger = DAC_Trigger_T6_TRGO;//DAC´¥·¢Æ÷Ϊ¶¨Ê±Æ÷6´¥·¢
DAC_Init(DAC_Channel_1, &DAC_InitStructure); //
DAC_Cmd(DAC_Channel_1, ENABLE); //
DAC_DMACmd(DAC_Channel_1, ENABLE); //
}
TIM6的配置如下:
/////////////////////////// TIM6用作DAC的触发 配置如下 //////////////////////////////////////////////////////////////////////////////
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = 50; //
TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
TIM_SelectOutputTrigger(TIM6, TIM_TRGOSource_Update);
TIM_Cmd(TIM6, ENABLE);
/////////////////////////////////////////////////////////////////////////////////////////////////////////
请高手帮我看看,我想用STM32F207的DMA+DAC+TIM6输出正玄波,现在遇到问题,不知道哪里不对,总是没有预期结果出来。有知道的请加我微信:18123784178,谢谢。
DMA循环只是说DMA循环,不没有指定DMA的数据地址。数据DMA到DAC完了后,需要重置数据指针
具体该怎么做呢?我用了你的代码,出来了杂波,不是正玄波,估计是没有重置数组指针,请问这个在什么时候什么地方做这一步动作?谢谢
一周热门 更多>