STM32F407 USART6使用问题

2019-07-20 05:53发布

原来使用过STM32F407的USART2,收发送数据没有问题,这次使用USART6,将原来的USART2配置改成了USART6,却出现了问题,调适发现程序在while( (USART_GetFlagStatus(UsARTx,USART_FLAG_TXE) != SET));死循环了。在发送缓冲区为空的时候,TXE应该为1,USART2时没问题,USART6时却为0,导致了死循环。在将USART2改为USART6时也特别注意了,USART6是挂在APB2下的,其他的还有什么要改的吗?下面是我的USART6配置程序,为什么会导致TXE不为1呢?

[mw_shl_code=c,true] void USART6_Config(u32 bound){    //GPIO配置    GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //????GPIOC?±?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);//????USART6?±?? GPIO_PinAFConfig(GPIOC,GPIO_PinSource6,GPIO_AF_USART6); //GPIOC6??????USART6 GPIO_PinAFConfig(GPIOC,GPIO_PinSource7,GPIO_AF_USART6); //GPIOC7??????USART6    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; //GPIOC6??GPIOC7 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(GPIOC,&GPIO_InitStructure); //??????PC6??PC7    //USART6 ???????è?? 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(USART6, &USART_InitStructure); //???????®??6    USART_Cmd(USART6, ENABLE); //?????®??6 USART_ClearFlag(USART6, USART_FLAG_TC); } void USART6_IT_Config(void) {    NVIC_InitTypeDef NVIC_InitStructure; USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);//?????à??????    USART_ITConfig(USART6, USART_IT_TXE, ENABLE); //Usart6 NVIC ????    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//?è????????????????·?×é2    NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;//?®??6?????¨?? NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//??????????3 NVIC_InitStructure.NVIC_IRQChannelSubPriority =2; //×???????2 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ?¨?????? NVIC_Init(&NVIC_InitStructure); //?ù?????¨????????????NVIC?????÷?? } [/mw_shl_code]




友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。