From f152f0dd5cb4aaf867b8976e357291001bb2eebe Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期一, 21 十月 2024 16:06:24 +0800
Subject: [PATCH] 开发完成,版本V1.0

---
 Src/main.c |  494 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 358 insertions(+), 136 deletions(-)

diff --git a/Src/main.c b/Src/main.c
index 92e97d9..bea8c3a 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -17,7 +17,6 @@
   ******************************************************************************
   */
 /* USER CODE END Header */
-
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 
@@ -35,10 +34,14 @@
 #include "string.h"
 #include "stdio.h"
 #include "delay.h"
+#include "lora.h"
+#include "dps310.h"
+#include "dw_mbx_anc.h"
 #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 +61,7 @@
 /* USER CODE END PM */
 
 /* Private variables ---------------------------------------------------------*/
-ADC_HandleTypeDef hadc;
+ ADC_HandleTypeDef hadc;
 
 IWDG_HandleTypeDef hiwdg;
 
@@ -77,11 +80,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 */
 
@@ -89,6 +92,9 @@
 
 /* Private user code ---------------------------------------------------------*/
 /* USER CODE BEGIN 0 */
+#define DIANLIANG_TIME 3600
+uint8_t Anchor_Vcc_Flag;
+uint16_t Anchor_Vcc_time=DIANLIANG_TIME-2;
 uint32_t dev_id;
 uint16_t heartbeat_timer,poll_timer,sync_timer;
 uint8_t aRxBuffer[1],group_id;
@@ -96,10 +102,14 @@
 extern u8 motor_state;
 uint16_t tyncpoll_time,lpsettime;
 uint16_t slottime,max_slotpos;
-uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time;
+uint16_t lastpoll_count,interval_count,slot_startcount,tag_frequency,lastpoll_time,current_time;
 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);
@@ -161,10 +171,10 @@
 		}
 		if(bat_percent>99)
 		{
-			LED_LR_OFF;
+//			LED_LR_OFF;
 			LED_LG_ON;
 		}else{
-			LED_LR_ON;
+//			LED_LR_ON;
 			LED_LG_OFF;		
 		}		
 	}else{
@@ -173,7 +183,7 @@
             state5v=0;
             UsartDeInit();
         }
-		LED_LR_OFF;
+//		LED_LR_OFF;
 		LED_LG_OFF;
 //	}
 }
@@ -184,13 +194,25 @@
 
 	}
 
-
+void delay_us(uint32_t nTimer)  
+{  
+    uint32_t i=0;  
+    for(i=0;i<nTimer;i++){  
+        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();  
+        __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
+		__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();  
+        __NOP();__NOP();__NOP();__NOP(); 
+    }  
+}
 u16 total_slotnum,current_slotnum;
 extern int32_t offsettimeus;
 u16 last_lpcount = 0;
 void SetNextPollTime(u16 time)
 {
-  int32_t lpcount,lptime,target_time;
+  int32_t lpcount;
 
 //	if(current_slotnum>=total_slotnum)
 //		current_slotnum-=total_slotnum;
@@ -215,29 +237,34 @@
 	__HAL_LPTIM_COMPARE_SET(&hlptim1, lpcount);
 
 }
+
 u8 active_flag,nomovesleeptime;
 void Program_Init(void)
-{	float temp;
-	uint16_t temp2;
-	uint16_t i;
+{	
 	Usart1ParseDataCallback = UsartParseDataHandler;
 	parameter_init();
     hardware_version = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP);
 	hardware_pici = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+2);
 	hardware_type = STMFLASH_ReadHalfWord(FLASH_HARDWARE_VERSION_MAP+4);
 	//deca_sleep(1000);
-	g_com_map[VERSION] = (1<<8)|68;
-    
+	g_com_map[VERSION] = (1<<8)|0;
+ //   testprogram();
+//    g_com_map[DEV_ID]=0x6777;
     #ifdef DEBUG_MODE
    // g_com_map[GROUP_ID]=21;
-//    		g_com_map[DEV_ID]=4;
+//    		g_com_map[DEV_ID]=0x6777;
     //	g_com_map[COM_INTERVAL]=100;
     //	g_com_map[MAX_REPORT_ANC_NUM]=1;
     //	g_com_map[NOMOVESLEEP_TIME]=10;
     #endif
-    g_com_map[GROUP_ID]=3;
+    g_com_map[ACTIVE_INDEX] = 1;
+    g_com_map[GROUP_ID]=88;
+    g_com_map[UWBPOLLTIME_MS_IDX] = 520;
     g_com_map[COM_INTERVAL] = 1000;
+    if(g_com_map[COM_INTERVAL]<1000)
+    {g_com_map[COM_INTERVAL] = 1000;}
     active_flag = g_com_map[ACTIVE_INDEX];
+//    g_com_map[POWER]=0;
     module_power = g_com_map[POWER];
     g_com_map[IMU_ENABLE] = 0;
 	imu_enable=g_com_map[IMU_ENABLE];
@@ -255,53 +282,34 @@
     nomovesleeptime = g_com_map[NOMOVESLEEP_TIME];
 	if(active_flag==0)
 	{   
-		imu_enable=1;
-		nomovesleeptime =10;		
+        
 	}
 
  //   g_com_map[COM_INTERVAL]=100;
 		if(g_com_map[COM_INTERVAL]==0)
 	{
-	  g_com_map[COM_INTERVAL]=100;
+	  g_com_map[COM_INTERVAL]=1000;
 	}
 	 if(module_power>67)
 		{module_power=67;}
-		if(module_power<0)
-		{module_power=0;}
 
 	current_slotnum=1;
-//	current_time=GetLPTime();
+	current_time=GetLPTime();
 		if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK)  //system time is 1010ms   1 puls=30.518us
   {
     Error_Handler();
   }
 //g_com_map[NOMOVESLEEP_TIME]=5;
-    printf("固件版本: 免布线基站 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
+    printf("固件版本: LORA免布线基站-工装测试 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
 	memcpy(g_com_map2,g_com_map,COM_MAP_SIZE);
 //	printf("DEVICE PAIRID: %d .\r\n",g_com_map[PAIR_ID]);
 //	printf("DEVICE ALARM DISTANCE: 1.%d 2.%d 3.%d .\r\n",g_com_map[ALARM_DISTANCE1],g_com_map[ALARM_DISTANCE2],g_com_map[ALARM_DISTANCE3]);
 
 }
-
-static void SystemPower_Config(void)
-{
-  /* Enable Ultra low power mode */
-  HAL_PWREx_EnableUltraLowPower();
-  
-  /* Enable the fast wake up from Ultra low power mode */
-  HAL_PWREx_EnableFastWakeUp();
-}
 void mcu_sleep(void);
 uint32_t temp;
 extern uint8_t sleep_flag,m_bEUARTTxEn;
 uint16_t waitusart_timer;
-//void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
-//{
-//  /* Set transmission flag: trasfer complete*/
-//  waitusart_timer = tag_frequency*USART_KEEPWAKE_TIME;
-//	
-
-//}
 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
 {
 		//SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader   
@@ -312,7 +320,7 @@
 {
     static uint8_t first = 1;
     static float last_value = 100;   
-    static uint16_t bat_count = 0;
+    
     //if(bat_count++%600==0)
     {
 	temp2=dwt_readtempvbat(1);
@@ -344,34 +352,159 @@
     HAL_ADC_DeInit(&hadc);
     HAL_ADCEx_DisableVREFINT();
 }
-uint16_t irq_num;
+extern uint8_t TX_Buffer;
+uint8_t tx_num;
 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
 {
-    if(GPIO_Pin == GPIO_PIN_11)
+    if(GPIO_Pin == GPIO_PIN_3)
     {
-//        l_bIsVibration = HIDO_TRUE;
-//        nomove_time=0;
-//        printf("RXD :77777\r\n");
-        irq_num++;
         RadioIrqProcess();
     }
-//    if(GPIO_Pin == GPIO_PIN_8)
-//    {
-//     Anchor_App();
-//    }
 }
-void Uwb_Lora_Switch(uint8_t uwb, uint8_t lora)
+extern uint16_t AD_value[500];
+    u16 poll_startcount;
+u8 flag_entersleep = 1;
+uint32_t status_reg111 = 0;
+void Get_Dianliang_Poll()
 {
-if(uwb)
-HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET);
-else
-HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_RESET);    
-
-if(lora)
-HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_SET);
-else
-HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_RESET); 
+   if(Anchor_Vcc_Flag)
+   {
+       Anchor_Vcc_Flag=0;
+       bat_percent=Get_VDDVlotage();
+    UWB_Wkup(); 
+Delay_Ms(50);       
+    dwt_setrxtimeout(0);////设定接收超时时间,0位没有超时时间
+    dwt_rxenable(0);//打开接收
+       while(1)
+       {
+       while (!((status_reg111 = dwt_read32bitreg(SYS_STATUS_ID)) & (SYS_STATUS_RXFCG | SYS_STATUS_ALL_RX_ERR)))//不断查询芯片状态直到成功接收或者发生错误
+       {
+       bat_percent=Get_VDDVlotage();}
+       if (status_reg111 & SYS_STATUS_RXFCG)//如果成功接收
+       {
+        dwt_write32bitreg(SYS_STATUS_ID, SYS_STATUS_RXFCG | SYS_STATUS_TXFRS);//清楚寄存器标志位
+        dwt_setrxtimeout(0);////设定接收超时时间,0位没有超时时间
+        dwt_rxenable(0);//打开接收
+       }
+       else
+        {
+        dwt_write32bitreg(SYS_STATUS_ID,SYS_STATUS_RXFCG| SYS_STATUS_ALL_RX_ERR);
+        dwt_rxenable(0);	
+                                   
+        }
+         
+       }
+    
+    Delay_Ms(50);
+    dwt_forcetrxoff();
+    dwt_entersleep();
+   }
 }
+extern dwt_config_t config ;
+uint8_t shuzu[3]={0xff,0xff,0xff};
+uint8_t datashuju[50];
+uint8_t datachangdu;
+/*mode:区域	UART_PushFrame(send_frame, data_length+9);	*/
+void uartsend(uint8_t quyu,uint16_t data)
+{
+    if(quyu==4)
+    {
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t4.txt=\"%d\"",data);
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    }      
+    if(quyu==5)
+    {
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t5.txt=\"YES\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    }
+    if(quyu==6)
+    {
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t6.txt=\"%d\"",data);
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    }
+    if(quyu==7)
+    {
+//    memset(datashuju,0,sizeof(datashuju));    
+//    USART_puts(shuzu, 3);//开始结束都要发
+//    datachangdu=sprintf(datashuju,"t7.txt=\"%f\"",data);
+//    USART_puts(datashuju, datachangdu);       
+//    USART_puts(shuzu, 3);   
+    }    
+    if(quyu==8)
+    {
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t8.txt=\"%d\"",data);
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    }
+}
+void Lcd_Rest()
+{
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t0.bco=63488");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t1.bco=63488");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t2.bco=63488");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t3.bco=63488");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t4.txt=\"0\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t5.txt=\"0\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t6.txt=\"0\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t7.txt=\"0\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);   
+    
+//    memset(datashuju,0,sizeof(datashuju));    
+//    USART_puts(shuzu, 3);//开始结束都要发
+//    datachangdu=sprintf(datashuju,"t8.txt=\"power\"");
+//    USART_puts(datashuju, datachangdu);       
+//    USART_puts(shuzu, 3);   
+}
+uint8_t ceshimode;
 /* USER CODE END 0 */
 
 /**
@@ -402,40 +535,76 @@
 
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
-  MX_LPTIM1_Init();
-  MX_USART1_UART_Init();
-  MX_SPI1_Init();
   MX_ADC_Init();
   MX_DMA_Init();
-//  MX_IWDG_Init();
+  MX_LPTIM1_Init();
+  MX_SPI1_Init();
+  MX_USART1_UART_Init();
+  MX_IWDG_Init();
   /* USER CODE BEGIN 2 */
     LED_LG_ON;
     Program_Init();
+    if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
+    {
+    Error_Handler();
+    }
+    Lcd_Rest();
     //	LIS3DH_Data_Init();	
-//    Uwb_Lora_Switch(1,0);
+    //    Uwb_Lora_Switch(1,0);
+//    if(g_com_map[NEARBASE_ID10]==0)
+//    {
+        memset(datashuju,0,sizeof(datashuju));    
+        USART_puts(shuzu, 3);//开始结束都要发
+        datachangdu=sprintf(datashuju,"t8.txt=\"功率\"");
+        USART_puts(datashuju, datachangdu);       
+        USART_puts(shuzu, 3);   
+        
+        Reset_DW1000();//重启DW1000 /* Target specific drive of RSTn line into DW1000 low for a period. */
+        Spi_ChangePrescaler(SPIx_PRESCALER_SLOW);	//设置为快速模式
+        dwt_initialise(DWT_LOADUCODE);//初始化DW1000
+        dwt_configure(&config);//配置DW1000
+        dwt_setrxantennadelay(32899);		//设置接收天线延迟
+        dwt_settxantennadelay(0);		//设置发射天线延迟  
+        Dw1000_App_Init();
+        Delay_Ms(10);
+        dwt_configcontinuousframemode(124800);
+        dwt_writetxfctrl(13, 0);
+        //	dwt_starttx(DWT_START_TX_IMMEDIATE);
+        while(1)
+        {		
+            IdleTask();	
+//            ceshimode=1;
+            if(ceshimode)
+            {
+             break;
+            }
+        }
+//    }
+//    else
+//    {
+    memset(datashuju,0,sizeof(datashuju));    
+    USART_puts(shuzu, 3);//开始结束都要发
+    datachangdu=sprintf(datashuju,"t8.txt=\"测试\"");
+    USART_puts(datashuju, datachangdu);       
+    USART_puts(shuzu, 3);       
+        
     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();
-     if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE))
-    {
-     Error_Handler();
-    }
-    HAL_Delay(2000);
-//    Uwb_Lora_Switch(0,1);
+    dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN);
+    dwt_entersleep();
+    DW_DISABLE;
+    HAL_Delay(1500);
     Lora_Init();
+    MbxInit();
+  //  SwitchLoraSettingstest(UWB_CHANNEL_FRQ,UWB_CHANNEL_SF);
     Delay_Ms(10);
-//    Uwb_Lora_Switch(0,0);
-    printf("RXD :66666\r\n");
-    usart_send[0]=0x55;
-    usart_send[1]=0xaa;
-//	mcu_sleep();
-	//LED0_BLINK;		
-//	SystemPower_Config();
-//HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);   
+#ifdef _USE_BAR_
+    BarInit();
+#endif
+//     HAL_ADC_Start_DMA(&hadc,(uint32_t*)&AD_value,sizeof(AD_value));
   /* USER CODE END 2 */
 
   /* Infinite loop */
@@ -445,17 +614,52 @@
     /* USER CODE END WHILE */
 
     /* USER CODE BEGIN 3 */
-Lora_rx_open();
-//    HAL_IWDG_Refresh(&hiwdg);
-//    IdleTask();	
-//	Radio.IrqProcess( ); // Process Radio IRQ
-//     Anchor_App();
-    #ifndef DEBUG_MODE	
-    if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
-    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
-    #endif
-    
+    //  Send_Anchor_Vcc_Poll();
+    if(g_start_send_flag/*&&g_com_map[ACTIVE_INDEX]*/)
+	{
+		SystemClock_Config();
+		g_start_send_flag = 0;	
+		HAL_IWDG_Refresh(&hiwdg);
+		if(bat_percent>15)
+		{	
+          LED_TB_ON;
+			Tag_App();
+			LED_TB_OFF;
+		}else{
+			LED_TR_ON;
+			Tag_App();
+			LED_TR_OFF;		
+		}
+//        test1();
+        
+		//LED0_BLINK;		
+		IdleTask();	
+		if(waitusart_timer>0)
+		{
+			waitusart_timer--;
+		}		 
+	}else{  
+	IdleTask();	
+	}
+    if(m_bEUARTTxEn==0&&waitusart_timer==0)
+    {
+     if(memcmp(g_com_map2,g_com_map,200)!=0)
+     {
+        SCB->AIRCR = 0X05FA0000|(unsigned int)0x04;
+     }
+//         if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin))				
+//                    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
+//    #ifndef DEBUG_MODE	
+    if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)&&flag_entersleep)				
+                    HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);  
+//    #endif
+    }
+// HAL_Delay(100);
+    //  Get_Battary();
+
+	//	LIS3DH_Data_Init();	
   }
+//  }
   /* USER CODE END 3 */
 }
 
@@ -472,11 +676,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;
@@ -492,7 +699,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;
@@ -520,7 +728,7 @@
   * @param None
   * @retval None
   */
-void MX_ADC_Init(void)
+static void MX_ADC_Init(void)
 {
 
   /* USER CODE BEGIN ADC_Init 0 */
@@ -532,6 +740,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;
@@ -555,6 +764,7 @@
   {
     Error_Handler();
   }
+
   /** Configure for the selected ADC regular channel to be converted.
   */
   sConfig.Channel = ADC_CHANNEL_VREFINT;
@@ -757,21 +967,21 @@
   HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|PWR_CTL_Pin, GPIO_PIN_SET);
 
   /*Configure GPIO pin Output Level */
-  HAL_GPIO_WritePin(GPIOB, LED1_G_Pin|LED1_R_Pin|LED2_R_Pin|RADIO_nRESET_Pin
-                          |RADIO_NSS_Pin, GPIO_PIN_RESET);
+  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|RADIO_nRESET_Pin
+                          |RADIO_NSS_Pin|GPIO_PIN_7, GPIO_PIN_RESET);
 
   /*Configure GPIO pin Output Level */
   HAL_GPIO_WritePin(GPIOA, DW_WKUP_Pin|DW_CTRL_Pin|LED2_G_Pin, GPIO_PIN_RESET);
 
-  /*Configure GPIO pins : PA0 RADIO_DIO1_Pin */
-  GPIO_InitStruct.Pin = GPIO_PIN_0|RADIO_DIO1_Pin;
+  /*Configure GPIO pin : PA0 */
+  GPIO_InitStruct.Pin = GPIO_PIN_0;
   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
   /*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);
@@ -783,33 +993,32 @@
   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);
+
+  /*Configure GPIO pin : RADIO_BUSY_Pin */
+  GPIO_InitStruct.Pin = RADIO_BUSY_Pin;
+  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+  GPIO_InitStruct.Pull = GPIO_NOPULL;
+  HAL_GPIO_Init(RADIO_BUSY_GPIO_Port, &GPIO_InitStruct);
 
   /*Configure GPIO pin : INPUT_5V_Pin */
   GPIO_InitStruct.Pin = INPUT_5V_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
   GPIO_InitStruct.Pull = GPIO_PULLDOWN;
   HAL_GPIO_Init(INPUT_5V_GPIO_Port, &GPIO_InitStruct);
-
-  /*Configure GPIO pins : LED1_G_Pin LED1_R_Pin LED2_R_Pin RADIO_nRESET_Pin
-                           RADIO_NSS_Pin PWR_CTL_Pin */
-  GPIO_InitStruct.Pin = LED1_G_Pin|LED1_R_Pin|LED2_R_Pin|RADIO_nRESET_Pin
-                          |RADIO_NSS_Pin|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 pins : DW_WKUP_Pin DW_CTRL_Pin LED2_G_Pin */
   GPIO_InitStruct.Pin = DW_WKUP_Pin|DW_CTRL_Pin|LED2_G_Pin;
@@ -818,24 +1027,18 @@
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
-  /*Configure GPIO pin : RADIO_BUSY_Pin */
-  GPIO_InitStruct.Pin = RADIO_BUSY_Pin;
-  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
+  /*Configure GPIO pin : RADIO_DIO1_Pin */
+  GPIO_InitStruct.Pin = RADIO_DIO1_Pin;
+  GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
   GPIO_InitStruct.Pull = GPIO_NOPULL;
-  HAL_GPIO_Init(RADIO_BUSY_GPIO_Port, &GPIO_InitStruct);
-
-  /*Configure GPIO pin : PWR_ON_Pin */
-  GPIO_InitStruct.Pin = PWR_ON_Pin;
-  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
-  GPIO_InitStruct.Pull = GPIO_PULLUP;
-  HAL_GPIO_Init(PWR_ON_GPIO_Port, &GPIO_InitStruct);
+  HAL_GPIO_Init(RADIO_DIO1_GPIO_Port, &GPIO_InitStruct);
 
   /* EXTI interrupt init*/
   HAL_NVIC_SetPriority(EXTI0_1_IRQn, 1, 0);
   HAL_NVIC_EnableIRQ(EXTI0_1_IRQn);
 
-  HAL_NVIC_SetPriority(EXTI4_15_IRQn, 1, 0);
-  HAL_NVIC_EnableIRQ(EXTI4_15_IRQn);
+  HAL_NVIC_SetPriority(EXTI2_3_IRQn, 1, 0);
+  HAL_NVIC_EnableIRQ(EXTI2_3_IRQn);
 
 }
 
@@ -867,11 +1070,32 @@
 extern uint8_t tx_near_msg[80],stationary_flag;
 float key_keeptime;
 extern float freqlost_count,range_lost_time;
-uint32_t lp_time;
+extern uint16_t verfint_cal;
+extern float bat_volt;
+extern u16 rec_nearbaseid,temp_index,adc_val1,adc_val_min;
 void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim)
 {
-    lp_time++;
-    
+	static uint8_t i=0;
+	i++;
+	Anchor_Vcc_time++;
+    if(Anchor_Vcc_time>2)
+    {
+//    Anchor_Vcc_Flag=1;
+//        Anchor_Vcc_time=0;
+        Anchor_Vcc_time=0;
+              READC_Init();
+        verfint_cal = *(__IO uint16_t *)(0X1FF80078);  
+        adc_val1 = Get_ADC_Value();        
+        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);
+        Anchor_Vcc_Flag=0;
+        MX_ADC_DeInit();
+        bat_volt = 3*(float)verfint_cal/adc_val1-0.28;
+        
+    }
+	current_slotnum++;
+    freqlost_count+=1/(float)tag_frequency;
+    range_lost_time +=1/(float)tag_frequency;
+    g_start_send_flag=1;
 }
 /* USER CODE END 4 */
 
@@ -903,5 +1127,3 @@
   /* USER CODE END 6 */
 }
 #endif /* USE_FULL_ASSERT */
-
-/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

--
Gitblit v1.9.3