【基本情况】CPU:
STM32F207IG 利用
tiM5的CH2通道产生PWM波,开启DMA,利用TIM5更新事件请求DMA搬运。搬运数组数值到TIM5->ARR寄存器。
目前进不去DMA中断,不知道是哪里配置的问题……
【函数如下】
void TIM5_PWM_Configeration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOH,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOH, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOH,GPIO_PinSource11,GPIO_AF_TIM5);
TIM_DeInit(TIM5);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE);
TIM_TimeBaseInitStruct.TIM_Period =1499;
TIM_TimeBaseInitStruct.TIM_Prescaler =CPU_FREQUENCE/F2TIME_PARA-1;
TIM_TimeBaseInitStruct.TIM_ClockDivision =TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseInitStruct.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM5, &TIM_TimeBaseInitStruct);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 749;
TIM_OC2Init(TIM5, & TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable);
Initial_DMA();
TIM_DMACmd(TIM5, TIM_DMA_Update, ENABLE);
TIM_ARRPreloadConfig(TIM5,ENABLE);
TIM_CtrlPWMOutputs(TIM5,ENABLE);
TIM_Cmd(TIM5,ENABLE);
}
void Initial_DMA(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1,ENABLE);
DMA_DeInit(DMA1_Stream4);
DMA_StructInit(&DMA_InitStructure_M2);
DMA_InitStructure_M2.DMA_Channel = DMA_Channel_6;
DMA_InitStructure_M2.DMA_PeripheralBaseAddr = (uint32_t)TIM5_ARR_ADDRESS; // 0x40000C2C
DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0;
DMA_InitStructure_M2.DMA_DIR = DMA_DIR_MemoryToPeripheral;
DMA_InitStructure_M2.DMA_BufferSize = 10;
DMA_InitStructure_M2.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure_M2.DMA_MemoryInc = DMA_MemoryInc_Disable;
DMA_InitStructure_M2.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure_M2.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure_M2.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure_M2.DMA_Priority = DMA_Priority_High;
DMA_InitStructure_M2.DMA_FIFOMode = DMA_FIFOMode_Disable;
DMA_InitStructure_M2.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStructure_M2.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStructure_M2.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2);
DMA_ClearFlag(DMA1_Stream4,DMA_FLAG_TCIF4);
DMA_ITConfig(DMA1_Stream4,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA1_Stream4, DISABLE);
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =PWM2_PreemptionPriority;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = PWM2_SubPriority;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
补充一下,DMA配置函数中 DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)0; 并未赋值,在程序启动后进行了如下设置:
DMA_Cmd(DMA1_Stream4, DISABLE);
DMA_InitStructure_M2.DMA_Memory0BaseAddr = (uint32_t)addr; //搬运的是定时器需要配置的PWM频率数值
DMA_InitStructure_M2.DMA_BufferSize = len; //希望DMA在搬运len长度数据以后进入DMA中断
DMA_Init(DMA1_Stream4, &DMA_InitStructure_M2);
DMA_Cmd(DMA1_Stream4, ENABLE);
DMA_MemoryDataSize_HalfWord改为DMA_MemoryDataSize_Word
同时内存数组也用32bit的来传。
一周热门 更多>