哪里有CH32F207VCT6串口4的代碼例子。要做套設(shè)備,6串口的。現(xiàn)在只搞定了1、2、3串口,
以下是參照別人的代碼,發(fā)送沒問題了,但是接收不到數(shù)據(jù)
void uart4_init(u32 bound4){
? ? //GPIO端口設(shè)置
? ? 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 初始化設(shè)置
? ? USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字長(zhǎng)為8位數(shù)據(jù)格式
? ? USART_InitStructure.USART_StopBits = USART_StopBits_1;//一個(gè)停止位
? ? USART_InitStructure.USART_Parity = USART_Parity_No;//無奇偶校驗(yàn)位
? ? USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//無硬件數(shù)據(jù)流控制
? ? USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //收發(fā)模式
? ? 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:接收中斷標(biāo)志位
? ? 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); //讀取接收到的數(shù)據(jù)
? ? ? ? USART_SendData(UART4, Res);//返回接收的數(shù)據(jù)
? ? }
}