CH32X033F8 UART4问题

void hw_uart4_init(u32 band)

{

    GPIO_InitTypeDef GPIO_InitStructure = { 0 };

    USART_InitTypeDef USART_InitStructure = { 0 };

    NVIC_InitTypeDef NVIC_InitStructure = { 0 };


    RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART4, ENABLE );

    RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE );

    USART_DeInit(USART4);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

    GPIO_Init( GPIOA, &GPIO_InitStructure );


    GPIO_PinRemapConfig(GPIO_PartialRemap1_USART4, ENABLE);


    USART_InitStructure.USART_BaudRate = baund;

    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_Tx;

    USART_Init( USART4, &USART_InitStructure );


    USART_Cmd( USART4, ENABLE );


}

void hw_uart4_send_bytes(u8 *xbuf, u16 slen)

{

     u16 i;

     for(i = 0; i < slen; i++)

     {

         while(USART_GetFlagStatus(USART4, USART_FLAG_TC) == RESET);

         USART_SendData(USART4, xbuf[i]);

     }

}

 uart4初始化和发送函数如上,hw_uart4_send_bytes发送数据,PA5没任何波形输出,芯片为CH32X033F8P6。


使用PA5作为UART4的TX引脚需要做端口重映射映射,看你的程序,没有打开AFIO时钟,同时端口重映射的函数要在GPIO初始化之前调用才能有效。


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