wanyisq 发表于 2017-12-27 18:05:18

STM32F030 串口中断问题

我用的是STM32F030K6
串口初始化程序如下:
      GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
      RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE );
       
        /*********ÅäÖÃUART1********************/
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource6, GPIO_AF_0);   //PB6 PB7?????UART1
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource7, GPIO_AF_0);    //?????????(?????)

        GPIO_PinAFConfig(GPIOB,GPIO_PinSource6, GPIO_AF_0);        
        GPIO_PinAFConfig(GPIOB,GPIO_PinSource7, GPIO_AF_0);

        /* Configure USART Tx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
        GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        /* Configure USART Rx as alternate function push-pull */
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;       
        GPIO_Init(GPIOB,&GPIO_InitStructure);
       
       
       
        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_Tx | USART_Mode_Rx ;
        USART_Init(USART1, &USART_InitStructure);
       
//        USART_ITConfig(USART1, USART_IT_TC, ENABLE);      
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        USART_Cmd(USART1, ENABLE);


      NVIC_InitTypeDef        NVIC_InitStructconfig;
       
        NVIC_InitStructconfig.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructconfig.NVIC_IRQChannelPriority = 1;
        NVIC_InitStructconfig.NVIC_IRQChannelCmd = ENABLE;
       
        NVIC_Init(&NVIC_InitStructconfig);



串口中断函数如下:

void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{        
                UsartType.RX_pData=(USART1->RDR & (uint16_t)0x01FF);
                USART_SendData(USART1,USART1->RDR);
                if(UsartType.RX_Size>=200)
                {
                        UsartType.RX_Size=0;
                }

            USART_ClearFlag(USART1,USART_IT_RXNE);
               
}

}

函数功能就是串口把接收到的数据再发出来。
目前的现象是在中断函数设置一个断点,进入断点后再全速运行,就接收不到数据了,无法进入中断。
哪位大神知道问题在哪

yklstudent-1794 发表于 2017-12-27 18:38:04

别在中断中设断点,全速运行看是否有问题

wanyisq 发表于 2017-12-27 18:52:53

yklstudent-1794 发表于 2017-12-27 18:38
别在中断中设断点,全速运行看是否有问题

全速运行没问题,就是如果调试程序的话,进入其他地方的断点(不在中断函数内)后,再全速运行也无法接收到数据。

hello_bug 发表于 2017-12-28 13:16:27

查看下中断标志位是否有变化。

wanyisq 发表于 2017-12-28 13:27:57

hello_bug 发表于 2017-12-28 13:16
查看下中断标志位是否有变化。

中断标志位没有变化 可以进中断 但是标志位进不去

yklstudent-1794 发表于 2017-12-28 14:19:02

仔细检查串口寄存器配置是否正常
页: [1]
查看完整版本: STM32F030 串口中断问题