打印

启用串口中断,后串口就莫名其妙的不工作?求大神点解

[复制链接]
338|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
稻花香1号|  楼主 | 2018-7-4 20:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我刚在开始调试程序,直接使用printf函数可以打印字符串,但是当调用USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);USART_ITConfig(USART1, USART_IT_TXE, ENABLE);开启接收和发送使能后,串口即不能工作,求解释。本来是准备自己去查的,但是看到可以作为第一个发帖的人,所以就先抢这个先机了。
初始化函数如下:
void UASRT1_Init(void)
{
         /*????????*/
        GPIO_InitTypeDef        GPIO_InitStructure;
        USART_InitTypeDef        USART_InitStucture;

        /*??????*/
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_USART1,ENABLE);

        /*????*/
        /*??????PA.9*/
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;//?????
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//????????
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//??????????
        GPIO_Init(GPIOA,&GPIO_InitStructure);

        /*??????PA.10*/
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;//?????
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//????????
        //GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//??????????
        GPIO_Init(GPIOA,&GPIO_InitStructure);

        /*????????*/
        USART_InitStucture.USART_BaudRate=19200;
        USART_InitStucture.USART_WordLength=USART_WordLength_8b;
        USART_InitStucture.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
        USART_InitStucture.USART_StopBits=USART_StopBits_1;
        USART_InitStucture.USART_Parity=USART_Parity_No;
        USART_InitStucture.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;

        USART_Init(USART1,&USART_InitStucture);

         /* Enable USARTy Receive and Transmit interrupts */
//          USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
//          USART_ITConfig(USART1, USART_IT_TXE, ENABLE);

        USART_Cmd(USART1, ENABLE);
}

其中中文注释因keil没设置GB2312代码,所以显示不了。大家将就着看下吧

使用特权

评论回复

相关帖子

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

本版积分规则

381

主题

382

帖子

1

粉丝