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] 工程帮忙在附件,请各位大神帮忙


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
11条回答
安宁和平
2019-07-21 16:17
回复【3楼】waitig:
---------------------------------
回复【2楼】STM32VBT6:
---------------------------------
int fputc(int ch, FILE *f)
{
/* ??Printf????·??ù???? */
  USART_SendData(USART2, (unsigned char) ch);
  while (!(USART2->SR & USART_FLAG_TXE));
  return (ch);
}

int fputc(int ch, FILE *f)
{      
while((USART2->SR&0X40)==0);//???··???,?±??·????ê±?   
    USART2->DR = (u8) ch;      
return ch;
}
寄存器版的和库函数版的都试过了,还是不行

一周热门 更多>