美文网首页
GD32 USART0串口空闲中断的配置(非DMA空闲中断)

GD32 USART0串口空闲中断的配置(非DMA空闲中断)

作者: 骑上我心爱的小蜗牛 | 来源:发表于2020-08-25 11:31 被阅读0次

    中断服务函数的配置

    /*!
        \brief      this function handles USART0 exception
        \param[in]  none
        \param[out] none
        \retval     none
    */
    void USART0_IRQHandler(void)
    {
        uint8_t clea123r = clea123r;
        if (RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_RBNE))
        {
            Com0_rx_buffer[Com0_rx_counter++] = (uint8_t)usart_data_receive(USART0);
        }else if(RESET != usart_interrupt_flag_get(USART0, USART_INT_FLAG_IDLE))
            {
                usart_interrupt_flag_clear(USART0,USART_INT_FLAG_IDLE); /* 清除空闲中断标志位 */
                usart_data_receive(USART0); /* 清除接收完成标志位 */
                Com0_rx_counter=0;
                printf("com0 idle test rx:%s\r\n",Com0_rx_buffer);
                memset(Com0_rx_buffer,0,strlen((char *)Com0_rx_buffer));
        
            }
    }
    

    com0_usart0的初始化配置

    void com0_init(void)
    {
        /* com init config */
        gd_eval_com_init(EVAL_COM0);
        nvic_irq_enable(USART0_IRQn,0,1);
        usart_interrupt_enable(USART0, USART_INT_RBNE);         /* 使能USART0读区非空中断 */  
        usart_interrupt_enable(USART0, USART_INT_IDLE);         /* 使能USART0空闲中断 */
    }
    
    /*!
        \brief      configure COM port
        \param[in]  com: COM on the board
          \arg        EVAL_COM0: COM0 on the board
          \arg        EVAL_COM1: COM1 on the board
        \param[out] none
        \retval     none
    */
    void gd_eval_com_init(uint32_t com)
    {
        uint32_t com_id = 0U;
        if(EVAL_COM0 == com){
            com_id = 0U;
        }else if(EVAL_COM1 == com){
            com_id = 1U;
        }
        
        /* enable GPIO clock */
        rcu_periph_clock_enable(COM_GPIO_CLK[com_id]);
    
        /* enable USART clock */
        rcu_periph_clock_enable(COM_CLK[com_id]);
    
        /* connect port to USARTx_Tx */
        gpio_init(COM_GPIO_PORT[com_id], GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, COM_TX_PIN[com_id]);
    
        /* connect port to USARTx_Rx */
        gpio_init(COM_GPIO_PORT[com_id], GPIO_MODE_IN_FLOATING, GPIO_OSPEED_50MHZ, COM_RX_PIN[com_id]);
    
        /* USART configure */
        usart_deinit(com);
        usart_baudrate_set(com, 115200U);
        usart_word_length_set(com, USART_WL_8BIT);
        usart_stop_bit_set(com, USART_STB_1BIT);
        usart_parity_config(com, USART_PM_NONE);
        usart_hardware_flow_rts_config(com, USART_RTS_DISABLE);
        usart_hardware_flow_cts_config(com, USART_CTS_DISABLE);
        usart_receive_config(com, USART_RECEIVE_ENABLE);
        usart_transmit_config(com, USART_TRANSMIT_ENABLE);
        usart_enable(com);
    }
    
    

    相关文章

      网友评论

          本文标题:GD32 USART0串口空闲中断的配置(非DMA空闲中断)

          本文链接:https://www.haomeiwen.com/subject/pfwajktx.html