STM32F103ZET6的UART2能接收到数据,不能发送数据!

2019-07-21 01:24发布

把战舰开发板上的USART1串口改成USART2通信,结果能正确收到数据却不能发送数据。
usart2初始化如下:
[mw_shl_code=c,true]void uart2_init(u32 bound){ GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* config USART2 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); USART_DeInit(USART2); //USART2_TX PA.2 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; //PA.9 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); //USART2_RX PA.3 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;//???????? GPIO_Init(GPIOA, &GPIO_InitStructure); //??????PA10 //Usart1 NVIC ???? NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); //USART ???????è?? USART_InitStructure.USART_BaudRate = bound; 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(USART2, &USART_InitStructure); USART_ITConfig(USART2, USART_IT_RXNE, ENABLE); USART_Cmd(USART2, ENABLE); }[/mw_shl_code] MAIN函数代码如下
[mw_shl_code=c,true]int main(void) { u16 times; u8 t,len; delay_init(); //???±?????????? uart2_init(9600); TIM3_Int_Init(9,7199); LED_Init(); //LED?????????? Usart_SendChar(USART2,'b'); while(1) { if((USART_RX_STA>0)&(tt>3)) { len=USART_RX_STA&0x3fff;//?????????????????????¤?? printf(" ?ú·???????????:"); for(t=0;t<len;t++) { Usart_SendChar(USART2,USART_RX_BUF[t]); } printf(" ");//???????? USART_RX_STA=0; } else { times++; if(times%500==0) { Usart_SendChar(USART2,'a'); //printf("AT+CIPMUX=0 "); } if(times%30==0)LED0=!LED0;//????LED,?á??????????????. delay_ms(10); } } }[/mw_shl_code] 工程帮忙在附件,请各位大神帮忙


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