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 |  107 +++++++++++++++++++++++------------------------------
 1 files changed, 47 insertions(+), 60 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 6590662..42937f3 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -17,7 +17,6 @@
   ******************************************************************************
   */
 /* USER CODE END Header */
-
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 
@@ -38,7 +37,7 @@
 #define NSH1 0x0001
 #define GP   0x0002
 #define FLASH_HARDWARE_VERSION_MAP		(uint32_t)0x08004F00    //硬件版本号和批次信息位置
-//#define DEBUG_MODE
+#define DEBUG_MODE
 /* USER CODE END Includes */
 
 /* Private typedef -----------------------------------------------------------*/
@@ -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);
@@ -216,6 +219,7 @@
 	__HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
 
 }
+
 u8 active_flag,nomovesleeptime;
 void Program_Init(void)
 {	float temp;
@@ -228,6 +232,7 @@
 	hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
 	//deca_sleep(1000);
 	g_com_map[VERSION] = (1<<8)|0;
+    testprogram();
 //    g_com_map[DEV_ID]=0x6777;
     #ifdef DEBUG_MODE
    // g_com_map[GROUP_ID]=21;
@@ -369,7 +374,7 @@
         RadioIrqProcess();
     }
 }
-u16 poll_startcount;
+    u16 poll_startcount;
 u16 Anchor_Vcc_time1;
 uint8_t TX_Anchor_Vcc[100]={0x55,0xAA,0x14,20,0,0/*标签id*/,0,0/*基站ID*/,0/*保留*/,};
 extern float bat_volt;
@@ -427,21 +432,21 @@
 
   /* 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;
     Program_Init();
     //	LIS3DH_Data_Init();	
-//    Uwb_Lora_Switch(1,0);
+    //    Uwb_Lora_Switch(1,0);
     Dw1000_Init();
     Dw1000_App_Init();
     Delay_Ms(10);
-//    Uwb_Lora_Switch(0,0);
+    // Uwb_Lora_Switch(0,0);
     //	HardWareTypeDiffConfig();
     dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
     dwt_entersleep();
@@ -450,7 +455,7 @@
     {
      Error_Handler();
     }
-    HAL_Delay(2000);
+    HAL_Delay(1500);
 
     Lora_Init();
 
@@ -464,7 +469,7 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-      Send_Anchor_Vcc_Poll();
+    //  Send_Anchor_Vcc_Poll();
 		if(g_start_send_flag)
 	{ static uint16_t blink_count=0;
 		SystemClock_Config();
@@ -472,21 +477,14 @@
 		HAL_IWDG_Refresh(&hiwdg);
 
 
-        memcpy(&TX_Buffer+3,&tx_num,1);
-//        printf("Lora发送%d",tx_num);
-        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
-        poll_startcount=HAL_LPTIM_ReadCounter(&hlptim1);
-        poll_startcount=poll_startcount+557;//557代表17ms
-        if(poll_startcount>=32768)
-		{
-		poll_startcount -=32768;
-		}
-	    Radio.Send( &TX_Buffer, 4);
+       
+//        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
 
-        tx_num++;
-        delay_ms(3);
-
-
+	   
+//        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
+//         Radio.Send( &TX_Buffer, 4);
+//        UWB_Wkup();
+//        delay_us(700);
 		if(bat_percent>15)
 		{	
           LED_TB_ON;
@@ -541,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;
@@ -561,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;
@@ -589,7 +591,7 @@
   * @param None
   * @retval None
   */
-void MX_ADC_Init(void)
+static void MX_ADC_Init(void)
 {
 
   /* USER CODE BEGIN ADC_Init 0 */
@@ -601,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;
@@ -624,6 +627,7 @@
   {
     Error_Handler();
   }
+
   /** Configure for the selected ADC regular channel to be converted.
   */
   sConfig.Channel = ADC_CHANNEL_VREFINT;
@@ -831,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;
@@ -848,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);
@@ -860,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);
 
@@ -878,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;
@@ -1022,5 +1011,3 @@
   /* USER CODE END 6 */
 }
 #endif /* USE_FULL_ASSERT */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

--
Gitblit v1.9.3