攻城狮小黄 发表于 2017-9-23 09:20:20

stm32f103串口3的接收中断进不去

以下是我的串口3的初始化程序和中断程序,大神们请帮小弟看看,问题出在哪儿了,不胜感激
void USART3_Init(void)
{
        GPIO_InitTypeDefGPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
      NVIC_InitTypeDefNVIC_InitStructure;
       
        /* config USART3 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
       
        /* USART3 GPIO config */
        /* Configure USART3 Tx (PB.10) as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOB, &GPIO_InitStructure);   
        /* Configure USART3 Rx (PB.11) as input floating */
        GPIO_InitStructure.GPIO_Pin= GPIO_Pin_11;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
          
        /* USART3 mode config */
        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_HardwareFlowControl = USART_HardwareFlowControl_None;
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
        USART_Init(USART3, &USART_InitStructure);

      NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
      NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQChannel;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;               
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;       
        NVIC_Init(&NVIC_InitStructure);
       
        USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
      USART_Cmd(USART3, ENABLE);
}


void USART3_IRQHandler(void)
{

if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
    /* Read one byte from the receive data register */
    RXBuffer = (USART_ReceiveData(USART3) & 0x7F);         

    /* Clear the USART1 Receive interrupt */
    USART_ClearITPendingBit(USART3, USART_IT_RXNE);

    if(RXCounter == 100)
    {
      /* Disable the USART Receive interrupt */
      USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
    }
}
}

MrJiu 发表于 2017-9-23 09:43:17

标准库?上HAL,一键化配置!!!!

anobodykey 发表于 2017-9-23 09:48:00

可以看看能不能输出,确定外设是好的

斜阳 发表于 2017-9-23 10:00:35

推荐CubeMX配置工程。方便快捷

攻城狮小黄 发表于 2017-9-23 16:54:47

anobodykey 发表于 2017-9-23 09:48
可以看看能不能输出,确定外设是好的

输出没有问题

YY777 发表于 2023-12-6 18:20:49

大佬想问下怎么解决的呀?
页: [1]
查看完整版本: stm32f103串口3的接收中断进不去