| | |
| | | |
| | | SPI_HandleTypeDef hspi1; |
| | | |
| | | TIM_HandleTypeDef htim2; |
| | | |
| | | /* USER CODE BEGIN PV */ |
| | | |
| | | /* USER CODE END PV */ |
| | |
| | | /* 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); |
| | | static void MX_ADC_Init(void); |
| | | static void MX_DMA_Init(void); |
| | | static void MX_IWDG_Init(void); |
| | | static void MX_TIM2_Init(void); |
| | | static void MX_LPUART1_UART_Init(void); |
| | | static void MX_LPTIM1_Init(void); |
| | | /* USER CODE BEGIN PFP */ |
| | | |
| | | /* USER CODE END PFP */ |
| | |
| | | } |
| | | uint16_t hardware_version,hardware_pici,hardware_type; |
| | | uint8_t state5v = 1; |
| | | extern uint8_t du_flag; |
| | | extern uint8_t xie_flag; |
| | | float motor_keeptime; |
| | | void IdleTask(void) |
| | | { |
| | | //if(huart1.Instance->ISR&USART_ISR_FE) |
| | | // { |
| | | // SCB->AIRCR = 0X05FA0000|(unsigned int)0x04; //软复位回到bootloader |
| | | // } |
| | | //// } |
| | | // if(du_flag==1) |
| | | // { |
| | | // du_flag=0; |
| | | // |
| | | // } |
| | | // if(xie_flag==1) |
| | | // { |
| | | // xie_flag=0; |
| | | // memcpy((uint8_t*)&g_com_map + pack_index, mUsartReceivePack, pack_datalen); |
| | | // } |
| | | if(HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | { |
| | | |
| | |
| | | } |
| | | if(bat_percent>99) |
| | | { |
| | | // LED_LR_OFF; |
| | | LED_LG_ON; |
| | | LED2_TR_OFF; |
| | | LED2_TB_ON; |
| | | }else{ |
| | | // LED_LR_ON; |
| | | LED_LG_OFF; |
| | | LED2_TR_ON; |
| | | LED2_TB_OFF; |
| | | } |
| | | }else{ |
| | | if(state5v==1) |
| | |
| | | state5v=0; |
| | | UsartDeInit(); |
| | | } |
| | | // LED_LR_OFF; |
| | | LED_LG_OFF; |
| | | LED2_TR_OFF; |
| | | LED2_TB_OFF; |
| | | // } |
| | | } |
| | | if(g_com_map[MAP_SIGN_INDEX]!=0x55AA||g_com_map[COM_INTERVAL]==0) |
| | |
| | | u8 active_flag,nomovesleeptime; |
| | | void GetLoratx_frequency(void) |
| | | { |
| | | //if(g_com_map[NEARBASE_ID1]==0x470) |
| | | //{Loratx_frequency=470000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x471) |
| | | //{Loratx_frequency=471000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x472) |
| | | //{Loratx_frequency=472000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x473) |
| | | //{Loratx_frequency=473000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x474) |
| | | //{Loratx_frequency=474000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x475) |
| | | //{Loratx_frequency=475000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x476) |
| | | //{Loratx_frequency=476000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x477) |
| | | //{Loratx_frequency=477000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x478) |
| | | //{Loratx_frequency=478000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x479) |
| | | //{Loratx_frequency=479000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x480) |
| | | //{Loratx_frequency=480000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x481) |
| | | //{Loratx_frequency=481000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x482) |
| | | //{Loratx_frequency=482000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x483) |
| | | //{Loratx_frequency=483000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x484) |
| | | //{Loratx_frequency=484000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x485) |
| | | //{Loratx_frequency=485000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x486) |
| | | //{Loratx_frequency=486000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x487) |
| | | //{Loratx_frequency=487000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x488) |
| | | //{Loratx_frequency=488000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x489) |
| | | //{Loratx_frequency=489000000;} |
| | | //if(g_com_map[NEARBASE_ID1]==0x490) |
| | | //{Loratx_frequency=490000000;} |
| | | Loratx_frequency=470000000; |
| | | srand(HAL_LPTIM_ReadCounter(&hlptim1)); |
| | | Loratx_frequency=((rand()%5)+470)*1000000; |
| | | //Loratx_frequency=474000000; |
| | | if(470000000<=Loratx_frequency&&Loratx_frequency<480000000) |
| | | g_com_map[NEARBASE_ID1]=1136+(Loratx_frequency/1000000-470); |
| | | if(480000000<=Loratx_frequency&&Loratx_frequency<490000000) |
| | | g_com_map[NEARBASE_ID1]=1152+(Loratx_frequency/1000000-480); |
| | | Loratx_frequency=470000000; |
| | | } |
| | | void Program_Init(void) |
| | | { float temp; |
| | |
| | | // g_com_map[MAX_REPORT_ANC_NUM]=1; |
| | | // g_com_map[NOMOVESLEEP_TIME]=10; |
| | | #endif |
| | | g_com_map[GROUP_ID]=33; |
| | | g_com_map[COM_INTERVAL] = 1000; |
| | | g_com_map[GROUP_ID]=5; |
| | | // 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]; |
| | | module_power = g_com_map[POWER]; |
| | | g_com_map[IMU_ENABLE] = 0; |
| | |
| | | // 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;} |
| | |
| | | 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 |
| | |
| | | if(GPIO_Pin == GPIO_PIN_0)//加速度 |
| | | { |
| | | stationary_flag =0; |
| | | stationary_num=0; |
| | | } |
| | | } |
| | | void Uwb_Lora_Switch(uint8_t uwb, uint8_t lora) |
| | | { |
| | | 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); |
| | | } |
| | | extern void Lora_tx_zubao( void ); |
| | | extern void Lora_tx_mode( void ); |
| | |
| | | extern uint16_t Lora_tx_ancdist[50]; |
| | | extern uint8_t Lora_tx_anc_electricity[50]; |
| | | u8 lora_seq_nb1; |
| | | static uint8_t send_frame1[EUART_RX_BUF_SIZE]; |
| | | uint8_t data_length1; |
| | | void LoraSendComMap(uint8_t data_length, uint8_t index) |
| | | { |
| | | uint16_t checksum = 0; |
| | | send_frame1[0] = 0x55; |
| | | send_frame1[1] = 0xAA; |
| | | send_frame1[2] = 0x39; |
| | | send_frame1[3] = data_length+5; |
| | | send_frame1[4] = 3; |
| | | send_frame1[5] = index; |
| | | send_frame1[6] = data_length; |
| | | memcpy(&send_frame1[7], &g_com_map[index], data_length); |
| | | for(int i = 0; i<(data_length+5); i++) |
| | | { |
| | | checksum += send_frame1[2+i]; |
| | | } |
| | | checksum = Checksum_u16(&send_frame1[2],5+data_length); |
| | | memcpy(&send_frame1[7+data_length],&checksum,2); |
| | | data_length1=data_length+9; |
| | | // UART_PushFrame(send_frame1, data_length+9); |
| | | } |
| | | uint8_t no_yingdaflag; |
| | | void Lora_Tx_Poll() |
| | | { |
| | | |
| | | if(lora_tx_flag) |
| | | { |
| | | // Lora47X_change(); |
| | | // Delay_Ms(50); |
| | | // SX126xReset(); |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_SET); |
| | | Lora47X_Init(); |
| | | lora_tx_flag=0; |
| | | LED_TB_ON; |
| | | { |
| | | lora_tx_flag=0; |
| | | if(du_flag==1) |
| | | { |
| | | Lora47X_Init(); |
| | | du_flag=0; |
| | | Radio.Send( send_frame1, data_length1); |
| | | no_yingdaflag=1; |
| | | } |
| | | else |
| | | { |
| | | Lora47X_Init(); |
| | | if(bat_percent>20) |
| | | {LED_TR_ON;} |
| | | else |
| | | {LED_TB_ON;} |
| | | |
| | | lora_seq_nb2++; |
| | | Lora_tx_zubao(); |
| | | // Lora_tx_mode(); |
| | | Radio.Send( usart_send, 13+Lora_tx_ancnum*4); |
| | | // if(usart_send[2]==0x99) |
| | | // {LED_TB_ON;} |
| | | Radio.Send( usart_send, 15+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) |
| | | { |
| | | // SX126xReset(); |
| | | // Lora47X_change(); |
| | | // Delay_Ms(50); |
| | | Lora47X_Init(); |
| | | 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(); |
| | | } |
| | | extern uint16_t Lora_rece_error; |
| | | extern uint16_t Beepchixutime; |
| | | void Beep_Off() |
| | | { |
| | | __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 0); |
| | | HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4); |
| | | HAL_TIM_Base_Stop_IT(&htim2); |
| | | } |
| | | void Beep_On() |
| | | { |
| | | HAL_TIM_Base_Start_IT(&htim2); |
| | | HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4); |
| | | __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, 60); |
| | | } |
| | | #define BleRxBufferSize 1 |
| | | uint8_t aRxBuffer[1],group_id,BleRxBuffer[BleRxBufferSize]; |
| | | uint8_t ble_rx_success_flag; |
| | | uint8_t fangzhijinrushuimian_flag; |
| | | uint8_t ble_rxzhongzhuandate[50]; |
| | | uint8_t ble_rxzhongzhuandate[1024]; |
| | | uint8_t ble_zhongzhuannum; |
| | | uint8_t ble_rxdate[50]={1,2,3,4,5,6,7,8,9}; |
| | | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
| | | { |
| | | // HAL_UART_Transmit(&hlpuart1,(uint8_t*)ble_rxdate11111,3,1000); |
| | | // uint8_t ble_rxzhongzhuandate[50]; |
| | | // uint8_t ble_zhongzhuannum; |
| | | // if(lp_time>3) |
| | | |
| | | { |
| | | ble_rxzhongzhuandate[ble_zhongzhuannum]=BleRxBuffer[0]; |
| | | ble_zhongzhuannum++; |
| | | if(ble_rxzhongzhuandate[ble_zhongzhuannum-1]==0x0A&&ble_rxzhongzhuandate[ble_zhongzhuannum-2]==0x0D) |
| | | { |
| | | // HAL_UART_Transmit(&hlpuart1,ble_rxdate,5,1000); |
| | | ble_zhongzhuannum=0; |
| | | memcpy(ble_rxdate,ble_rxzhongzhuandate,50); |
| | | memset(ble_rxzhongzhuandate,0,sizeof(ble_rxzhongzhuandate)); |
| | | fangzhijinrushuimian_flag=0; |
| | | ble_rx_success_flag=1; |
| | | } |
| | | // if(ble_rxzhongzhuandate[ble_zhongzhuannum-1]==0x0A&&ble_rxzhongzhuandate[ble_zhongzhuannum-2]==0x0D) |
| | | // { |
| | | //// HAL_UART_Transmit(&hlpuart1,ble_rxdate,5,1000); |
| | | // ble_zhongzhuannum=0; |
| | | // memcpy(ble_rxdate,ble_rxzhongzhuandate,50); |
| | | // memset(ble_rxzhongzhuandate,0,sizeof(ble_rxzhongzhuandate)); |
| | | // fangzhijinrushuimian_flag=0; |
| | | // ble_rx_success_flag=1; |
| | | // } |
| | | HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)BleRxBuffer, 1); |
| | | // if(huart->Instance == hlpuart.Instance) |
| | | // { //if(huart == &huart3) |
| | | // g_uart3_rx_status = SET; |
| | | // } |
| | | } |
| | | } |
| | | uint8_t ble_rxdate111[3]={0x11,0x22,0x33}; |
| | |
| | | if(ble_rx_success_flag) |
| | | { |
| | | ble_rx_success_flag=0; |
| | | if(ble_rxdate[0]==0x55&&ble_rxdate[1]==0xAA&&ble_rxdate[5]==0x0D&&ble_rxdate[6]==0x0A) |
| | | { |
| | | if(ble_rxdate[2]==0x01) |
| | | { |
| | | memcpy(&g_com_map[NEARBASE_ID1],&ble_rxdate[3],2); |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | // NVIC_SystemReset(); |
| | | } |
| | | if(ble_rxdate[3]==0x02) |
| | | { |
| | | memcpy(&g_com_map[NEARBASE_ID2],&ble_rxdate[4],2); |
| | | save_com_map_to_flash(); |
| | | delay_ms(100); |
| | | // NVIC_SystemReset(); |
| | | } |
| | | // if(ble_rxdate[0]==0x55&&ble_rxdate[1]==0xAA&&ble_rxdate[5]==0x0D&&ble_rxdate[6]==0x0A) |
| | | // { |
| | | // if(ble_rxdate[2]==0x01) |
| | | // { |
| | | // memcpy(&g_com_map[NEARBASE_ID1],&ble_rxdate[3],2); |
| | | // save_com_map_to_flash(); |
| | | // delay_ms(100); |
| | | //// NVIC_SystemReset(); |
| | | // } |
| | | // if(ble_rxdate[3]==0x02) |
| | | // { |
| | | // memcpy(&g_com_map[NEARBASE_ID2],&ble_rxdate[4],2); |
| | | // save_com_map_to_flash(); |
| | | // delay_ms(100); |
| | | //// NVIC_SystemReset(); |
| | | // } |
| | | |
| | | |
| | | } |
| | | HAL_UART_Transmit(&hlpuart1,ble_rxdate,10,1000); |
| | | memset(ble_rxdate,0,sizeof(ble_rxdate)); |
| | | // |
| | | // } |
| | | // HAL_UART_Transmit(&hlpuart1,ble_rxdate,10,1000); |
| | | // memset(ble_rxdate,0,sizeof(ble_rxdate)); |
| | | } |
| | | } |
| | | /* USER CODE END 0 */ |
| | |
| | | |
| | | /* Initialize all configured peripherals */ |
| | | MX_GPIO_Init(); |
| | | MX_LPTIM1_Init(); |
| | | MX_DMA_Init(); |
| | | MX_USART1_UART_Init(); |
| | | MX_SPI1_Init(); |
| | | MX_ADC_Init(); |
| | | |
| | | MX_IWDG_Init(); |
| | | MX_DMA_Init(); |
| | | // MX_IWDG_Init(); |
| | | MX_TIM2_Init(); |
| | | MX_LPUART1_UART_Init(); |
| | | MX_LPTIM1_Init(); |
| | | /* USER CODE BEGIN 2 */ |
| | | // LED_LG_ON; |
| | | Program_Init(); |
| | |
| | | Error_Handler(); |
| | | } |
| | | Delay_Ms(2); |
| | | // Uwb_Lora_Switch(0,1); |
| | | // Lora433rx_Init(); |
| | | // Lora47xrx_Init(); |
| | | // Lora_Init(); |
| | | // Lora47xrx_Init(); |
| | | // Radio.Sleep( ); |
| | | Delay_Ms(10); |
| | | // Uwb_Lora_Switch(0,0); |
| | | printf("RXD :66666\r\n"); |
| | | // printf("RXD :66666\r\n"); |
| | | usart_send[0]=0x55; |
| | | usart_send[1]=0xaa; |
| | | bat_percent=Get_VDDVlotage(); |
| | | GetLoratx_frequency(); |
| | | HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)BleRxBuffer, 1); |
| | | HAL_UART_Receive_IT(&hlpuart1, (uint8_t *)BleRxBuffer, 1); |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET); //开GPS电源 |
| | | // Lora47X_Init(); |
| | | // 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无效 |
| | | // HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, GPIO_PIN_SET); |
| | | // Lora47X_Init(); |
| | | // Radio.Sleep(); |
| | | // lora_tx_flag=1; |
| | | // Lora_Tx_Poll(); |
| | | /* USER CODE END 2 */ |
| | |
| | | //Lora_rx_open(); |
| | | // Lora_Tx_Poll(); |
| | | Lora_Tx_Poll(); |
| | | Ble_rx_Poll(); |
| | | HAL_IWDG_Refresh(&hiwdg); |
| | | // IdleTask(); |
| | | // Ble_rx_Poll(); |
| | | // HAL_IWDG_Refresh(&hiwdg); |
| | | IdleTask(); |
| | | // Lora_rece_error=0; |
| | | // Radio.IrqProcess( ); // Process Radio IRQ |
| | | // Anchor_App(); |
| | | |
| | | // #ifndef DEBUG_MODE |
| | | // if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | // { |
| | | if(fangzhijinrushuimian_flag==0) |
| | | #ifndef DEBUG_MODE |
| | | if(!HAL_GPIO_ReadPin(INPUT_5V_GPIO_Port,INPUT_5V_Pin)) |
| | | { |
| | | // if(fangzhijinrushuimian_flag==0) |
| | | { |
| | | Selection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT; |
| | | HAL_UARTEx_EnableClockStopMode(&hlpuart1); |
| | | HAL_UARTEx_EnableStopMode( &hlpuart1 ); |
| | | HAL_UARTEx_StopModeWakeUpSourceConfig( &hlpuart1, Selection ); |
| | | __HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF); |
| | | // Selection.WakeUpEvent = UART_WAKEUP_ON_STARTBIT; |
| | | // HAL_UARTEx_EnableClockStopMode(&hlpuart1); |
| | | // HAL_UARTEx_EnableStopMode( &hlpuart1 ); |
| | | // HAL_UARTEx_StopModeWakeUpSourceConfig( &hlpuart1, Selection ); |
| | | // __HAL_UART_ENABLE_IT(&hlpuart1, UART_IT_WUF); |
| | | HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI); |
| | | } |
| | | // } |
| | | // #endif |
| | | } |
| | | #endif |
| | | |
| | | } |
| | | /* USER CODE END 3 */ |
| | |
| | | /** Configure LSE Drive Capability |
| | | */ |
| | | HAL_PWR_EnableBkUpAccess(); |
| | | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_HIGH); |
| | | __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW); |
| | | /** Initializes the CPU, AHB and APB busses clocks |
| | | */ |
| | | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI |
| | |
| | | Error_Handler(); |
| | | } |
| | | /* USER CODE BEGIN LPTIM1_Init 2 */ |
| | | // if (HAL_LPTIM_TimeOut_Start_IT(&hlptim1, Period, Timeout) != HAL_OK) |
| | | // { |
| | | // Error_Handler(); |
| | | // } |
| | | |
| | | /* USER CODE END LPTIM1_Init 2 */ |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * @brief TIM2 Initialization Function |
| | | * @param None |
| | | * @retval None |
| | | */ |
| | | static void MX_TIM2_Init(void) |
| | | { |
| | | |
| | | /* USER CODE BEGIN TIM2_Init 0 */ |
| | | |
| | | /* USER CODE END TIM2_Init 0 */ |
| | | |
| | | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
| | | TIM_OC_InitTypeDef sConfigOC = {0}; |
| | | |
| | | /* USER CODE BEGIN TIM2_Init 1 */ |
| | | |
| | | /* USER CODE END TIM2_Init 1 */ |
| | | htim2.Instance = TIM2; |
| | | htim2.Init.Prescaler = 32-1; |
| | | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
| | | htim2.Init.Period = 250-1; |
| | | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
| | | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
| | | if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| | | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
| | | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | sConfigOC.OCMode = TIM_OCMODE_PWM1; |
| | | sConfigOC.Pulse = 0; |
| | | sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH; |
| | | sConfigOC.OCFastMode = TIM_OCFAST_DISABLE; |
| | | if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) |
| | | { |
| | | Error_Handler(); |
| | | } |
| | | /* USER CODE BEGIN TIM2_Init 2 */ |
| | | |
| | | /* USER CODE END TIM2_Init 2 */ |
| | | HAL_TIM_MspPostInit(&htim2); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * Enable DMA controller clock |
| | | */ |
| | | static void MX_DMA_Init(void) |
| | |
| | | __HAL_RCC_GPIOB_CLK_ENABLE(); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2|GPIO_PIN_8, GPIO_PIN_RESET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(SPI_CS_GPIO_Port, SPI_CS_Pin, GPIO_PIN_SET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | |
| | | HAL_GPIO_WritePin(GPIOB, LED1_G_Pin|LED1_R_Pin|GPIO_PIN_14|RADIO_nRESET_Pin |
| | | |RADIO_NSS_Pin|GPIO_PIN_7, GPIO_PIN_RESET); |
| | | |
| | | /*Configure GPIO pin Output Level */ |
| | | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8|DW_CTRL_Pin|LED2_G_Pin, GPIO_PIN_RESET); |
| | | |
| | | /*Configure GPIO pin : PA0 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_0; |
| | | /*Configure GPIO pins : PA0 PA15 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_15; |
| | | GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING; |
| | | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| | | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| | | |
| | | /*Configure GPIO pins : PA2 PA8 */ |
| | | GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_8; |
| | | 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 : SPI_CS_Pin */ |
| | |
| | | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| | | HAL_GPIO_Init(GPIOB, &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 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 : SDA_Pin SCL_Pin */ |
| | | GPIO_InitStruct.Pin = SDA_Pin|SCL_Pin; |
| | |
| | | extern uint8_t lora_chongfuyingda_flag; |
| | | uint16_t no_data_chongqi_num; |
| | | uint16_t anchor_send_num; |
| | | uint8_t no_yingdatime; |
| | | void HAL_LPTIM_CompareMatchCallback(LPTIM_HandleTypeDef *hlptim) |
| | | { |
| | | // uint8_t pinlv; |
| | | SystemClock_Config(); |
| | | lp_time++; |
| | | anchor_send_num++; |
| | | no_data_chongqi_num++; |
| | | stationary_num++; |
| | | if(Beepchixutime>0) |
| | | { |
| | | Beepchixutime--; |
| | | if(Beepchixutime==0) |
| | | {Beep_Off();} |
| | | } |
| | | if(no_yingdaflag==1) |
| | | { |
| | | no_yingdatime++; |
| | | if(no_yingdatime>=5) |
| | | { |
| | | no_yingdaflag=0; |
| | | no_yingdatime=0; |
| | | } |
| | | } |
| | | |
| | | if( no_data_chongqi_num>600) |
| | | {NVIC_SystemReset();} |
| | | SetNextPollTime(0); |
| | |
| | | // } |
| | | // else |
| | | // { |
| | | |
| | | |
| | | // pinlv=g_com_map[COM_MAP_SIZE]/1000; |
| | | if(lp_time%(g_com_map[COM_INTERVAL]/1000)==0) |
| | | { |
| | | lora_tx_flag=1; |
| | | lora_txanchor_power_flag=0; |
| | | // } |
| | | if(anchor_send_num>=600) |
| | | if(anchor_send_num>=3600) |
| | | {anchor_send_num=0; |
| | | lora_txanchor_power_flag=1; |
| | | lora_tx_flag=0; |
| | | bat_percent=Get_VDDVlotage(); |
| | | } |
| | | |
| | | } |
| | | |
| | | if(stationary_num>=10) |
| | | {stationary_num=0; |