yincheng.zhong
2024-01-22 5634c27b87d185b213dc31c921f9b64e5303d368
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);
@@ -371,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;
@@ -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;
@@ -466,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();
@@ -474,19 +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(GPIOB, GPIO_PIN_12, GPIO_PIN_SET);
        UWB_Wkup();
        delay_us(700);
//        HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET);
//        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;
@@ -953,17 +942,17 @@
    freqlost_count+=1/(float)tag_frequency;
    range_lost_time +=1/(float)tag_frequency;
//    g_start_send_flag=1;
    if(0)//freqlost_count>FREQ_LOST_TIME)
    {
        tag_frequency = NOTAG_FREQ;
        if(lost_jumpcount++>=10) //无测距情况下,每5秒发一次;
        {
            lost_jumpcount = 0;
            g_start_send_flag=1;
        }
    }else{
//    if(freqlost_count>FREQ_LOST_TIME)
//    {
//        tag_frequency = NOTAG_FREQ;
//        if(lost_jumpcount++>=0) //无测距情况下,每5秒发一次;
//        {
//            lost_jumpcount = 0;
//            g_start_send_flag=1;
//        }
//    }else{
        g_start_send_flag=1;
    }
//    }
    if(range_lost_time<1||freqlost_count>FREQ_LOST_TIME)
    {
        SetNextPollTime(0);
@@ -1022,5 +1011,3 @@
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/