打印

STM32F103 ADC+DMA和UART2中断冲突问题求助

[复制链接]
5788|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zddpy|  楼主 | 2010-12-3 20:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
程序中使用了TIM2,UART1,UART2和ADC+DMA1中断,不加上UART2时都正常,加上UART2中断后,运行几分钟后ADC+DMA1的中断就不能进去了,更改了几种中断优先级方式后都没有解决。请大家看看是什么原因?
void NVIC_Configuration(void)
{
   NVIC_InitTypeDef NVIC_InitStructure;
#ifdef  VECT_TAB_RAM
  /* Set the Vector Table base location at 0x20000000 */
   NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
  /* Enable the TIM2 gloabal Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);
  /* Enable the DMA channel1 gloabal Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);  
  /* Enable Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStructure);  
  /* Enable Interrupt */
   NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//   NVIC_Init(&NVIC_InitStructure);  
}
沙发
zddpy|  楼主 | 2010-12-4 08:01 | 只看该作者
但定时中断一直能正常运行,启动ADC,
void TIM2_IRQHandler(void)
{
static INT16U count = 0;

  if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);

    ADC_SoftwareStartConvCmd(ADC1,ENABLE);
    // Start ADC1 Software Conversion     
    capture = TIM_GetCapture1(TIM2);
    TIM_SetCompare1(TIM2, capture + TimerCount_500);
  }
  else if (TIM_GetITStatus(TIM2, TIM_IT_CC2) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);
    capture = TIM_GetCapture2(TIM2);
    TIM_SetCompare2(TIM2, capture + CCR2_Val);
  }
  else if (TIM_GetITStatus(TIM2, TIM_IT_CC3) != RESET)
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);

    capture = TIM_GetCapture3(TIM2);
    TIM_SetCompare3(TIM2, capture + CCR3_Val);
  }
  else
  {
    TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);

    capture = TIM_GetCapture4(TIM2);
    TIM_SetCompare4(TIM2, capture + CCR4_Val);
  }
}

使用特权

评论回复
板凳
zddpy|  楼主 | 2010-12-4 08:06 | 只看该作者
void DMA1_Channel1_IRQHandler(void)
{
        static INT8U        channel = 0;
        static INT8U        vchannel = 0;

        if(DMA_GetITStatus(DMA1_IT_TC1)==SET)
        {
        gAllSampleData[channel]= ADC_ConvertedValue[0]&0x0fff;                 //ADC_IN0
        gVSampleData[vchannel] = ADC_ConvertedValue[1]&0x0fff;                 //ADC_IN1
        gDCSampleData[channel] = ADC_ConvertedValue[2]&0x0fff;                 //ADC_IN8
        if(++channel ==4){
              //一次的采样完成,设置数据处理标志位
            channel = 0;
              ADFinished = TRUE;
        }
          else {
              ADC_SoftwareStartConvCmd(ADC1,ENABLE);                                      /* Start ADC1 Software Conversion     */
        }
           DMA_ClearITPendingBit(DMA1_IT_TC1);       
        }
        else if(DMA_GetITStatus(DMA1_IT_HT1)==SET)
        {
           DMA_ClearITPendingBit(DMA1_IT_HT1);
        }

}

void USART1_IRQHandler(void)
{

        if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
        {
                UART1_Rec_Isr();
                /* Clear the USART1 Receive interrupt */
                USART_ClearITPendingBit(USART1, USART_IT_RXNE);
        }
        else if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)
        {
                UART1_Send_Isr();
                /* Clear the USART1 Receive interrupt */
                USART_ClearITPendingBit(USART1, USART_IT_TXE);
        }
}

/*******************************************************************************
* Function Name  : USART2_IRQHandler
* Description    : This function handles USART2 global interrupt request.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void USART2_IRQHandler(void)
{
        if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
        {
                UART2_Rec_Isr();
                /* Clear the USART1 Receive interrupt */
                USART_ClearITPendingBit(USART2, USART_IT_RXNE);
        }
        else if(USART_GetITStatus(USART2, USART_IT_TXE) != RESET)
        {
                UART2_Send_Isr();
                /* Clear the USART1 Receive interrupt */
                USART_ClearITPendingBit(USART2, USART_IT_TXE);
        }
}

使用特权

评论回复
地板
wubing1211| | 2010-12-4 12:33 | 只看该作者
路过

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

16

主题

34

帖子

0

粉丝