如题,我一个项目里,ADC通过DMA进行采样,DMA采满后进入DMA中断函数,进入函数后,打开定时器开始计时,同时处理DMA中断里面的程序,定时到后操作定时器中断,然后退出DMA中断再次采样。可是为什么每次进DMA中断后,定时器没有计时就直接操作定时器中断操作了。设置有问题吗
- void TIM3_Int_Init()
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
- TIM_TimeBaseInitStructure.TIM_Period =3200-1 ;
- TIM_TimeBaseInitStructure.TIM_Prescaler=8400-1 ; //160ms
- TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;
- TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
- TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
- TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
- NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- TIM_Cmd(TIM3,DISABLE);
- }
- void TIM3_IRQHandler(void)
- {
- if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)
- {
- TIM_ClearITPendingBit(TIM3, TIM_IT_Update );
- if(!N_3)
- {
- GPIO_SetBits(GPIOA,GPIO_Pin_7);
- }
- else
- {
- GPIO_ResetBits(GPIOA,GPIO_Pin_7);
- }
- N_3=!N_3;
- change=1;
- }
- }
- void DMA2_Stream1_IRQHandler(void)
- {
- int i=0;
- TIM_Cmd(TIM3,ENABLE);
- /*************************/
- (数据处理,忽略)/*************************/
- while(!change);
- DMA_ClearFlag(DMA2_Stream1,DMA_FLAG_TCIF1);
- TIM_Cmd(TIM3,DISABLE);
- TIM3_Int_Init();
- change=0;
-
- }
复制代码
请大神帮看看设置是否有问题。(AD采样时间为640ms)
此帖出自
小平头技术问答
一周热门 更多>