我根据stm32的库函数写的代码
下面是串口一的初始化代码
??? RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
??? GPIO_InitTypeDef? GPIO_InitStructure={0};
??? USART_InitTypeDef USART_InitStructure={0};
??? //NVIC_InitTypeDef NVIC_InitStructure;
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
??? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
??? GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
??? GPIO_Init(GPIOA, &GPIO_InitStructure);
?? GPIO_PinRemapConfig(GPIO_PartialRemap1_USART1, ENABLE);
??? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
??? 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;
//??? NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
//??? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=4 ;//抢占优先级4
//??? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;????? //子优先级4
//??? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;???????? //IRQ通道使能
//??? NVIC_Init(&NVIC_InitStructure); //根据指定的参数初始化VIC寄存器
??? USART_Init(USART1, &USART_InitStructure);
??? //USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//开启串口接受中断
??? USART_Cmd(USART1, ENABLE);
接下来是通过串口一发消息出来的代码,我直接放在main函数里面的
?? uint16_t Data=0x24;
??? while(1)
??? {
??????? USART_SendData(USART1, Data);
??????? Delay_Ms(500);
??? }
接下来是串口接收中断
void USART1_IRQHandler(void)
{
??? uint8_t rec = 0;
??? if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
??? {
??????????? USART_ClearITPendingBit(USART1, USART_IT_RXNE);
??????????? rec = USART_ReceiveData(USART1); //读取接收到的数据
????????????//把数据放到队列中,队列暂时没写
??? }
}
代码是参考stm32的库函数代码写的,我实在不知道哪里有问题了,还请赐教,拜托拜托
另外还想请教一下,usb虚拟的串口接收中断,是不是就是串口2的接收中断