From 5047decf97ca5439a4176febabe4da0c39d8fb6c Mon Sep 17 00:00:00 2001 From: Oxore Date: Sun, 5 Mar 2023 00:21:35 +0300 Subject: ESP32 kinda works but not really still --- Project/src/main.c | 91 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 73 insertions(+), 18 deletions(-) (limited to 'Project/src/main.c') diff --git a/Project/src/main.c b/Project/src/main.c index 0d485bc..aa8c111 100644 --- a/Project/src/main.c +++ b/Project/src/main.c @@ -97,14 +97,14 @@ static void USART1Init(void) GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIOA, &GPIO_InitStructure); - USART_InitTypeDef usart1_init = {0}; - usart1_init.USART_BaudRate = 115200; - usart1_init.USART_WordLength = USART_WordLength_8b; - usart1_init.USART_StopBits = USART_StopBits_1; - usart1_init.USART_Parity = USART_Parity_No; - usart1_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - usart1_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_Init(USART1, &usart1_init); + USART_InitTypeDef usart_init = {0}; + usart_init.USART_BaudRate = 115200; + usart_init.USART_WordLength = USART_WordLength_8b; + usart_init.USART_StopBits = USART_StopBits_1; + usart_init.USART_Parity = USART_Parity_No; + usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_Init(USART1, &usart_init); USART_Cmd(USART1, ENABLE); } @@ -123,24 +123,75 @@ static void USART4Init(void) GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_Init(GPIOA, &GPIO_InitStructure); - USART_InitTypeDef usart4_init = {0}; - usart4_init.USART_BaudRate = 9600; - usart4_init.USART_WordLength = USART_WordLength_8b; - usart4_init.USART_StopBits = USART_StopBits_1; - usart4_init.USART_Parity = USART_Parity_No; - usart4_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; - usart4_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; - USART_Init(USART4, &usart4_init); + USART_InitTypeDef usart_init = {0}; + usart_init.USART_BaudRate = 9600; + usart_init.USART_WordLength = USART_WordLength_8b; + usart_init.USART_StopBits = USART_StopBits_1; + usart_init.USART_Parity = USART_Parity_No; + usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None; + USART_Init(USART4, &usart_init); USART_Cmd(USART4, ENABLE); } +static void WIFI_IO_GPIOInit(void) +{ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_Init(GPIOA, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_SetBits(GPIOB, GPIO_Pin_0); // WIFI_EN + GPIO_ResetBits(GPIOA, GPIO_Pin_15); // WIFI_IO0 +} + +static void USART3Init(void) +{ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); + GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_4); + GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_4); + GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_4); + GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_4); + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; + GPIO_Init(GPIOB, &GPIO_InitStructure); + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; + GPIO_Init(GPIOB, &GPIO_InitStructure); + USART_InitTypeDef usart_init = {0}; + usart_init.USART_BaudRate = 115200; + usart_init.USART_WordLength = USART_WordLength_8b; + usart_init.USART_StopBits = USART_StopBits_1; + usart_init.USART_Parity = USART_Parity_No; + usart_init.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; + usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_RTS_CTS; + USART_Init(USART3, &usart_init); + USART_Cmd(USART3, ENABLE); +} + // ---------------------------------------------------------------------------- // Инициализация до создания задач // ---------------------------------------------------------------------------- void InitAll ( void ) { SystemInit(); + WIFI_IO_GPIOInit(); USART1Init(); + USART3Init(); USART4Init(); InitLTimers(); LightSensorInit(); @@ -161,10 +212,14 @@ static void TestUart(void *arg) { (void) arg; while (1) { - if (USART4->ISR & USART_ISR_RXNE) { - const uint16_t data = USART_ReceiveData(USART4); + if (USART3->ISR & USART_ISR_RXNE) { + const uint16_t data = USART_ReceiveData(USART3); USART_SendData(USART1, data); } + if (USART1->ISR & USART_ISR_RXNE) { + const uint16_t data = USART_ReceiveData(USART1); + USART_SendData(USART3, data); + } } } -- cgit v1.2.3