From aa2cbe27094cf0ef29dde1b4f7b0a00a28e652a2 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Mon, 25 Mar 2024 10:52:11 +0800 Subject: [PATCH] fixed normal open 1.6uA, closed, 90uA --- Core/Src/gpio.c | 21 ++++++++++++++++++--- Core/Src/stm32_lpm_if.c | 3 +++ LoRaWAN/App/lora_app.c | 4 ++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index 7cda6a6..4dd4cfe 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -49,6 +49,21 @@ void MX_GPIO_Init(void) __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); + GPIO_InitStruct.Pin = GPIO_PIN_All; + GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; + GPIO_InitStruct.Pull = GPIO_NOPULL; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_GPIOC_CLK_ENABLE(); + + GPIO_InitStruct.Pin = BUT1_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLUP; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + +#if 0 /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, LED1_Pin|LED2_Pin|PROB2_Pin|PROB1_Pin |LED3_Pin, GPIO_PIN_RESET); @@ -78,17 +93,17 @@ void MX_GPIO_Init(void) GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(BUT3_GPIO_Port, &GPIO_InitStruct); - +#endif /* EXTI interrupt init*/ HAL_NVIC_SetPriority(EXTI0_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI0_IRQn); - +#if 0 HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI1_IRQn); HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); - +#endif } /* USER CODE BEGIN 2 */ diff --git a/Core/Src/stm32_lpm_if.c b/Core/Src/stm32_lpm_if.c index 8b623ee..f358f2d 100644 --- a/Core/Src/stm32_lpm_if.c +++ b/Core/Src/stm32_lpm_if.c @@ -94,6 +94,9 @@ void PWR_EnterStopMode(void) /* USER CODE BEGIN EnterStopMode_1 */ /* USER CODE END EnterStopMode_1 */ + //HAL_GPIO_WritePin(GPIOB, GPIO_PIN_All, GPIO_PIN_RESET); + //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_All, GPIO_PIN_RESET); + //HAL_GPIO_WritePin(GPIOA, GPIO_PIN_All, GPIO_PIN_RESET); HAL_SuspendTick(); /* Clear Status Flag before entering STOP/STANDBY Mode */ LL_PWR_ClearFlag_C1STOP_C1STB(); diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 553e8d2..91208f1 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -610,8 +610,8 @@ static void SendTxData(void) { AppData.Buffer[i++] = 0; AppData.Buffer[i++] = 0; - AppData.Buffer[i++] = 0; - AppData.Buffer[i++] = 0; + AppData.Buffer[i++] = (uint8_t)(99*GetBatteryLevel()/255); /* 1 (very low) to 254 (fully charged) */ + AppData.Buffer[i++] = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0); } else {