Jelajahi Sumber

每次循环重置E52的电源

xuxinyi 1 bulan lalu
induk
melakukan
af666ee22c
3 mengubah file dengan 14 tambahan dan 3 penghapusan
  1. 2 0
      Core/Inc/E52.h
  2. 8 2
      Core/Src/E52.c
  3. 4 1
      Core/Src/main.c

+ 2 - 0
Core/Inc/E52.h

@@ -201,6 +201,8 @@ void E52_CtlPowerOn_Fun();
 //关闭lora电源
 void E52_CtlPowerOff_Fun();
 
+GPIO_PinState E52_GET_PowerLevel_Fun(void);
+
 void schedule_Fun(void);
 
 void Enter_Sleep_ACK_Fun(void);

+ 8 - 2
Core/Src/E52.c

@@ -8,11 +8,17 @@ Device_structure deviceInfo;
 
 
 void E52_CtlPowerOn_Fun() {
-    HAL_GPIO_WritePin(POWER_ON_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_RESET);
+    HAL_GPIO_WritePin(CTL_LORA_POWER_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_RESET);
 }
 
 void E52_CtlPowerOff_Fun() {
-    HAL_GPIO_WritePin(POWER_ON_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_SET);
+    HAL_GPIO_WritePin(CTL_LORA_POWER_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_SET);
+}
+
+// 将函数返回类型从void改为GPIO_PinState
+GPIO_PinState E52_GET_PowerLevel_Fun(void) {
+    // 直接返回读取到的电平值
+    return HAL_GPIO_ReadPin(CTL_LORA_POWER_GPIO_Port, CTL_LORA_POWER_Pin);
 }
 
 //AT COMMAND

+ 4 - 1
Core/Src/main.c

@@ -348,7 +348,8 @@ int main(void)
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
-
+  HAL_Delay(5000);
+  E52_Heartbeat_Fun();
   printf("设备地址:0x%02X%02X\n", deviceInfo.loraDeviceAddress_H, deviceInfo.loraDeviceAddress_L);
 
 
@@ -362,6 +363,8 @@ int main(void)
     // 检查是否接收到"心跳"命令,且设备在线
     printf("设备状态:0x%02X\n", deviceInfo.commandFromCloud);
     printf("Device is ready: %d\r\n", deviceInfo.isOnline);
+    E52_CtlPowerOn_Fun();
+
     // schedule_Fun();
     // 心跳:不在线时,每 10 秒发一次
     if (!deviceInfo.isOnline) {