Sfoglia il codice sorgente

添加电源灯显示。

xuxinyi 2 mesi fa
parent
commit
1b09009736
4 ha cambiato i file con 40 aggiunte e 61 eliminazioni
  1. 2 0
      Core/Inc/main.h
  2. 18 6
      Core/Src/main.c
  3. 9 50
      Core/Src/stm32f1xx_it.c
  4. 11 5
      lora_bl.ioc

+ 2 - 0
Core/Inc/main.h

@@ -66,6 +66,8 @@ void Error_Handler(void);
 #define POWER_ON_GPIO_Port GPIOA
 #define CTL_LORA_POWER_Pin GPIO_PIN_15
 #define CTL_LORA_POWER_GPIO_Port GPIOA
+#define PowerLED_Pin GPIO_PIN_3
+#define PowerLED_GPIO_Port GPIOB
 
 /* USER CODE BEGIN Private defines */
 extern uint8_t rx_buf[100];

+ 18 - 6
Core/Src/main.c

@@ -19,7 +19,6 @@
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 
-//上船测试版本
 /* Private includes ----------------------------------------------------------*/
 /* USER CODE BEGIN Includes */
 #include <time.h>
@@ -171,6 +170,7 @@ HAL_StatusTypeDef Timer_Managment_Fun(TIM_HandleTypeDef *htim, Timer_Operation o
 void powerOn() {
 
   HAL_GPIO_WritePin(POWER_ON_GPIO_Port, POWER_ON_Pin, GPIO_PIN_SET);
+  HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_SET);//亮灯
 }
 //设备关闭供电
 void powerOff() {
@@ -220,10 +220,6 @@ int main(void)
 
   /* Initialize all configured peripherals */
   MX_GPIO_Init();
-
-  // 将GPIO引脚拉高
-  // HAL_GPIO_WritePin(POWER_ON_GPIO_Port, POWER_ON_Pin, GPIO_PIN_SET);
-  // HAL_GPIO_WritePin(POWER_ON_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_RESET);
   MX_DMA_Init();
   MX_USART1_UART_Init();
   MX_USART2_UART_Init();
@@ -294,7 +290,13 @@ int main(void)
   printf("Device is ready\r\n");
   printf("设备地址:0x%02X%02X\n", deviceInfo.loraDeviceAddress_H, deviceInfo.loraDeviceAddress_L);
   uint8_t i = 0;
-
+  // HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_RESET);//亮灯
+  // HAL_Delay(2000);
+  // HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_SET);//亮灯
+  // HAL_Delay(2000);
+  // HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_RESET);//亮灯
+  // HAL_Delay(2000);
+  // HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_SET);//亮灯
   while (1)
   {
     /* USER CODE END WHILE */
@@ -779,6 +781,9 @@ static void MX_GPIO_Init(void)
   /*Configure GPIO pin Output Level */
   HAL_GPIO_WritePin(CTL_LORA_POWER_GPIO_Port, CTL_LORA_POWER_Pin, GPIO_PIN_RESET);
 
+  /*Configure GPIO pin Output Level */
+  HAL_GPIO_WritePin(PowerLED_GPIO_Port, PowerLED_Pin, GPIO_PIN_RESET);
+
   /*Configure GPIO pin : SOS_KEY_Pin */
   GPIO_InitStruct.Pin = SOS_KEY_Pin;
   GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
@@ -805,6 +810,13 @@ static void MX_GPIO_Init(void)
   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
   HAL_GPIO_Init(CTL_LORA_POWER_GPIO_Port, &GPIO_InitStruct);
 
+  /*Configure GPIO pin : PowerLED_Pin */
+  GPIO_InitStruct.Pin = PowerLED_Pin;
+  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+  GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+  HAL_GPIO_Init(PowerLED_GPIO_Port, &GPIO_InitStruct);
+
   /* EXTI interrupt init*/
   HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
   HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);

+ 9 - 50
Core/Src/stm32f1xx_it.c

@@ -20,17 +20,15 @@
 /* Includes ------------------------------------------------------------------*/
 #include "main.h"
 #include "stm32f1xx_it.h"
+/* Private includes ----------------------------------------------------------*/
+/* USER CODE BEGIN Includes */
 
+#include <locale.h>
 #include <stdio.h>
 
 #include "string.h"
 #include "E104-BT5005A.h"
 #include "E52.h"
-/* Private includes ----------------------------------------------------------*/
-/* USER CODE BEGIN Includes */
-
-#include <locale.h>
-
 #include "RTC_SLEEP.h"
 
 /* USER CODE END Includes */
@@ -267,6 +265,7 @@ void TIM4_IRQHandler(void)
 
   /* USER CODE END TIM4_IRQn 0 */
   HAL_TIM_IRQHandler(&htim4);
+  /* USER CODE BEGIN TIM4_IRQn 1 */
   // printf("定时器测试\r\n");
   deviceInfo.timeCount++;
   if (GET_CMD(deviceInfo.commandFromCloud) == REQUEST_BLUETOOTH_DATA) {
@@ -274,8 +273,6 @@ void TIM4_IRQHandler(void)
       deviceInfo.commandFromCloud = COMBINE_CMD_STEP(REQUEST_BLUETOOTH_DATA, REQUEST_BLUETOOTH_DATA_SEND);
     }
   }
-  /* USER CODE BEGIN TIM4_IRQn 1 */
-
   /* USER CODE END TIM4_IRQn 1 */
 }
 
@@ -288,6 +285,7 @@ void USART2_IRQHandler(void)
 
   /* USER CODE END USART2_IRQn 0 */
   HAL_UART_IRQHandler(&huart2);
+  /* USER CODE BEGIN USART2_IRQn 1 */
 
   // 检测空闲中断
   if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE))
@@ -329,8 +327,6 @@ void USART2_IRQHandler(void)
     HAL_UART_Receive_DMA(&huart2, rx_buf_uart2, sizeof(rx_buf_uart2));
   }
 
-  /* USER CODE BEGIN USART2_IRQn 1 */
-
   /* USER CODE END USART2_IRQn 1 */
 }
 
@@ -373,52 +369,16 @@ void USART3_IRQHandler(void)
 /**
   * @brief This function handles EXTI line[15:10] interrupts.
   */
-void EXTI15_10_IRQHandler(void) {
+void EXTI15_10_IRQHandler(void)
+{
   /* USER CODE BEGIN EXTI15_10_IRQn 0 */
 
   /* USER CODE END EXTI15_10_IRQn 0 */
   HAL_GPIO_EXTI_IRQHandler(SOS_KEY_Pin);
-  // printf("I AM SOS KEY\r\n");
-  // RTC_DateTimeTypeDef currentDT;
-  // // 读取当前时间日期
-  // RTC_GetDateTime(&hrtc, &currentDT);
-  //
-  // if (SOS_key_struct.sosCheckActive == 0) {
-  //   // 第一次触发,记录时间
-  //   firstPressTime = currentDT;
-  //   SOS_key_struct.SOS_key_Count = 1;
-  //   SOS_key_struct.sosCheckActive = TRUE;
-  // } else {
-  //   // 后续触发,只计数
-  //   SOS_key_struct.SOS_key_Count++;
-  // }
-  //
-  // printf("当前时间: %02X:%02X:%02X\n",
-  //    currentDT.hours, currentDT.minutes, currentDT.seconds);
-  // // printf("当前日期: 20%02X年%02X月%02X日 星期%d\n",
-  // //        currentDT.year, currentDT.month, currentDT.date, currentDT.weekday);
-  //
-  // printf("第一次按下时间: %02X:%02X:%02X\n",
-  //      firstPressTime.hours, firstPressTime.minutes, firstPressTime.seconds);
-  // printf("第一次按下日期: 20%02X年%02X月%02X日 星期%d\n",
-  //        firstPressTime.year, firstPressTime.month, firstPressTime.date, firstPressTime.weekday);
-
-  // 触发第一次中断 ,记录第一次按压时间
-  // 通知主函数,开始计时
-  // 主函数中循检测,当前时间与第一次时间间隔是否超过5秒
-  // 如果超过五秒停止检测,并判断按压次数,如果超过5次,则认为是SOS,并停止检测
-}
-
-  // 打印当前时间日期
-  // printf("当前时间: %02X:%02X:%02X\n",
-  //        currentDT.hours, currentDT.minutes, currentDT.seconds);
-  // printf("当前日期: 20%02X年%02X月%02X日 星期%d\n",
-  //        currentDT.year, currentDT.month, currentDT.date, currentDT.weekday);
-
   /* USER CODE BEGIN EXTI15_10_IRQn 1 */
 
   /* USER CODE END EXTI15_10_IRQn 1 */
-
+}
 
 /**
   * @brief This function handles RTC alarm interrupt through EXTI line 17.
@@ -429,9 +389,8 @@ void RTC_Alarm_IRQHandler(void)
 
   /* USER CODE END RTC_Alarm_IRQn 0 */
   HAL_RTC_AlarmIRQHandler(&hrtc);
-  printf("hello world\r\n");
   /* USER CODE BEGIN RTC_Alarm_IRQn 1 */
-
+  printf("hello world\r\n");
   /* USER CODE END RTC_Alarm_IRQn 1 */
 }
 

+ 11 - 5
lora_bl.ioc

@@ -48,11 +48,12 @@ Mcu.Pin12=PA10
 Mcu.Pin13=PA13
 Mcu.Pin14=PA14
 Mcu.Pin15=PA15
-Mcu.Pin16=VP_RTC_VS_RTC_Activate
-Mcu.Pin17=VP_RTC_VS_RTC_Calendar
-Mcu.Pin18=VP_SYS_VS_tim3
-Mcu.Pin19=VP_TIM4_VS_ClockSourceINT
+Mcu.Pin16=PB3
+Mcu.Pin17=VP_RTC_VS_RTC_Activate
+Mcu.Pin18=VP_RTC_VS_RTC_Calendar
+Mcu.Pin19=VP_SYS_VS_tim3
 Mcu.Pin2=PD0-OSC_IN
+Mcu.Pin20=VP_TIM4_VS_ClockSourceINT
 Mcu.Pin3=PD1-OSC_OUT
 Mcu.Pin4=PA2
 Mcu.Pin5=PA3
@@ -60,7 +61,7 @@ Mcu.Pin6=PB10
 Mcu.Pin7=PB11
 Mcu.Pin8=PB14
 Mcu.Pin9=PB15
-Mcu.PinsNb=20
+Mcu.PinsNb=21
 Mcu.ThirdPartyNb=0
 Mcu.UserConstants=
 Mcu.UserName=STM32F103C8Tx
@@ -125,6 +126,11 @@ PB15.GPIO_Label=JUGE_PIN
 PB15.GPIO_PuPd=GPIO_NOPULL
 PB15.Locked=true
 PB15.Signal=GPIO_Input
+PB3.GPIOParameters=GPIO_PuPd,GPIO_Label
+PB3.GPIO_Label=PowerLED
+PB3.GPIO_PuPd=GPIO_PULLDOWN
+PB3.Locked=true
+PB3.Signal=GPIO_Output
 PC14-OSC32_IN.Mode=LSE-External-Oscillator
 PC14-OSC32_IN.Signal=RCC_OSC32_IN
 PC15-OSC32_OUT.Mode=LSE-External-Oscillator