最近调试CH32V103C8T6发现配置了IDLE和RXNE中断后,无法进入USART1_IRQHandler中断,接收的数据也是乱码;


1. 串口中断实现
void USART1_IRQHandler(void)

{

    if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

    {

            //hwUart_Callback();

    }

    if (USART_GetITStatus(USART1, USART_IT_IDLE) != RESET)

    {

        USART1->STATR;

        USART1->DATAR;//清除IDLE标志位

        hwUart_Callback();

    }

}

2. 注册中断

USART_ITConfig((USART_TypeDef*)UARTN[uartn], USART_FLAG_IDLE, ENABLE);//注册IDLE中断

    USART_ITConfig((USART_TypeDef*)UARTN[uartn], USART_FLAG_RXNE, ENABLE);//注册RXNE中断

3. gpio初始化
    gpio_init(A9, GPO, 0, SPEED_50MHZ|OUT_AF_PP);

    gpio_init(A10, GPI, 0, IN_FLOAT);

4. 串口配置

    USART_InitStructure.USART_BaudRate = baud;

    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_InitStructure.USART_Mode = USART_Mode_Rx;


    //使能串口

    USART_Init((USART_TypeDef*)UARTN[uartn], &USART_InitStructure);

    USART_Cmd((USART_TypeDef*)UARTN[uartn], ENABLE);

5. 调试现象具体描述:
    USART1_IRQHandler中断时进入过的,但是USART_IT_IDLE始终无法进入,串口发送功能正常,接收只能时一个字节且是乱码。

串口IDLE可以参考这个https://www.cnblogs.com/wchmcu/p/17101580.html

还有问题可以发送到邮箱zc@wch.cn


谢谢,解决了,感谢呀。


只有登录才能回复,可以选择微信账号登录