Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Configure UART5 for 115200 baud with no flow control
- void USART_Config()
- {
- // Structures to hold initialization data
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- // Enable GPIO and then peripheral clocks respectively
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
- // Connect the pins to the alternate function mapping
- GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); // TX
- GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); // RX
- // Configure the GPIO pins as AF push-pull
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Pin = GPIO_PinSource12;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_PinSource2;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- // Configure the peripheral
- 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;
- USART_Init(UART5, &USART_InitStructure);
- USART_Cmd(UART5, ENABLE);
- }
Advertisement
Add Comment
Please, Sign In to add comment