stm32F407 串口中断进不去 急 已经一周了!!

2019-03-23 19:01发布

程序如下:
GPIO_Configuration();
  USART_Configuration();
  NVIC_Configuration();
void GPIO_Remap_Configuration(void);

/*    GPIO   */
GPIO_InitTypeDef  GPIO_InitStructure;
void GPIO_Configuration(void)
{
  /* GPIO clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB|RCC_AHB1Periph_GPIOC|RCC_AHB1Periph_GPIOD|RCC_AHB1Periph_GPIOE, ENABLE
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  GPIO_PinAFConfig(GPIOD,GPIO_PinSource5,GPIO_AF_USART2);
  GPIO_PinAFConfig(GPIOD,GPIO_PinSource6,GPIO_AF_USART2);
  GPIO_StructInit(&GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

void USART_Configuration(void)
{
        GPIO_InitTypeDef  GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;       
        USART_ClockInitTypeDef USART_ClockInitStruct;        


        //USART_DeInit(USART2);
        //USART_StructInit(&USART_InitStructure);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);
          RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
        USART_InitStructure.USART_BaudRate = 9600;
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        USART_InitStructure.USART_Parity = USART_Parity_No ;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

        USART_Init(USART2, &USART_InitStructure);
        USART_ClockStructInit(&USART_ClockInitStruct);
        USART_ClockInit(USART2, &USART_ClockInitStruct);
        USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART2,ENABLE);  

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void USART2_IRQHandler(void)
{
      int tmp;
          if(USART_GetITStatus(USART2,USART_IT_RXNE) != RESET)
  {
    Recieve_Data = USART_ReceiveData(USART2);
    USART_ClearITPendingBit(USART2, USART_IT_RXNE);
             tmp=USART_ReceiveData(USART2);
             USART_SendData(USART2,tmp);
  }
}

串口中断一直进不去 中断初始化完了直接就跳出了! 本人刚接触STM32F407希望各路大神指点!不胜感激!! 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。