GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; GPIO_PinRemapConfig(GPIO_Remap_USART2,ENABLE); /* Enable USART2 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* USART2 remap to PD5 PD6 */ /* Configure the GPIO ports( USART2 Transmit and Receive Lines) */ /* Configure the USART2_Tx as Alternate function Push-Pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); /* Configure the USART2_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ; GPIO_Init(GPIOD, &GPIO_InitStructure); /* USART2 configuration ------------------------------------------------------*/ /* USART2 configured as follow: - BaudRate = 4800 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 = 4800; 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 USART2 */ USART_Init(USART2, &USART_InitStructure); /* Configure the USART2 RX interrupt */ USART_ITConfig(USART2,USART_IT_RXNE,ENABLE); /* Enable the USART2 */ USART_Cmd(USART2, ENABLE); 收发均不工作,没有Remap试过TX可以,RX没试(电路板不好试). |
RE:帮忙,32F101 UART2 Remap后不工作
RE:帮忙,32F101 UART2 Remap后不工作