diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 9194319..553e6b8 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -29,15 +29,12 @@
-
+
-
-
-
-
+
@@ -202,6 +199,8 @@
+
+
@@ -220,32 +219,32 @@
- {
- "keyToString": {
- "ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "CMake Application.IntelliChargingPile.elf.executor": "Run",
- "OpenOCD Download & Run.IntelliChargingPile.elf.executor": "Run",
- "OpenOCD Download & Run.OCD IntelliChargingPile.executor": "Run",
- "RunOnceActivity.RadMigrateCodeStyle": "true",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.cidr.known.project.marker": "true",
- "RunOnceActivity.git.unshallow": "true",
- "RunOnceActivity.readMode.enableVisualFormatting": "true",
- "RunOnceActivity.west.config.association.type.startup.service": "true",
- "SHARE_PROJECT_CONFIGURATION_FILES": "true",
- "cf.first.check.clang-format": "false",
- "cidr.known.project.marker": "true",
- "git-widget-placeholder": "main",
- "last_opened_file_path": "/Users/timothy/Workbench/embedded/project/IntelliChargingPile/Core/Src",
- "node.js.detected.package.eslint": "true",
- "node.js.detected.package.tslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "node.js.selected.package.tslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "CMakeSettings",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -306,7 +305,7 @@
-
+
@@ -380,7 +379,23 @@
1743531723695
-
+
+
+ 1746704030956
+
+
+
+ 1746704030956
+
+
+
+ 1746705282234
+
+
+
+ 1746705282234
+
+
@@ -400,26 +415,29 @@
-
+
+
+
file://$PROJECT_DIR$/Core/Src/OneNet.c
- 199
+ 195
+
-
+
diff --git a/Core/Inc/main.h b/Core/Inc/main.h
index 876ea5b..fb86e04 100644
--- a/Core/Inc/main.h
+++ b/Core/Inc/main.h
@@ -36,7 +36,10 @@ extern "C" {
/* Exported types ------------------------------------------------------------*/
/* USER CODE BEGIN ET */
-
+extern char flag_1s;
+extern char flag_2s;
+extern char flag_5s;
+extern char flag_10s;
/* USER CODE END ET */
/* Exported constants --------------------------------------------------------*/
diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c
index e110b5d..b613f3b 100644
--- a/Core/Src/freertos.c
+++ b/Core/Src/freertos.c
@@ -33,6 +33,7 @@
#include "stm32f1xx_hal.h"
#include
#include "retarget.h"
+#include "tim.h"
#include "timers.h"
/* USER CODE END Includes */
@@ -57,6 +58,9 @@
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */
char ONENET_CONNECTED = 0;
+
+// Flags
+char KEY_PRESSED[4] = {0, 0, 0, 0};
/* USER CODE END Variables */
/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
@@ -114,6 +118,8 @@ void MX_FREERTOS_Init(void) {
OLED_ShowString(0,0,"OneNet online ",12);
HAL_GPIO_WritePin(LED0_GPIO_Port, LED0_Pin, GPIO_PIN_RESET);
+
+ HAL_TIM_Base_Start_IT(&htim1);
/* USER CODE END Init */
/* USER CODE BEGIN RTOS_MUTEX */
@@ -165,16 +171,47 @@ void StartDefaultTask(void *argument)
/* Infinite loop */
for(;;)
{
- IM_ReadFlag = 1; //抄读标志
+
+ // osDelay(500);
+ //
+ // OneNet_SendData();
+ // osDelay(500);
+ // ESP8266_Clear();
+
+ if (KEY_PRESSED[0] || KEY_PRESSED[1])
+ {
+ KEY_PRESSED[0] = 0;
+ KEY_PRESSED[1] = 0;
+ HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
+ }
+
+
+ if (flag_1s)
+ {
+ flag_1s = 0;
+ IM_ReadFlag = 1;
+ }
+
+ if (flag_2s)
+ {
+ flag_2s = 0;
+ HAL_GPIO_TogglePin(LED0_GPIO_Port, LED0_Pin);
+ }
+
+ if (flag_5s)
+ {
+ flag_5s = 0;
+ OneNet_SendData();
+ ESP8266_Clear();
+ }
+
+ if (IM_RecvDone)
+ {
+ IM_Analyze();
+ Display_IM1281B();
+ }
+
IM_Read();
-
- osDelay(500);
-
- OneNet_SendData();
- osDelay(500);
- ESP8266_Clear();
-
- Display_IM1281B();
}
/* USER CODE END StartDefaultTask */
}
@@ -210,14 +247,14 @@ void startCmdTask(void *argument)
/* Infinite loop */
for(;;)
{
- if (ONENET_CONNECTED)
- {
- uint8_t* dataPtr = ESP8266_GetIPD_soft(0);
- if (dataPtr != NULL)
- {
- OneNet_RevPro(dataPtr);
- }
- }
+ // if (ONENET_CONNECTED)
+ // {
+ // uint8_t* dataPtr = ESP8266_GetIPD_soft(0);
+ // if (dataPtr != NULL)
+ // {
+ // OneNet_RevPro(dataPtr);
+ // }
+ // }
}
/* USER CODE END startCmdTask */
}
@@ -228,41 +265,37 @@ void KeyScan(void)
{
if (K1 == GPIO_PIN_RESET)
{
- // HAL_Delay(5);
osDelay(5);
if (K1 == GPIO_PIN_RESET)
{
- HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
+ KEY_PRESSED[0] = 1;
}
while (K1 == GPIO_PIN_RESET);
}
if (K2 == GPIO_PIN_RESET)
{
- // HAL_Delay(5);
osDelay(5);
if (K2 == GPIO_PIN_RESET)
{
- HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
+ KEY_PRESSED[1] = 1;
}
while (K2 == GPIO_PIN_RESET);
}
if (K3 == GPIO_PIN_RESET)
{
- // HAL_Delay(5);
osDelay(5);
if (K3 == GPIO_PIN_RESET)
{
- HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
+ KEY_PRESSED[2] = 1;
}
while (K3 == GPIO_PIN_RESET);
}
if (K4 == GPIO_PIN_RESET)
{
- // HAL_Delay(5);
osDelay(5);
if (K4 == GPIO_PIN_RESET)
{
- HAL_GPIO_TogglePin(RELAY1_GPIO_Port, RELAY1_Pin);
+ KEY_PRESSED[3] = 1;
}
while (K4 == GPIO_PIN_RESET);
}
diff --git a/Core/Src/main.c b/Core/Src/main.c
index a3877c8..08768c7 100644
--- a/Core/Src/main.c
+++ b/Core/Src/main.c
@@ -57,6 +57,13 @@
/* USER CODE BEGIN PV */
extern unsigned short esp8266_cnt;
extern unsigned char esp8266_buf[128];
+
+volatile uint32_t systick_1ms = 0;
+
+char flag_1s = 0;
+char flag_2s = 0;
+char flag_5s = 0;
+
uint8_t* UART1_RxData[40];
uint8_t UART2_RxData;
@@ -292,7 +299,7 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
memcpy(IM_RxBuf, UART1_RxData, Size);
IM_RecvLen = Size;
IM_RecvDone = 1;
- IM_Analyze();
+ // IM_Analyze();
HAL_UARTEx_ReceiveToIdle_IT(&huart1, (uint8_t*)UART1_RxData, 40);
}
}
@@ -322,17 +329,23 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
/* USER CODE BEGIN Callback 0 */
- // if(htim->Instance == TIM1){
- // KeyScan();
- // }
- // if (htim->Instance == TIM3)
+ // if(htim->Instance == TIM1)
// {
- // if (ONENET_CONNECTED)
- // {
- // dataPtr = ESP8266_GetIPD(0);
- // if (dataPtr != NULL)
- // {
- // OneNet_RevPro(dataPtr);
+ // systick_1ms++;
+ //
+ // if(systick_1ms % 1000 == 0) {
+ // flag_1s = 1;
+ //
+ // static uint8_t cnt_2s = 0;
+ // if(++cnt_2s >= 2) {
+ // cnt_2s = 0;
+ // flag_2s = 1;
+ // }
+ //
+ // static uint8_t cnt_5s = 0;
+ // if(++cnt_5s >= 5) {
+ // cnt_5s = 0;
+ // flag_5s = 1;
// }
// }
// }
@@ -342,7 +355,27 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
HAL_IncTick();
}
/* USER CODE BEGIN Callback 1 */
+ if (htim->Instance == TIM4)
+ {
+ if (uwTick % 1000 == 0)
+ {
+ flag_1s = 1;
+ static uint8_t cnt_2s = 0;
+ if (++cnt_2s >= 2)
+ {
+ cnt_2s = 0;
+ flag_2s = 1;
+ }
+
+ static uint8_t cnt_5s = 0;
+ if (++cnt_5s >= 5)
+ {
+ cnt_5s = 0;
+ flag_5s = 1;
+ }
+ }
+ }
/* USER CODE END Callback 1 */
}
diff --git a/Core/Src/tim.c b/Core/Src/tim.c
index c61a887..9c3d6c5 100644
--- a/Core/Src/tim.c
+++ b/Core/Src/tim.c
@@ -42,9 +42,9 @@ void MX_TIM1_Init(void)
/* USER CODE END TIM1_Init 1 */
htim1.Instance = TIM1;
- htim1.Init.Prescaler = 7199;
+ htim1.Init.Prescaler = 71;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim1.Init.Period = 99;
+ htim1.Init.Period = 9999;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
diff --git a/IntelliChargingPile.ioc b/IntelliChargingPile.ioc
index 893610d..8c64fc1 100644
--- a/IntelliChargingPile.ioc
+++ b/IntelliChargingPile.ioc
@@ -216,8 +216,8 @@ SPI1.Mode=SPI_MODE_MASTER
SPI1.VirtualType=VM_MASTER
TIM1.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM1.IPParameters=Prescaler,Period,AutoReloadPreload
-TIM1.Period=99
-TIM1.Prescaler=7199
+TIM1.Period=9999
+TIM1.Prescaler=71
TIM3.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
TIM3.IPParameters=Prescaler,Period,AutoReloadPreload
TIM3.Period=59