//GPIO¶Ë¿ÚÉèÖà GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //ʹÄÜUSART2ʱÖÓ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹÄÜGPIOAʱÖÓ GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);//¸´ÓÃÍÆÍìÊä³ö GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);//¸´ÓÃÍÆÍìÊä³ö //USART1_TX GPIOA.2 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //¸´ÓÃÍÆÍìÊä³ö GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; // I/OÊä³öƵÂÊ 50 MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.2 GPIO_Init(GPIOA, &GPIO_InitStructure); //USART1_RX GPIOA.3 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; //PA.3 GPIO_Init(GPIOA, &GPIO_InitStructure); //Usart2 NVIC ÅäÖà NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPriority=2 ;//ÓÅÏȼ¶3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨµÀʹÄÜ NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝÖ¸¶¨µÄ²ÎÊý³õʼ»¯VIC¼Ä´æÆ÷ //USART ³õʼ»¯ÉèÖà USART_InitStructure.USART_BaudRate = bound2;//´®¿Ú²¨ÌØÂÊ 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_Init(USART2, &USART_InitStructure); //³õʼ»¯´®¿Ú2 USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);//¿ªÆô´®¿Ú2½ÓÊÜÖÐ¶Ï USART_Cmd(USART2, ENABLE); u8 aa; void USART2_IRQHandler(void) //´®¿Ú1ÖжϷþÎñ³ÌÐò { if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //½ÓÊÕÖжÏ(½ÓÊÕµ½µÄÊý¾Ý±ØÐëÊÇ0x0d 0x0a½áβ) { aa =USART_ReceiveData(USART2); //¶ÁÈ¡½ÓÊÕµ½µÄÊý¾Ý } } |
楼主怎么没有请中断标志位?
USART_ClearITPendingBit(USART2,USART_IT_RXNE);
评分
查看全部评分