Guest User

Untitled

a guest
Mar 23rd, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. // Configure UART5 for 115200 baud with no flow control
  2. void USART_Config()
  3. {
  4.     // Structures to hold initialization data
  5.     GPIO_InitTypeDef GPIO_InitStructure;
  6.     USART_InitTypeDef USART_InitStructure;
  7.  
  8.     // Enable GPIO and then peripheral clocks respectively
  9.     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD, ENABLE);
  10.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
  11.  
  12.     // Connect the pins to the alternate function mapping
  13.     GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5); // TX
  14.     GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5); // RX
  15.  
  16.     // Configure the GPIO pins as AF push-pull
  17.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  18.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  19.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  20.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  21.     GPIO_InitStructure.GPIO_Pin = GPIO_PinSource12;
  22.     GPIO_Init(GPIOC, &GPIO_InitStructure);
  23.  
  24.     GPIO_InitStructure.GPIO_Pin = GPIO_PinSource2;
  25.     GPIO_Init(GPIOD, &GPIO_InitStructure);
  26.    
  27.     // Configure the peripheral
  28.     USART_InitStructure.USART_BaudRate = 115200;
  29.     USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  30.     USART_InitStructure.USART_StopBits = USART_StopBits_1;
  31.     USART_InitStructure.USART_Parity = USART_Parity_No;
  32.     USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  33.     USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  34.     USART_Init(UART5, &USART_InitStructure);
  35.     USART_Cmd(UART5, ENABLE);
  36. }
Advertisement
Add Comment
Please, Sign In to add comment