问题:DMA传输不能启动
实验目标:学习定时器的DMA
实验方法:参考原子哥输入捕获的例程,运用TIM14产生PMW波,TIM5通道1输入捕获并产生DMA请求,捕获1000次时产生DMA中断,在DMA中断服务函数中计算频率
实验平台:探索者开发板
部分代码:
//输入捕获通道,DMA及其配置
void TIM5_CH1_Cap_Init(u32 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_ICInitTypeDef TIM5_ICInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5,ENABLE); //TIM5时钟使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //使能PORTA时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //Pin0
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //速度100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //下拉
GPIO_Init(GPIOA,&GPIO_InitStructure); //初始化PA0
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM5); //PA0复用位定时器5
TIM_TimeBaseStructure.TIM_Prescaler=psc; //定时器分频
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseStructure.TIM_Period=arr; //自动重装载值
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM5,&TIM_TimeBaseStructure);
//初始化TIM5输入捕获参数
TIM5_ICInitStructure.TIM_Channel = TIM_Channel_1; //CC1S=01 选择输入端 IC1映射到TI1上
TIM5_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; //上升沿捕获
TIM5_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; //映射到TI1上
TIM5_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; //配置输入分频,不分频
TIM5_ICInitStructure.TIM_ICFilter = 0x00; //IC1F=0000 配置输入滤波器 不滤波
TIM_ICInit(TIM5, &TIM5_ICInitStructure);
//NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn; //把参考例程中的中断源改为DMA
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Stream2_IRQn; //DMA中断源
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 2; //抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //子优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道使能
NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
MYDMA_Config(DMA1_Stream2,DMA_Channel_6,(u32)&TIM5->CCR1,(u32)Rx_Buf_Tim_Dma1,RX_BUF_SIZE); //参考DMA例程配置
//TIM_ITConfig(TIM5,TIM_IT_Update|TIM_IT_CC1,ENABLE);//允许更新中断 ,允许CC1IE捕获中断
DMA_ITConfig(DMA1_Stream2,DMA_IT_TC,ENABLE); //使能传输完成中断
TIM_DMAConfig(TIM5,TIM_DMABase_CCR1,TIM_DMABurstLength_4Transfers); //配置捕获时DMA请求
TIM_DMACmd(TIM5,TIM_DMA_CC1,ENABLE); //产生DMA请求
TIM_Cmd(TIM5,ENABLE ); //使能定时器5
DMA_Cmd(DMA1_Stream2,ENABLE); //打开DMA
}
//DMA中断服务函数
u8 iFlag=0;
void DMA1_Stream2_IRQHandler()
{
if(DMA_GetITStatus(DMA1_Stream2,DMA_IT_TCIF2)==SET)
{
DMA_ClearITPendingBit(DMA1_Stream2,DMA_IT_TCIF2);
iFlag=1;
TIM_Cmd(TIM5,DISABLE); //关闭定时器5
TIM_SetCounter(TIM5,0);
TIM_Cmd(TIM5,ENABLE ); //使能定时器5
}
}
问题:中断服务函数中判断条件 if(DMA_GetITStatus(DMA1_Stream2,DMA_IT_TCIF2)==SET)永远不为真
求大神指点!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>