| | |
| | | #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 -----------------------------------------------------------*/ |
| | |
| | | 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_IWDG_Init(void); |
| | | /* USER CODE BEGIN PFP */ |
| | |
| | | extern uint8_t module_power; |
| | | extern float nomove_count; |
| | | uint8_t imu_enable,motor_enable; |
| | | uint32_t lp_time; |
| | | extern uint32_t lora_txtime_old; |
| | | uint8_t anjian_flag; |
| | | uint8_t stationary_flag; |
| | | uint16_t stationary_num; |
| | | u16 GetLPTime(void) |
| | | { |
| | | u16 count=HAL_LPTIM_ReadCounter(&hlptim1); |
| | |
| | | } |
| | | if(bat_percent>99) |
| | | { |
| | | LED_LR_OFF; |
| | | // LED_LR_OFF; |
| | | LED_LG_ON; |
| | | }else{ |
| | | LED_LR_ON; |
| | | // LED_LR_ON; |
| | | LED_LG_OFF; |
| | | } |
| | | }else{ |
| | |
| | | state5v=0; |
| | | UsartDeInit(); |
| | | } |
| | | LED_LR_OFF; |
| | | // LED_LR_OFF; |
| | | LED_LG_OFF; |
| | | // } |
| | | } |
| | |
| | | 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[DEV_ID]=1158; |
| | | g_com_map[VERSION] = (1<<8)|0; |
| | | // g_com_map[DEV_ID]=1158; |
| | | #ifdef DEBUG_MODE |
| | | // g_com_map[GROUP_ID]=21; |
| | | // g_com_map[DEV_ID]=4; |
| | |
| | | |
| | | current_slotnum=1; |
| | | // 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 |
| | | if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, LPTIMER_1S_COUNT, 32767) != HAL_OK) //system time is 1010ms 1 puls=30.518us |
| | | { |
| | | Error_Handler(); |
| | | } |
| | |
| | | uint16_t irq_num; |
| | | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
| | | { |
| | | if(GPIO_Pin == GPIO_PIN_11) |
| | | if(GPIO_Pin == GPIO_PIN_3) |
| | | { |
| | | SystemClock_Config(); |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | // HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_RESET); //片选lora有效 |
| | | // l_bIsVibration = HIDO_TRUE; |
| | | // nomove_time=0; |
| | | // printf("RXD :77777\r\n"); |
| | | irq_num++; |
| | | RadioIrqProcess(); |
| | | } |
| | | // if(GPIO_Pin == GPIO_PIN_8) |
| | | // { |
| | | // Anchor_App(); |
| | | // } |
| | | if(GPIO_Pin == GPIO_PIN_1)//按键 |
| | | { |
| | | anjian_flag=1; |
| | | } |
| | | if(GPIO_Pin == GPIO_PIN_0)//加速度 |
| | | { |
| | | stationary_flag =0; |
| | | } |
| | | } |
| | | void Uwb_Lora_Switch(uint8_t uwb, uint8_t lora) |
| | | { |
| | |
| | | HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_SET); |
| | | else |
| | | HAL_GPIO_WritePin(GPIOB, RADIO_NSS_Pin, GPIO_PIN_RESET); |
| | | } |
| | | extern void Lora_tx_zubao( void ); |
| | | extern void Lora_tx_mode( void ); |
| | | extern uint8_t Lora_tx_ancnum; |
| | | extern u8 lora_seq_nb2; |
| | | extern uint16_t lora_yingda_num; |
| | | uint8_t lora_tx_flag; |
| | | uint8_t lora_txanchor_power_flag; |
| | | extern uint16_t Lora_tx_ancid[50]; |
| | | extern uint16_t Lora_tx_ancdist[50]; |
| | | extern uint8_t Lora_tx_anc_electricity[50]; |
| | | u8 lora_seq_nb1; |
| | | void Lora_Tx_Poll() |
| | | { |
| | | if(lora_tx_flag) |
| | | { |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | lora_tx_flag=0; |
| | | LED_TB_ON; |
| | | lora_seq_nb2++; |
| | | Lora_tx_zubao(); |
| | | Lora_tx_mode(); |
| | | Radio.Send( usart_send, 13+Lora_tx_ancnum*4); |
| | | Lora_tx_ancnum=0; |
| | | memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | | memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid)); |
| | | anjian_flag=0; |
| | | } |
| | | if(lora_txanchor_power_flag) |
| | | { |
| | | LED_TB_ON; |
| | | lora_seq_nb1++; |
| | | lora_txanchor_power_flag=0; |
| | | uint16_t checksum; |
| | | usart_send[2] = 0x23;//基站电量模式 |
| | | usart_send[3] = 6+Lora_tx_ancnum*3;//数据段长度 |
| | | memcpy(&usart_send[4],&dev_id,2); |
| | | usart_send[6] = lora_seq_nb1;//包序 |
| | | usart_send[7] = Lora_tx_ancnum; |
| | | memcpy(&usart_send[8],&Lora_tx_ancid,2*Lora_tx_ancnum); |
| | | memcpy(&usart_send[8+Lora_tx_ancnum*2],&Lora_tx_anc_electricity,Lora_tx_ancnum); |
| | | checksum = Checksum_u16(&usart_send[2],8+3*Lora_tx_ancnum); |
| | | memcpy(&usart_send[8+3*Lora_tx_ancnum],&checksum,2); |
| | | Lora_tx_mode(); |
| | | Radio.Send( usart_send, 10+Lora_tx_ancnum*3); |
| | | Lora_tx_ancnum=0; |
| | | |
| | | } |
| | | |
| | | |
| | | // Lora_Txcount=HAL_LPTIM_ReadCounter(&hlptim1); |
| | | // |
| | | // if(Lora_Txcount-Old_Lora_Txcount>=6554) |
| | | // { |
| | | // Old_Lora_Txcount=Lora_Txcount; |
| | | // LED_TB_ON; |
| | | // lora_seq_nb2++; |
| | | // Lora_tx_zubao(); |
| | | // Lora_tx_mode(); |
| | | // Radio.Send( usart_send, 12+Lora_tx_ancnum*4); |
| | | // Lora_tx_ancnum=0; |
| | | // memset(Lora_tx_ancdist,0,sizeof(Lora_tx_ancdist)); |
| | | // memset(Lora_tx_ancid,0,sizeof(Lora_tx_ancid)); |
| | | // } |
| | | } |
| | | void MX_ADC1_Init() |
| | | { |
| | | MX_ADC_Init(); |
| | | } |
| | | /* USER CODE END 0 */ |
| | | |
| | |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | MX_DMA_Init(); |
| | | // MX_IWDG_Init(); |
| | | MX_IWDG_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | // LED_LG_ON; |
| | | Program_Init(); |
| | | // LIS3DH_Data_Init(); |
| | | LIS3DH_Data_Init(); |
| | | // Uwb_Lora_Switch(1,0); |
| | | Dw1000_Init(); |
| | | Dw1000_App_Init(); |
| | |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | HAL_Delay(2000); |
| | | Delay_Ms(2); |
| | | // Uwb_Lora_Switch(0,1); |
| | | Lora_Init(); |
| | | // Radio.Sleep( ); |
| | |
| | | printf("RXD :66666\r\n"); |
| | | usart_send[0]=0x55; |
| | | usart_send[1]=0xaa; |
| | | bat_percent=Get_VDDVlotage(); |
| | | // mcu_sleep(); |
| | | //LED0_BLINK; |
| | | // SystemPower_Config(); |
| | | //HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | // HAL_GPIO_WritePin(RADIO_NSS_GPIO_Port, RADIO_NSS_Pin, GPIO_PIN_SET); //片选lora无效 |
| | | /* USER CODE END 2 */ |
| | | |
| | | /* Infinite loop */ |
| | |
| | | |
| | | /* USER CODE BEGIN 3 */ |
| | | Lora_rx_open(); |
| | | Lora_Tx_Poll(); |
| | | |
| | | |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | // IdleTask(); |
| | | 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); |
| | |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | void MX_ADC_Init(void) |
| | | static void MX_ADC_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN ADC_Init 0 */ |
| | |
| | | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOA, SCL_Pin|SDA_Pin|SPI_CS_Pin, GPIO_PIN_SET); |
| | | HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|PWR_CTL_Pin, GPIO_PIN_SET); |
| | | HAL_GPIO_WritePin(GPIOB, BAT_MEAS_GND_Pin|SDA_Pin|SCL_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); |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|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.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pin : SPI_CS_Pin */ |
| | |
| | | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| | | HAL_GPIO_Init(USER_KEY_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; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | 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; |
| | | 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; |
| | | /*Configure GPIO pins : PB10 LED1_G_Pin LED1_R_Pin RADIO_nRESET_Pin |
| | | RADIO_NSS_Pin PB7 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_10|LED1_G_Pin|LED1_R_Pin|RADIO_nRESET_Pin |
| | | |RADIO_NSS_Pin|GPIO_PIN_7; |
| | | 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; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| | | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| | | HAL_GPIO_Init(PWR_ON_GPIO_Port, &GPIO_InitStruct); |
| | | GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
| | | HAL_GPIO_Init(INPUT_5V_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : PA8 DW_CTRL_Pin LED2_G_Pin */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_8|DW_CTRL_Pin|LED2_G_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | /*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_DIO1_GPIO_Port, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : SDA_Pin SCL_Pin */ |
| | | GPIO_InitStruct.Pin = SDA_Pin|SCL_Pin; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
| | | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| | | |
| | | /* EXTI interrupt init*/ |
| | | HAL_NVIC_SetPriority(EXTI0_1_IRQn, 1, 0); |
| | | HAL_NVIC_SetPriority(EXTI0_1_IRQn, 2, 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); |
| | | |
| | | } |
| | | |
| | |
| | | /*Enter the Standby mode*/ |
| | | HAL_PWR_EnterSTANDBYMode(); |
| | | } |
| | | extern uint8_t tx_near_msg[80],stationary_flag; |
| | | extern uint8_t tx_near_msg[80]; |
| | | float key_keeptime; |
| | | extern float freqlost_count,range_lost_time; |
| | | uint32_t lp_time; |
| | | extern uint8_t lora_yingda_flag; |
| | | uint8_t lora_yingdatime; |
| | | extern uint8_t lora_chongfuyingda_flag; |
| | | uint8_t no_data_chongqi_num; |
| | | uint16_t anchor_send_num; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | SystemClock_Config(); |
| | | lp_time++; |
| | | anchor_send_num++; |
| | | no_data_chongqi_num++; |
| | | stationary_num++; |
| | | if( no_data_chongqi_num>60) |
| | | {NVIC_SystemReset();} |
| | | if(lora_yingda_flag) |
| | | { |
| | | lora_yingdatime++; |
| | |
| | | Radio.Send( usart_send, 2); |
| | | } |
| | | } |
| | | else |
| | | {lora_tx_flag=1; |
| | | lora_txanchor_power_flag=0; |
| | | } |
| | | if(anchor_send_num>=600) |
| | | {anchor_send_num=0; |
| | | lora_txanchor_power_flag=1; |
| | | lora_tx_flag=0; |
| | | bat_percent=Get_VDDVlotage(); |
| | | } |
| | | if(stationary_num>=10) |
| | | {stationary_num=0; |
| | | stationary_flag=1; |
| | | } |
| | | |
| | | } |
| | | /* USER CODE END 4 */ |
| | | |