1 | /******** USART initialisieren ********/
|
2 | void USART_Configuration(void)
|
3 | {
|
4 | USART_InitTypeDef USART_InitStructure;
|
5 | GPIO_InitTypeDef GPIO_InitStructure;
|
6 |
|
7 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); // Enable GPIOA on APB2 peripheral clock
|
8 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); // Enable AFIO Clock
|
9 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); // Enable USART2 Clock
|
10 |
|
11 | GPIO_StructInit(&GPIO_InitStructure); // Set GPIO to default values
|
12 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // Set TX(PA2)
|
13 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // Set as output Push-Pull
|
14 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // Set freq. of PortPin
|
15 | GPIO_Init(GPIOA, &GPIO_InitStructure); // Initialize
|
16 |
|
17 | /*
|
18 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; // Set RX(PA3)
|
19 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ; // Set as floating input
|
20 | GPIO_Init(GPIOA, &GPIO_InitStructure); // Initialize
|
21 | */
|
22 |
|
23 | USART_StructInit(&USART_InitStructure); // Initializes structure with default values
|
24 | USART_DeInit(USART2); // Put everything back to power-on defaults
|
25 |
|
26 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); // Enable USART2 on APB1 peripheral clock
|
27 |
|
28 | // ------------------------------ USART2 Configuration ------------------------------
|
29 | USART_InitStructure.USART_BaudRate = 115200; // The Baudrate
|
30 | USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // Software or Hardware FlowControl
|
31 | //USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; // Enable RX and TX
|
32 | USART_InitStructure.USART_Mode = USART_Mode_Tx; // Enable RX and TX
|
33 | USART_InitStructure.USART_Parity = USART_Parity_No; // No Parity Bit
|
34 | USART_InitStructure.USART_StopBits = USART_StopBits_1; // One Stopbit
|
35 | USART_InitStructure.USART_WordLength = USART_WordLength_8b; // 8-Bit Word length of Data
|
36 | USART_Init(USART2, &USART_InitStructure); // Now do the setup
|
37 |
|
38 | USART_Cmd(USART2, ENABLE); // Enable USART2
|
39 | }
|