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初始化和發(fā)送函數(shù)如上,hw_uart4_send_bytes發(fā)送數(shù)據(jù),PA5沒(méi)任何波形輸出,芯片為CH32X033F8P6。