stm32f103c8t6的usart2
G空白世界 2020-12-11 04:17:33 各位大佬们,我想用USART2去发送数据,这样去初始化为什么不行呢
void usart2_init(uint32_t bound)//USART2初始化
{
GPIO_InitTypeDef GPIOInitStructure;
USART_InitTypeDef USART2InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
//USART2_TX PA7
GPIOInitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIOInitStructure.GPIO_Pin = GPIO_Pin_7;
GPIOInitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIOInitStructure);
USART2InitStructure.USART_BaudRate = bound;
USART2InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART2InitStructure.USART_Mode = USART_Mode_Tx;
USART2InitStructure.USART_Parity = USART_Parity_No;
USART2InitStructure.USART_StopBits = USART_StopBits_1;
USART2InitStructure.USART_WordLength = USART_WordLength_8b;
USART_Init(USART2, &USART2InitStructure);
USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
USART_Cmd(USART2, ENABLE);
}