我的配置程序如下:
void UART_Config(void)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure USART1 Tx(PA.09) as alternate function open-drain */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = RS485_TXD1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART3 Tx(PC.10) as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = RS232_TXD4;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART3 Tx(PB.10) as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = ALARM_TXD3;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART1_Rx(PA.10) as input floating */
GPIO_InitStructure.GPIO_Pin = RS485_RXD1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART1_Rx(PC.11) as input floating */
GPIO_InitStructure.GPIO_Pin = RS232_RXD4;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART1_Rx(PB.11) as input floating */
GPIO_InitStructure.GPIO_Pin = ALARM_RXD3;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* USARTx configuration ------------------------------------------------------*/
/* USARTx configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitStructure.USART_BaudRate = 115200;
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;
/* Configure the USARTx */
USART_Init(UART4, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
/* Enable the USARTx */
USART_Cmd(UART4, ENABLE);
/* Configure the USARTx */
USART_Init(USART3, &USART_InitStructure);
/* Enable USART1 Receive and Transmit interrupts */
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
/* Enable the USARTx */
USART_Cmd(USART3, ENABLE);
}
UART4能收能接,USART3却是不能发送数据,只能接受 |