哪里有CH32F207VCT6串口4的代码例子。要做套设备,6串口的。现在只搞定了1、2、3串口,
以下是参照别人的代码,发送没问题了,但是接收不到数据
void uart4_init(u32 bound4){
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_AFIO , ENABLE);
//串口引脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//USART 初始化设置
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字长为8位数据格式
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_Rx | USART_Mode_Tx; //收发模式
USART_InitStructure.USART_BaudRate = bound4;//串口波特率
USART_Init(UART4, &USART_InitStructure); //初始化串口
/*串口--4*/
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=4;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//开启串口接受中断 USART_IT_RXNE:接收中断标志位
USART_Cmd(UART4, ENABLE); //使能串口
}
__attribute__((interrupt("WCH-Interrupt-fast")))
void UART4_IRQHandler(void)
{
u8 Res;
if(USART_GetITStatus(UART4, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(UART4); //读取接收到的数据
USART_SendData(UART4, Res);//返回接收的数据
}
}