Home > other >  The stm32f103c8t6 usart2
The stm32f103c8t6 usart2

Time:12-12

Dear bosses, I want to use USART2 to send data, so that to initialize
or what not?Void usart2_init (uint32_t bound)//USART2 initialization
{
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, & amp; 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, & amp; USART2InitStructure);

USART_ITConfig (USART2, USART_IT_TXE, ENABLE);
USART_Cmd (USART2, ENABLE);
}
  • Related