From cebd82085108b30288a6357fae633e811dbea248 Mon Sep 17 00:00:00 2001 From: WXK <287788329@qq.com> Date: 星期三, 30 八月 2023 14:02:48 +0800 Subject: [PATCH] 加入看门狗,目前功耗正常。 --- Core/Src/main.c | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 45 insertions(+), 10 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index fb4782f..45af8fa 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -51,6 +51,8 @@ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc; +IWDG_HandleTypeDef hiwdg; + LPTIM_HandleTypeDef hlptim1; UART_HandleTypeDef hlpuart1; @@ -75,6 +77,7 @@ static void MX_SPI1_Init(void); static void MX_TIM21_Init(void); static void MX_LPTIM1_Init(void); +static void MX_IWDG_Init(void); /* USER CODE BEGIN PFP */ #define UWB_WORK_TIME_S 10 //#define JIASUDU_INSLEEP_TIME 3600 @@ -163,13 +166,13 @@ bigslot_num = TOTAL_SLOTNUM/tag_frequency; current_slotnum=1; // current_time=GetLPTime(); - nomovesleep_time = g_com_map[NOMOVESLEEP_TIME]; +// nomovesleep_time = g_com_map[NOMOVESLEEP_TIME]; interval = g_com_map[COM_INTERVAL]; if(active_flag==0) { interval=1000; imu_enable=1; - nomovesleep_time = 10; +// nomovesleep_time = 10; motor_enable=0; } tag_frequency = 1000/interval; @@ -324,6 +327,7 @@ MX_SPI1_Init(); MX_TIM21_Init(); MX_LPTIM1_Init(); + MX_IWDG_Init(); /* USER CODE BEGIN 2 */ Program_Init(); Dw1000_Init(); @@ -335,11 +339,11 @@ Set4LEDColor_Off(); //关一下led总电源 Power_GPS_LoraOff();//关一下GPS总电源 // Lora_Sleep(); -// Set4LEDColor(RED,RED,RED,RED); -// HAL_Delay(500); -// Set4LEDColor(GREEN,GREEN,GREEN,GREEN); -// HAL_Delay(500); - + Set4LEDColor(RED,RED,RED,RED); + HAL_Delay(500); + Set4LEDColor(GREEN,GREEN,GREEN,GREEN); + HAL_Delay(500); + MX_IWDG_Init(); // NVIC_SystemReset(); /* USER CODE END 2 */ @@ -347,7 +351,7 @@ /* USER CODE BEGIN WHILE */ while (1) { - + HAL_IWDG_Refresh(&hiwdg); APL_Poll();//lora接收,gps接收时间判断,单片机休眠函数,蜂鸣器判断函数。 Uwb_Poll(); Battery_Poll();//检测电量函数,每60s测一次电量。 @@ -379,10 +383,12 @@ /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE; + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI + |RCC_OSCILLATORTYPE_LSE; RCC_OscInitStruct.LSEState = RCC_LSE_ON; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4; @@ -468,6 +474,35 @@ /* USER CODE BEGIN ADC_Init 2 */ /* USER CODE END ADC_Init 2 */ + +} + +/** + * @brief IWDG Initialization Function + * @param None + * @retval None + */ +static void MX_IWDG_Init(void) +{ + + /* USER CODE BEGIN IWDG_Init 0 */ + + /* USER CODE END IWDG_Init 0 */ + + /* USER CODE BEGIN IWDG_Init 1 */ + + /* USER CODE END IWDG_Init 1 */ + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_256; + hiwdg.Init.Window = 4095; + hiwdg.Init.Reload = 4095; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN IWDG_Init 2 */ +HAL_IWDG_Refresh(&hiwdg); + /* USER CODE END IWDG_Init 2 */ } @@ -778,7 +813,7 @@ GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); - + /**/ HAL_I2CEx_EnableFastModePlus(I2C_FASTMODEPLUS_PB6); -- Gitblit v1.9.3