用的是STM32F101VBT6,USART3重定义到PD8、PD9,但经示波器测量PD8、PD9电平时钟为低!下面是代码
串口配置:
void USART3_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
/* USART3 configuration ------------------------------------------------------*/
USART_InitStructure.USART_BaudRate = 19200;
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 USART3 */
USART_Init(USART3, &USART_InitStructure);
/* Enable USART3 Receive interrupts */
USART_ClearITPendingBit(USART3,USART3_IRQn);
USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
/* Enable the USART3 */
USART_Cmd(USART3, ENABLE);
}
引脚配置:
void USART3_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/**************************GPIOD/ USART3******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; //USART3 TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART3 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //复用开漏输入
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);
} |