CH32V208無法進入串口中斷

串口配置完成可以發(fā)送但是無法接收

void?USART1_Init(void)
{
????GPIO_InitTypeDef??GPIO_InitStructure={0};
????USART_InitTypeDef?USART_InitStructure={0};
????NVIC_InitTypeDef??NVIC_InitStructure={0};

????/*?打開GPIO和USART部件的時鐘?*/
????RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA?|?RCC_APB2Periph_AFIO,?ENABLE);
????RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,?ENABLE);

????/*?配置GPIO的模式和IO口?*/
????GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;????????????//?串口輸出PA9(TX)
????GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;????//?IO口頻率
????GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;??????//?復用推挽輸出
????GPIO_Init(GPIOA,&GPIO_InitStructure);??????????????//?初始化
????GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;???????????//?串口輸入PA10(RX)
????GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;//?浮空輸入
????GPIO_Init(GPIOA,&GPIO_InitStructure);??????????????//?初始化

????/*?配置串口硬件參數?*/
????USART_InitStructure.USART_BaudRate?=?115200;????/*?波特率?*/
????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_Rx?|?USART_Mode_Tx;
????USART_Init(USART1,?&USART_InitStructure);

????/*?使能串口1中斷?*/
????NVIC_InitStructure.NVIC_IRQChannel?=?USART1_IRQn;
????NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?1;
????NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?1;
????NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
????NVIC_Init(&NVIC_InitStructure);

????USART_ITConfig(USART1,?USART_IT_RXNE,?ENABLE);????/*?使能串口空閑中斷?*/
????USART_Cmd(USART1,?ENABLE);????????/*?使能串口?*/
}



void?USART1_IRQHandler(void)
{
????if(USART_GetITStatus(USART1,?USART_IT_RXNE)?!=?RESET)?//中斷產生
????{
		uint8_t?RxData?=?USART_ReceiveData?(USART1);
		?USART_ClearITPendingBit(USART1,USART_IT_RXNE);
	}
}


您好,中斷函數注意要加中斷聲明,參考下圖

image.png


void?USART1_IRQHandler(void)?__attribute__((interrupt("WCH-Interrupt-fast")));

char?Serial_RxPacket[100];

void?USART1_Init(void)

加了 還是不進中斷



通了,線斷了

代碼沒問題



只有登錄才能回復,可以選擇微信賬號登錄

国产91精品新入口,国产成人综合网在线播放,九热这里只有精品,本道在线观看,美女视频a美女视频,韩国美女激情视频,日本美女pvp视频