| | |
| | | current_time=GetLPTime(); |
| | | 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; |
| | | motor_enable=0; |
| | | } |
| | | // if(active_flag==0) |
| | | // { |
| | | // interval=1000; |
| | | // imu_enable=1; |
| | | // nomovesleep_time = 10; |
| | | // motor_enable=0; |
| | | // } |
| | | tag_frequency = 1000/interval; |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, slot_startcount) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | { |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | MX_LPTIM1_Init(); |
| | | MX_DMA_Init(); |
| | | MX_USART1_UART_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | // MX_LPTIM1_Init(); |
| | | // MX_DMA_Init(); |
| | | // MX_USART1_UART_Init(); |
| | | // MX_SPI1_Init(); |
| | | // MX_ADC_Init(); |
| | | |
| | | MX_TIM2_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | LED_LG_ON; |
| | | Program_Init(); |
| | | Accelerometer_Init(); |
| | | // BarInit(); |
| | | Dw1000_Init(); |
| | | Dw1000_App_Init(); |
| | | HardWareTypeDiffConfig(); |
| | | // MX_TIM2_Init(); |
| | | // /* USER CODE BEGIN 2 */ |
| | | // LED_LG_ON; |
| | | // Program_Init(); |
| | | // Accelerometer_Init(); |
| | | // // BarInit(); |
| | | // Dw1000_Init(); |
| | | // Dw1000_App_Init(); |
| | | // HardWareTypeDiffConfig(); |
| | | // dwt_configuresleep(DWT_PRESRV_SLEEP | DWT_CONFIG, DWT_WAKE_CS | DWT_WAKE_WK| DWT_SLP_EN); |
| | | // dwt_entersleep(); |
| | | // waitusart_timer=tag_frequency*USART_KEEPWAKE_TIME;; |
| | | dwt_setinterrupt( DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1); |
| | | dwt_setrxtimeout(0);//设定接收超时时间,0位没有 |
| | | dwt_rxenable(0); |
| | | DW_DISABLE; |
| | | // dwt_setinterrupt( DWT_INT_RFCG | (DWT_INT_ARFE | DWT_INT_RFSL | DWT_INT_SFDT | DWT_INT_RPHE | DWT_INT_RFCE | DWT_INT_RFTO | DWT_INT_RXPTO), 1); |
| | | // dwt_setrxtimeout(0);//设定接收超时时间,0位没有 |
| | | // dwt_rxenable(0); |
| | | // DW_DISABLE; |
| | | Bmp390Init(); |
| | | while(1); |
| | | /*气压计*/ |
| | | IIC_Init(); |
| | | u8 BMP390_ID; |
| | | u8 Config; |
| | | BMP390_ID = BMP390_Init(); |
| | | Parameter_Reading(Pressure_Para,Temperature_Para); |
| | | // IIC_Init(); |
| | | // u8 BMP390_ID; |
| | | // u8 Config; |
| | | // BMP390_ID = BMP390_Init(); |
| | | // Parameter_Reading(Pressure_Para,Temperature_Para); |
| | | //Judge the relevant state of the sensor |
| | | Config = BMP390_Read_Byte(ERR_REG_Addr); |
| | | if(Config&0x01) |
| | | printf("Fatal Error"); |
| | | else |
| | | printf("No errors."); |
| | | if((Config>>1)&0x01) |
| | | printf("Failed."); |
| | | else |
| | | printf("Successful."); |
| | | // Config = BMP390_Read_Byte(ERR_REG_Addr); |
| | | // if(Config&0x01) |
| | | // printf("Fatal Error"); |
| | | // else |
| | | // printf("No errors."); |
| | | // if((Config>>1)&0x01) |
| | | // printf("Failed."); |
| | | // else |
| | | // printf("Successful."); |
| | | /*气压计*/ |
| | | |
| | | if(HAL_UART_Receive_DMA(&huart1,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE)) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | |
| | | |
| | | |
| | | // HAL_Delay(2000); |
| | |
| | | /* USER CODE BEGIN WHILE */ |
| | | while (1) |
| | | { |
| | | /* USER CODE END WHILE */ |
| | | |
| | | /* USER CODE BEGIN 3 */ |
| | | // while(1) |
| | | // { |
| | | // MODBUS_Poll(); |
| | | // } |
| | | if(m_bEUARTTxEn==0&&(motor_state==0||motor_state==3)) |
| | | { |
| | | #ifndef DEBUG_MODE |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | #endif |
| | | } |
| | | if(g_start_send_flag) |
| | | { static uint16_t blink_count=0; |
| | | g_start_send_flag = 0; |
| | | // GetPressAndTemp(); |
| | | // if(current_count>slot_startcount&¤t_count<slot_startcount+interval_count) |
| | | // { |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_SET); |
| | | // }else{ |
| | | // HAL_GPIO_WritePin(LED0_GPIO, GPIO_PIN_9, GPIO_PIN_RESET); |
| | | // } |
| | | // LED_TR_BLINK; |
| | | __disable_irq(); |
| | | if(bat_percent>15) |
| | | { LED_TB_ON; |
| | | Tag_App(); |
| | | LED_TB_OFF; |
| | | }else{ |
| | | LED_TR_ON; |
| | | Tag_App(); |
| | | LED_TR_OFF; |
| | | } |
| | | __enable_irq(); |
| | | //LED0_BLINK; |
| | | IdleTask(); |
| | | if(waitusart_timer>0) |
| | | { |
| | | waitusart_timer--; |
| | | } |
| | | |
| | | }else{ |
| | | IdleTask(); |
| | | } |
| | | |
| | | // HAL_Delay(100); |
| | | // Get_Battary(); |