stm32 ucosIII中使用USART1,USART2,USART3三个串口中断有问题

2019-08-23 16:40发布

最近研究uCOSIII,但是今天在同时用三个串口得时候发现配置好之后三个串口发数据没有问题,USART1接收中断正常,USART2和3不能进入中断,调试跟了一下接收到数据后USART1直接到中断服务函数里,USART2和3都不能进到中断服务函数里,下面附上配置USART1-3得代码,各位帮忙看下,万分感谢!@正点原子 [mw_shl_code=applescript,true]GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        NVIC_InitTypeDef NVIC_InitStructure;
         
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);       
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2|RCC_APB1Periph_USART3,ENABLE);
        USART_DeInit(USART1);  //¸´Î»´®¿Ú123
        USART_DeInit(USART2);
        USART_DeInit(USART3);
       
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       
    GPIO_Init(GPIOA, &GPIO_InitStructure);
   
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
       
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;       
    GPIO_Init(GPIOB, &GPIO_InitStructure);
               
                GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

   //Usart1 NVIC ÅäÖÃ

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;//ÇÀÕ¼ÓÅÏȼ¶3
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;                //×ÓÓÅÏȼ¶3
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                        //IRQͨµÀʹÄÜ
        NVIC_Init(&NVIC_InitStructure);        //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷
       
         //USART ³õʼ»¯ÉèÖÃ
        USART_InitStructure.USART_BaudRate = USART1BaudRate;
        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(USART1, &USART_InitStructure);
   USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
   USART_Cmd(USART1, ENABLE);     
       
       
        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3 ;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;       
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;               
        NVIC_Init(&NVIC_InitStructure);       
       
        USART_InitStructure.USART_BaudRate = USART2BaudRate;
        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(USART2, &USART_InitStructure);
    USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
    USART_Cmd(USART2, ENABLE);
       
       
        NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority= 3;
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;       
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;               
        NVIC_Init(&NVIC_InitStructure);               
       
        USART_InitStructure.USART_BaudRate = USART3BaudRate;
        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);
    USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
    USART_Cmd(USART3, ENABLE);[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
6条回答
正点原子 发表于 2017-3-24 18:39
请先在我们串口实验的基础上(不要用OS),实现串口1+串口2的数据收发,然后再实现串口1+串口2+串口3的收发 ...

这个就是在串口实验基础上增加了串口2和3,裸机跑得是正常得,但是加上了ucosIII之后就出现了这个情况,ucosIII也是用的原子哥你们得例程。现在用得C8T6芯片,然后刚刚我用RBT6试了一下竟然没有问题,我就郁闷了……不清楚式哪里得问题,加上os之后中断都进不去

一周热门 更多>