1 | void uart_ESP8266_Init(void)
|
2 | {
|
3 | // use PB11 (RX) and PB10 (TX)
|
4 | // USART3
|
5 |
|
6 | // enable clock for USART3, GPIOB, AFIO
|
7 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
|
8 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
|
9 | GPIO_InitTypeDef gpioInitStruct;
|
10 |
|
11 | // init TX Pin
|
12 | gpioInitStruct.GPIO_Pin = GPIO_Pin_10;
|
13 | gpioInitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
|
14 | gpioInitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
15 | GPIO_Init(GPIOB, &gpioInitStruct);
|
16 | // init RX Pin
|
17 | gpioInitStruct.GPIO_Pin = GPIO_Pin_11;
|
18 | gpioInitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
19 | GPIO_Init(GPIOB, &gpioInitStruct);
|
20 |
|
21 | // init RST Pin
|
22 | gpioInitStruct.GPIO_Pin = GPIO_Pin_8;
|
23 | gpioInitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
24 | GPIO_Init(GPIOB, &gpioInitStruct);
|
25 |
|
26 | // init Ch_PD Pin
|
27 | gpioInitStruct.GPIO_Pin = GPIO_Pin_9;
|
28 | gpioInitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
29 | GPIO_Init(GPIOB, &gpioInitStruct);
|
30 |
|
31 | // SET Reset and Ch_PD Pin
|
32 | GPIO_SetBits(GPIOB,GPIO_Pin_9);
|
33 | GPIO_SetBits(GPIOB,GPIO_Pin_8);
|
34 |
|
35 | // setup USART3:
|
36 | USART_InitTypeDef usartInitStruct;
|
37 | USART_StructInit(&usartInitStruct);
|
38 |
|
39 | usartInitStruct.USART_BaudRate = 115200;
|
40 | usartInitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
41 | USART_Init(USART3, &usartInitStruct);
|
42 | USART_Cmd(USART3, ENABLE);
|
43 |
|
44 | /* Enable the USART3 Interrupt */
|
45 | NVIC_InitTypeDef NVIC_InitStructure;
|
46 | NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
|
47 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
48 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
49 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
50 | NVIC_Init(&NVIC_InitStructure);
|
51 |
|
52 | }
|