请教串口4问题,谢谢

2019-07-21 01:03发布

[mw_shl_code=c,true] GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA,ENABLE); //????GPIOA?±?? RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4,ENABLE);//????UART4?±?? //?®??1???????????????? GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_UART4); //GPIOA1??????UART4 GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_UART4); //GPIOA0??????UART4 //USART1???????? GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0; //GPIOA9??GPIOA10 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//???????? GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //????50MHz GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //???ì???????? GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //???­ GPIO_Init(GPIOA,&GPIO_InitStructure); //??????PA1??PA0 //UART4 ???????è?? USART_InitStructure.USART_BaudRate = bound;//?¨?????è?? 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(UART4, &USART_InitStructure); //???????®??1 USART_Cmd(UART4, ENABLE); //?????®??4 USART_ClearFlag(UART4, USART_FLAG_TC); USART_ClearFlag(UART4, USART_IT_RXNE); USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);//?????à?????? //Usart1 NVIC ???? NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;//?®??4?????¨?? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//??????????3 NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //×???????3 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨?????? NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????VIC?????÷??[/mw_shl_code]
用的是串口1实验的程序,其他地方没动,遇到的问题是我没有发送数据,但是会不断走进中断函数里面,即使悬空也是会进入中断里面,还会有数据接收到!但是如果我换成串口1的话一切正常,请问到底怎么回事啊?谢谢指教。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。