From 5634c27b87d185b213dc31c921f9b64e5303d368 Mon Sep 17 00:00:00 2001 From: yincheng.zhong <634916154@qq.com> Date: 星期一, 22 一月 2024 22:22:41 +0800 Subject: [PATCH] Merge branch '免布线基站-lora' of http://47.108.70.204:60062/r/XRange_Tag into 免布线基站-lora --- Src/main.c | 72 ++++++++++++++++-------------------- 1 files changed, 32 insertions(+), 40 deletions(-) diff --git a/Src/main.c b/Src/main.c index 0a660f6..42937f3 100644 --- a/Src/main.c +++ b/Src/main.c @@ -17,7 +17,6 @@ ****************************************************************************** */ /* USER CODE END Header */ - /* Includes ------------------------------------------------------------------*/ #include "main.h" @@ -58,7 +57,7 @@ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ -ADC_HandleTypeDef hadc; + ADC_HandleTypeDef hadc; IWDG_HandleTypeDef hiwdg; @@ -77,11 +76,11 @@ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); -static void MX_LPTIM1_Init(void); -static void MX_USART1_UART_Init(void); -static void MX_SPI1_Init(void); -void MX_ADC_Init(void); +static void MX_ADC_Init(void); static void MX_DMA_Init(void); +static void MX_LPTIM1_Init(void); +static void MX_SPI1_Init(void); +static void MX_USART1_UART_Init(void); static void MX_IWDG_Init(void); /* USER CODE BEGIN PFP */ @@ -101,6 +100,10 @@ extern uint8_t module_power; extern float nomove_count; uint8_t imu_enable,motor_enable; +void READC_Init(void) +{ +MX_ADC_Init(); +} u16 GetLPTime(void) { u16 count=HAL_LPTIM_ReadCounter(&hlptim1); @@ -429,11 +432,11 @@ /* Initialize all configured peripherals */ MX_GPIO_Init(); - MX_LPTIM1_Init(); - MX_DMA_Init(); - MX_USART1_UART_Init(); - MX_SPI1_Init(); MX_ADC_Init(); + MX_DMA_Init(); + MX_LPTIM1_Init(); + MX_SPI1_Init(); + MX_USART1_UART_Init(); MX_IWDG_Init(); /* USER CODE BEGIN 2 */ LED_LG_ON; @@ -536,11 +539,14 @@ /** Configure the main internal regulator output voltage */ __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + /** Configure LSE Drive Capability */ HAL_PWR_EnableBkUpAccess(); - __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH); - /** Initializes the CPU, AHB and APB busses clocks + __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); + + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI |RCC_OSCILLATORTYPE_LSE; @@ -556,7 +562,8 @@ { Error_Handler(); } - /** Initializes the CPU, AHB and APB busses clocks + + /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; @@ -584,7 +591,7 @@ * @param None * @retval None */ -void MX_ADC_Init(void) +static void MX_ADC_Init(void) { /* USER CODE BEGIN ADC_Init 0 */ @@ -596,6 +603,7 @@ /* USER CODE BEGIN ADC_Init 1 */ /* USER CODE END ADC_Init 1 */ + /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; @@ -619,6 +627,7 @@ { Error_Handler(); } + /** Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_VREFINT; @@ -826,15 +835,7 @@ /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOA, DW_WKUP_Pin|DW_CTRL_Pin|LED2_G_Pin, GPIO_PIN_RESET); - ////////////////////////////////// - HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); - ////////////////////////////////// - GPIO_InitStruct.Pin = GPIO_PIN_15; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - + /*Configure GPIO pin : PA0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; @@ -843,7 +844,7 @@ /*Configure GPIO pins : SCL_Pin SDA_Pin */ GPIO_InitStruct.Pin = SCL_Pin|SDA_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); @@ -855,16 +856,18 @@ GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(SPI_CS_GPIO_Port, &GPIO_InitStruct); - /*Configure GPIO pin : BAT_MEAS_GND_Pin */ - GPIO_InitStruct.Pin = BAT_MEAS_GND_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; + /*Configure GPIO pins : BAT_MEAS_GND_Pin PB10 LED1_G_Pin LED1_R_Pin + RADIO_nRESET_Pin RADIO_NSS_Pin PB7 PWR_CTL_Pin */ + GPIO_InitStruct.Pin = BAT_MEAS_GND_Pin|GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin + |RADIO_nRESET_Pin|RADIO_NSS_Pin|GPIO_PIN_7|PWR_CTL_Pin; + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(BAT_MEAS_GND_GPIO_Port, &GPIO_InitStruct); + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pin : USER_KEY_Pin */ GPIO_InitStruct.Pin = USER_KEY_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; + GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(USER_KEY_GPIO_Port, &GPIO_InitStruct); @@ -873,15 +876,6 @@ GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(RADIO_BUSY_GPIO_Port, &GPIO_InitStruct); - - /*Configure GPIO pins : PB10 LED1_G_Pin LED1_R_Pin RADIO_nRESET_Pin - RADIO_NSS_Pin PB7 PWR_CTL_Pin */ - GPIO_InitStruct.Pin = GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|RADIO_nRESET_Pin - |RADIO_NSS_Pin|GPIO_PIN_7|PWR_CTL_Pin; - GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; - HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pin : INPUT_5V_Pin */ GPIO_InitStruct.Pin = INPUT_5V_Pin; @@ -1017,5 +1011,3 @@ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ - -/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ -- Gitblit v1.9.3