我的程序是想实现通过定时器引起DMA触发,产生pwm波,但是DMA传输的数据没有更新

2019-07-21 06:25发布

求助:我的程序是想实现通过定时器引起DMA触发,产生pwm波,但是DMA传输的数据没有更新
求大家帮帮忙,看一下,谢谢大家
           1、为什么我编写的程序中定时器引起的DMA触发,DMA传送数据没有更新呢
          2、使用定时器TIM3的CCR1基地址引起DMA触发时,我使用的是DMA的6通道。而我看见有很多程序使用的是DMA的3通道,即TIM3_UP在DMA中对应的通道?
          3、TIM_DMACmd(TIM3, TIM_DMA_Update, ENABLE);与TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE)语句不能同时使用吗,为什么呢?区别是什么呢?
          4、我的程序中DMA_InitStructure.DMA_PeripheralBaseAddr =TIM3_CCR1_Base ;为什么有的程序中将外设基地址设成 TIM_DMAR_Base?
以下是我写的程序
  #include "stm32f10x.h"
#define TIM3_CCR1_Base 0x4000434
u16 buf[36] = {500,800,700,600,500,400,300,200, 100,90,80,70,60,50,40,30,20,10,10,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900};

void DMA_Configuration(void)
{
DMA_InitTypeDef DMA_InitStructure;
DMA_DeInit(DMA1_Channel6); 
DMA_InitStructure.DMA_PeripheralBaseAddr =TIM3_CCR1_Base ;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)buf;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = 36;
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_M2M = DMA_M2M_Disable;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
DMA_Cmd(DMA1_Channel6, ENABLE);

}
static  void  RCC_Config(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); 
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); 

}
static void GPIO_Config(void) 

GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_6;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}

static  void  TIM3_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period = 999;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 2;//???????????????????à????????????????
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; 
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; 
TIM_OCInitStructure.TIM_Pulse = buf[0];
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM3, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM3, ENABLE);
//TIM_DMAConfig(TIM3, TIM_DMABase_CCR1, TIM_DMABurstLength_2Bytes);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);//?????¨?±?÷?ü??±ê????
TIM_Cmd(TIM3, ENABLE); 
TIM_DMACmd(TIM3, TIM_DMA_Update, ENABLE);//?????¨?±?÷?ü??
//TIM_DMACmd(TIM3, TIM_DMA_CC1, ENABLE); 
//TIM_CtrlPWMOutputs(TIM3, ENABLE);
}
int main(void)
{
 RCC_Config();
 GPIO_Config();
 TIM3_Config();
 DMA_Configuration();


while (1);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。