F103 串口只配置发送不接收

2019-07-21 06:37发布

现在使用F103芯片,因为IO口不够实用,所以想使用USART1的TX作为调试端口,值发送调试信息,USART1的RX作为输入检测使用,如何初始化这2个GPIO口,我看了一下,好像RX作为输入检测和作为串口使用时的配置是一样的,有没有知道怎么配置的。



/* Configure USART1 Tx (PA9) as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = MCU_USART1_TXD_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure (PA10) as input floating */
GPIO_InitStructure.GPIO_Pin = MCU_LOWPOWER_PIN;//MCU_USART1_RXD_PIN;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
USART_InitTypeDef USART_InitStructure;
USART_DeInit(USART1);
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* Configure USART1 */
USART_InitStructure.USART_BaudRate = 57600;
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_Tx;
USART_Init(USART1, &USART_InitStructure);
USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
USART_Cmd(USART1, ENABLE);

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