Compare commits
17 Commits
8053971109
...
fbd83bed35
Author | SHA1 | Date |
---|---|---|
|
fbd83bed35 | |
|
25af1a47ff | |
|
a31b9af810 | |
|
3ea22514fd | |
|
af04d91130 | |
|
3a36df469e | |
|
931a71a25c | |
|
ade6e13f20 | |
|
eaecfce9ad | |
|
c184bd3407 | |
|
55811f0946 | |
|
d6f0e84c3f | |
|
d0a9e1f573 | |
|
3ee2cccf2d | |
|
2b428a8e35 | |
|
bccfc0c450 | |
|
688f925657 |
|
@ -35,6 +35,13 @@
|
|||
"rtc.h": "c",
|
||||
"soe.h": "c",
|
||||
"hd_rtc.h": "c",
|
||||
"flash.h": "c"
|
||||
"flash.h": "c",
|
||||
"configparameter.h": "c",
|
||||
"usart.h": "c",
|
||||
"w25qxx.h": "c",
|
||||
"w25q256.h": "c",
|
||||
"gpio.h": "c",
|
||||
"bl_usart.h": "c",
|
||||
"soc.h": "c"
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "bl_chargControl.h"
|
||||
|
||||
#include "capture.h"
|
||||
|
||||
void chargControl(void);
|
||||
|
||||
|
|
|
@ -6,62 +6,78 @@
|
|||
#include "pDebug.h"
|
||||
#include "parameter.h"
|
||||
#include "FM_TIM.h"
|
||||
#include "inFlash.h"
|
||||
#include "SOE.h"
|
||||
|
||||
void startInfo(void)
|
||||
{
|
||||
log_info("uniqueDeviceID : 0x%x%x%x%x%x%x%x \n", g_cfgParameter.uniqueDeviceID[0]
|
||||
, g_cfgParameter.uniqueDeviceID[1]
|
||||
, g_cfgParameter.uniqueDeviceID[2]
|
||||
, g_cfgParameter.uniqueDeviceID[3]
|
||||
, g_cfgParameter.uniqueDeviceID[4]
|
||||
, g_cfgParameter.uniqueDeviceID[5]
|
||||
, g_cfgParameter.uniqueDeviceID[6]);
|
||||
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
|
||||
log_info("bat485_Baud : %d \n", g_cfgParameter.bat485_Baud);
|
||||
log_info("powerBoxType : 0x%x \n", g_cfgParameter.powerBoxType);
|
||||
log_info("constantVoltageV : %f \n", g_cfgParameter.constantVoltageV);
|
||||
log_info("floatI : %f \n", g_cfgParameter.floatI);
|
||||
log_info("startSolarOpenCircuitV : %f \n", g_cfgParameter.startSolarOpenCircuitV);
|
||||
log_info("stopSolarOpenCircuitV : %f \n", g_cfgParameter.stopSolarOpenCircuitV);
|
||||
log_info("stopSolarOutputCircuitV : %f \n", g_cfgParameter.stopSolarOutputCircuitV);
|
||||
log_info("checkCanStartTime : %d \n", g_cfgParameter.checkCanStartTime);
|
||||
log_info("shortCircuitJudgmentDelay : %d \n", g_cfgParameter.shortCircuitJudgmentDelay);
|
||||
log_info("inputPowerLowJudgmentDelay : %d \n", g_cfgParameter.inputPowerLowJudgmentDelay);
|
||||
log_info("inputPowerLowAgainOutputDelay : %d \n", g_cfgParameter.inputPowerLowAgainOutputDelay);
|
||||
log_info("firstStageProtectionDelay : %d \n", g_cfgParameter.firstStageProtectionDelay);
|
||||
log_info("firstStageProtectionValue : %d \n", g_cfgParameter.firstStageProtectionValue);
|
||||
log_info("firstStageProtectionCurr : %f \n", g_cfgParameter.firstStageProtectionCurr);
|
||||
log_info("secondStageProtectionDelay : %d \n", g_cfgParameter.secondStageProtectionDelay);
|
||||
log_info("secondStageProtectionCurr : %f \n", g_cfgParameter.secondStageProtectionCurr);
|
||||
log_info("thirdStageProtectionDelay : %d \n", g_cfgParameter.thirdStageProtectionDelay);
|
||||
log_info("thirdStageProtectionCurr : %f \n", g_cfgParameter.thirdStageProtectionCurr);
|
||||
log_info("inputPowerLowDetectionDelay : %d \n", g_cfgParameter.inputPowerLowDetectionDelay);
|
||||
log_info("inputPowerLowDetectionVolt : %f \n", g_cfgParameter.inputPowerLowDetectionVolt);
|
||||
log_info("maxOpenSolarOutputCircuitV : %f \n", g_cfgParameter.maxOpenSolarOutputCircuitV);
|
||||
log_info("maxChargCurr : %f \n", g_cfgParameter.maxChargCurr);
|
||||
log_info("minCheckLoopImpedanceChargCurr : %f \n", g_cfgParameter.minCheckLoopImpedanceChargCurr);
|
||||
log_info("fullPowerOutputTemperature : %f \n", g_cfgParameter.fullPowerOutputTemperature);
|
||||
log_info("reducePowerOutputTemperature : %f \n", g_cfgParameter.reducePowerOutputTemperature);
|
||||
log_info("stopPowerOutputTemperature : %f \n", g_cfgParameter.stopPowerOutputTemperature);
|
||||
log_info("constantVoltageChargeV : %f \n", g_cfgParameter.constantVoltageChargeV);
|
||||
log_info("FloatV : %f \n", g_cfgParameter.FloatV);
|
||||
log_info("loopImpedance : %f \n", g_cfgParameter.loopImpedance);
|
||||
log_info("HighSideMosTemperature_stop : %f \n", g_cfgParameter.HighSideMosTemperature_stop);
|
||||
log_info("HighSideMosTemperature_end : %f \n", g_cfgParameter.HighSideMosTemperature_end);
|
||||
log_info("HighSideMosTemperature_start : %f \n", g_cfgParameter.HighSideMosTemperature_start);
|
||||
log_info("outputAgainFlagTime : %d \n", g_cfgParameter.outputAgainFlagTime);
|
||||
log_info("excessiveLoadFlagTime : %d \n", g_cfgParameter.excessiveLoadFlagTime);
|
||||
log_info("FloatChargeV : %f \n", g_cfgParameter.FloatChargeV);
|
||||
log_info("collectOpenCircuitVoltageTime : %d \n", g_cfgParameter.collectOpenCircuitVoltageTime);
|
||||
log_info("Access_Node_Type : %d \n", g_cfgParameter.Access_Node_Type);
|
||||
log_info("Communication_Methods : %d \n", g_cfgParameter.Communication_Methods);
|
||||
log_info("Registration_Status : %d \n", g_cfgParameter.Registration_Status);
|
||||
log_info("address : 0x%x%x%x%x%x%x%x \n", g_cfgParameter.address[0]
|
||||
, g_cfgParameter.address[1]
|
||||
, g_cfgParameter.address[2]
|
||||
, g_cfgParameter.address[3]
|
||||
, g_cfgParameter.address[4]
|
||||
, g_cfgParameter.address[5]
|
||||
, g_cfgParameter.address[6]);
|
||||
log_info("Access_Node_Type : %x \n", g_cfgParameter.Access_Node_Type);
|
||||
log_info("Communication_Methods : %x \n", g_cfgParameter.Communication_Methods);
|
||||
log_info("startFlagSL : 0x%x%x \n", g_cfgParameter.startFlagSL[0], g_cfgParameter.startFlagSL[1]);
|
||||
log_info("endFlagSL : 0x%x \n", g_cfgParameter.endFlagSL);
|
||||
log_info("hardwareID : 0x%x%x%x%x%x%x \n", g_cfgParameter.hardwareID[0]
|
||||
, g_cfgParameter.hardwareID[1]
|
||||
, g_cfgParameter.hardwareID[2]
|
||||
, g_cfgParameter.hardwareID[3]
|
||||
, g_cfgParameter.hardwareID[4]
|
||||
, g_cfgParameter.hardwareID[5]);
|
||||
log_info("communicationID : 0x%x%x%x%x \n", g_cfgParameter.communicationID[0]
|
||||
, g_cfgParameter.communicationID[1]
|
||||
, g_cfgParameter.communicationID[2]
|
||||
, g_cfgParameter.communicationID[3]);
|
||||
log_info("protocolType : 0x%x \n", g_cfgParameter.protocolType);
|
||||
log_info("startFlagHY : 0x%x \n", g_cfgParameter.startFlagHY);
|
||||
log_info("endFlagHY : 0x%x \n", g_cfgParameter.endFlagHY);
|
||||
log_info("onlyPower : 0x%x \n", g_cfgParameter.onlyPower);
|
||||
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
|
||||
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
|
||||
|
||||
log_info("loopImpedance : %f \n", getLoopImpedance());
|
||||
}
|
||||
|
||||
|
||||
void start(void)
|
||||
{
|
||||
Init();
|
||||
|
||||
uartCommonInit();
|
||||
|
||||
|
||||
// setDutyRatio(0.0001f);
|
||||
// EN_PWMOUT_Eable();
|
||||
|
||||
task_Init();
|
||||
|
||||
startInfo();
|
||||
|
||||
// HAL_Delay(5000);
|
||||
|
||||
// HAL_Delay(5000);
|
||||
// while (1) {
|
||||
// cfgTest();
|
||||
// HAL_Delay(1000);
|
||||
// }
|
||||
/* 启动事件 */
|
||||
// insertEventsOrderRecord(startEvent);
|
||||
|
||||
TimeSliceOffset_Start();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,10 +10,12 @@
|
|||
|
||||
void eventsOrderRecordStartInit(void);
|
||||
void setEventsOrderRecord(void);
|
||||
void printfEventsOrderRecord(void);
|
||||
void readEventsOrderRecord(uint16_t offset, uint8_t *data);
|
||||
void insertEventsOrderRecord(eventsOrderRecordMode mode);
|
||||
void cleanEventsOrderRecord(void);
|
||||
|
||||
|
||||
uint16_t getSoeDataInfoSize(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,6 +28,6 @@ void checkAbnormal(void);
|
|||
|
||||
void WORK_VOLT_Interrupt(void);
|
||||
void DSG_PROT_Interrupt(void);
|
||||
|
||||
void EXCHG_PROT_Interrupt(void);
|
||||
|
||||
#endif
|
|
@ -5,6 +5,9 @@
|
|||
#include "FM_TIM.h"
|
||||
#include "comm_types.h"
|
||||
|
||||
#define PI_CONTROL_MAX 0.03f
|
||||
#define PI_CONTROL_MIN -0.03f
|
||||
|
||||
BOOL getChargControlFlag(void);
|
||||
void setChargControlFlag(BOOL state);
|
||||
void bl_chargControl(void);
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
|
||||
#ifndef BL_USART_H_
|
||||
#define BL_USART_H_
|
||||
|
||||
|
||||
#include "comm_types.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
/* 是否使能充电控制盒的HY协议 */
|
||||
#define HY_ChargeControlBox_PROTOCOL_ENABLE
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* SL协议读取寄存器最大地址 */
|
||||
#define maxReadRegAddrMacro 0x0150
|
||||
/* SL协议读取寄存器最小地址 */
|
||||
#define minReadRegAddrMacro 0x0100
|
||||
/* SL协议读取寄存器最大长度 */
|
||||
#define maxReadRegAddrNumMacro 80
|
||||
|
||||
|
||||
/* SL协议写入寄存器最大地址 */
|
||||
#define maxWriteRegAddrMacro 0x0150
|
||||
/* SL协议写入寄存器最小地址 */
|
||||
#define minWriteRegAddrMacro 0x0100
|
||||
/* SL协议写入寄存器最大长度 */
|
||||
#define maxWriteRegAddrNumMacro 10
|
||||
|
||||
/* SL协议寄存器长度 */
|
||||
#define RegAddrNumMacro 32
|
||||
|
||||
/* SL协议下发配置文件内容最长长度 */
|
||||
#define maxDistributionCfgLen 230
|
||||
/* SL协议读取配置文件内容最长长度 */
|
||||
#define maxReadCfgLen 80
|
||||
|
||||
|
||||
#define floatMagnification 10.0f
|
||||
|
||||
#ifdef HY_ChargeControlBox_PROTOCOL_ENABLE
|
||||
|
||||
#define maxDataLenHY 50
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void uartCommonInit(void);
|
||||
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
|
||||
|
||||
void gw485DataAnalysis(device_handle device);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
#ifndef BL_CFG_PROTOCOL_H_
|
||||
#define BL_CFG_PROTOCOL_H_
|
||||
|
||||
#include "comm_types.h"
|
||||
|
||||
void inConfigBuff(uint8_t c);
|
||||
void zeroConfigBuff(void);
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
|
||||
void read_and_process_config_data(void);
|
||||
|
||||
#endif
|
|
@ -1,14 +0,0 @@
|
|||
|
||||
#ifndef BL_HY_PROTOCOL_H_
|
||||
#define BL_HY_PROTOCOL_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
BOOL getHYconfigModeState(void);
|
||||
void setHYconfigModeState(BOOL state);
|
||||
|
||||
void HY_read_and_process_uart_data(device_handle device);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -5,88 +5,127 @@
|
|||
#include "flash.h"
|
||||
#include "stm32g431xx.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "bl_usart.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/* 高字节在前,低字节在后 */
|
||||
typedef struct _recv_config_info{
|
||||
uint8_t start_Flag[2]; /* 开始标志 */
|
||||
/* SL */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
// uint8_t Access_Node_Type[2]; /* 接入节点类型 */
|
||||
// uint8_t Communication_Methods[2]; /* 通信方式 */
|
||||
uint8_t gw485_Baud[4]; /* 串口波特率 */
|
||||
uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
|
||||
// /* 高字节在前,低字节在后 */
|
||||
// typedef struct _recv_config_info{
|
||||
// uint8_t start_Flag[2]; /* 开始标志 */
|
||||
// /* SL */
|
||||
// uint8_t address[7]; /* 地址 */
|
||||
// // uint8_t Access_Node_Type[2]; /* 接入节点类型 */
|
||||
// // uint8_t Communication_Methods[2]; /* 通信方式 */
|
||||
// uint8_t gw485_Baud[4]; /* 串口波特率 */
|
||||
// uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
// /* HY */
|
||||
// uint8_t hardwareID[6]; /* 硬件ID */
|
||||
// uint8_t communicationID[4]; /* 通信ID */
|
||||
// uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
|
||||
|
||||
uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
0x01:HY*/
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
// uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
// 0x01:HY*/
|
||||
// uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
// 0x01:是*/
|
||||
|
||||
uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */
|
||||
uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */
|
||||
uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */
|
||||
uint8_t stopSolarOpenCircuitV[2]; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
uint8_t constantVoltageChargeV[2]; /* 恒压充电时的输出电压 (V) */
|
||||
uint8_t FloatChargeV[2]; /* 浮充充电时的输出电压 (V) */
|
||||
uint8_t HighSideMosTemperature_stop[2]; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
uint8_t HighSideMosTemperature_end[2]; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
uint8_t HighSideMosTemperature_start[2];/* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
// uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */
|
||||
// uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */
|
||||
// uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */
|
||||
// uint8_t stopSolarOpenCircuitV[2]; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
// uint8_t constantVoltageChargeV[2]; /* 恒压充电时的输出电压 (V) */
|
||||
// uint8_t FloatChargeV[2]; /* 浮充充电时的输出电压 (V) */
|
||||
// uint8_t HighSideMosTemperature_stop[2]; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
// uint8_t HighSideMosTemperature_end[2]; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
// uint8_t HighSideMosTemperature_start[2];/* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
|
||||
// uint8_t checkSolarOpenCircuitVTime[2]; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
// uint8_t sensorEnableBroadcastTime[2]; /* 传感器运行再次注册的间隔 (S) */
|
||||
uint8_t outputAgainFlagTime[2]; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
uint8_t excessiveLoadFlagTime[2]; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
uint8_t eLAgainTime[2]; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
uint8_t crc[2]; /* 校验 */
|
||||
uint8_t end_Flag; /* 结束标志 */
|
||||
}recv_config_info;
|
||||
#define RECV_CONFIG_INFO sizeof(recv_config_info)
|
||||
// // uint8_t checkSolarOpenCircuitVTime[2]; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
// // uint8_t sensorEnableBroadcastTime[2]; /* 传感器运行再次注册的间隔 (S) */
|
||||
// uint8_t outputAgainFlagTime[2]; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
// uint8_t excessiveLoadFlagTime[2]; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
// uint8_t eLAgainTime[2]; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
// uint8_t crc[2]; /* 校验 */
|
||||
// uint8_t end_Flag; /* 结束标志 */
|
||||
// }recv_config_info;
|
||||
// #define RECV_CONFIG_INFO sizeof(recv_config_info)
|
||||
|
||||
typedef struct _config_info{
|
||||
/* SL */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
// uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
// uint16_t Communication_Methods; /* 通信方式 */
|
||||
uint32_t gw485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint32_t bat485_Baud; /* 串口波特率 */
|
||||
// /* SL */
|
||||
// uint8_t address[7]; /* 地址 */
|
||||
// // uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
// // uint16_t Communication_Methods; /* 通信方式 */
|
||||
// uint32_t gw485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
// uint32_t bat485_Baud; /* 串口波特率 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
// /* HY */
|
||||
// uint8_t hardwareID[6]; /* 硬件ID */
|
||||
// uint8_t communicationID[4]; /* 通信ID */
|
||||
// uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
|
||||
uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
0x01:HY*/
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
// uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
// 0x01:HY*/
|
||||
// uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
// 0x01:是*/
|
||||
|
||||
float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于FloatI + 0.1)进行恒压充电 */
|
||||
float floatI; /* 电压高于ConstantVoltageV且电流低于FloatI进行浮充充电 */
|
||||
float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 */
|
||||
float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压 停止充电 */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压 */
|
||||
float FloatChargeV; /* 浮充电压 */
|
||||
float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
|
||||
float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
|
||||
float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
|
||||
// float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于FloatI + 0.1)进行恒压充电 */
|
||||
// float floatI; /* 电压高于ConstantVoltageV且电流低于FloatI进行浮充充电 */
|
||||
// float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 */
|
||||
// float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压 停止充电 */
|
||||
// float constantVoltageChargeV; /* 恒压充电时的输出电压 */
|
||||
// float FloatChargeV; /* 浮充电压 */
|
||||
// float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
|
||||
// float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
|
||||
// float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
|
||||
|
||||
// uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
|
||||
// uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
|
||||
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
|
||||
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
|
||||
uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
|
||||
// // uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
|
||||
// // uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
|
||||
// uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
|
||||
// uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
|
||||
// uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
|
||||
|
||||
uint16_t crc; /* 校验 */
|
||||
uint8_t uniqueDeviceID[7]; /* 设备唯一ID */
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0x01:是*/
|
||||
float constantVoltageV; /* 恒压充电阈值电压(V) */
|
||||
float floatI; /* 浮充充电阈值电流(A) */
|
||||
float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */
|
||||
float stopSolarOutputCircuitV; /* 停止充电太阳能板输出电压(V) */
|
||||
uint16_t checkCanStartTime; /* 检测能否启动间隔时间(S) */
|
||||
uint16_t shortCircuitJudgmentDelay; /* 短路判断延时(S) */
|
||||
uint16_t inputPowerLowJudgmentDelay; /* 前端输入功率不足判断延时(S) */
|
||||
uint16_t inputPowerLowAgainOutputDelay; /* 前端输入功率不足再次输出延时(S) */
|
||||
uint16_t firstStageProtectionDelay; /* 第一段保护延时(10uS) */
|
||||
float firstStageProtectionCurr; /* 第一段保护电流(A) */
|
||||
uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */
|
||||
float secondStageProtectionCurr; /* 第二段保护电流(A) */
|
||||
uint32_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
|
||||
float thirdStageProtectionCurr; /* 第三段保护电流(A) */
|
||||
uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */
|
||||
float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */
|
||||
float maxOpenSolarOutputCircuitV; /* 最大太阳能板输出电压(V) */
|
||||
float maxChargCurr; /* 最大充电电流(A) */
|
||||
float minCheckLoopImpedanceChargCurr; /* 检测回路阻抗时的最小充电电流(A) */
|
||||
float fullPowerOutputTemperature; /* 满功率输出温度(℃) */
|
||||
float reducePowerOutputTemperature; /* 降功率输出温度(℃) */
|
||||
float stopPowerOutputTemperature; /* 停止输出温度(℃) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
|
||||
float FloatChargeV; /* 浮充充电时的输出电压(V) */
|
||||
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
|
||||
float reverseChargProtectionCurr; /* 反向充电保护电流 */
|
||||
|
||||
uint16_t crc; /* 校验 */
|
||||
}config_info;
|
||||
|
||||
#define CONFIG_INFO_SIZE (sizeof(config_info))
|
||||
// typedef struct _other_info {
|
||||
// float loopImpedance;
|
||||
// float totalElectricityConsumption;
|
||||
// float totalChargCapacity;
|
||||
// float lastTime;
|
||||
// }other_info;
|
||||
// #define OTHER_INFO_SIZE (sizeof(other_info))
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#define CONFIG_SAVE_addr (0)
|
||||
|
@ -97,10 +136,18 @@ typedef struct _config_info{
|
|||
#define totalChargCapacity_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 30)
|
||||
#define time_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 40)
|
||||
|
||||
// #define LoopImpedance_SAVE_addr (4096)
|
||||
// #define totalElectricityConsumption_SAVE_addr (LoopImpedance_SAVE_addr + 4)
|
||||
// #define totalChargCapacity_SAVE_addr (LoopImpedance_SAVE_addr + 8)
|
||||
// #define time_SAVE_addr (LoopImpedance_SAVE_addr + 12)
|
||||
|
||||
|
||||
// void save_config_info(config_info *save_config_info);
|
||||
void read_config_info(config_info *output_config_info);
|
||||
void saveConfigInfo(config_info *config_info);
|
||||
void config_info_start(void);
|
||||
void readFlashContent(config_info *configInfo);
|
||||
void cfgTest(void);
|
||||
|
||||
void saveLoopImpedance(float *loopImpedance);
|
||||
void readLoopImpedance(float *loopImpedance);
|
||||
|
@ -110,6 +157,8 @@ void savetotalChargCapacity(float *totalChargCapacity);
|
|||
void readtotalChargCapacity(float *totalChargCapacity);
|
||||
void saveTime(timeInfo *time);
|
||||
void readTime(timeInfo *time);
|
||||
// void saveOtherInfo(other_info *otherInfo);
|
||||
// void readOtherInfo(other_info *otherInfo);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,4 +19,7 @@ void send_init(void);
|
|||
void check_sendState(void);
|
||||
void uart_interruptSend(device_handle device, uint8_t buff[], uint8_t len);
|
||||
|
||||
uint8_t *getInsertData(void);
|
||||
void uart_insertDataSend(device_handle device, uint8_t len);
|
||||
|
||||
#endif
|
|
@ -4,69 +4,50 @@
|
|||
#include "main.h"
|
||||
#include "comm_types.h"
|
||||
#include "chargControlTypes.h"
|
||||
|
||||
#define softVer "SV01_24101501"
|
||||
#include "configParameter.h"
|
||||
|
||||
// #pragma pack(push,1)
|
||||
|
||||
/* 主要有配置文件读取出来的数据 */
|
||||
typedef struct _config_parameter{
|
||||
float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于(FloatI + 0.1)进行恒压充电
|
||||
电压低于该(ConstantVoltageV - 0.2) 进行恒流充电 (V) */
|
||||
float floatI; /* 电压高于该ConstantVoltageV且电流低于FloatI进行浮充充电 (A) */
|
||||
float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 (V) */
|
||||
float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压 (V) */
|
||||
float FloatV; /* 浮充充电时的输出电压 (V) */
|
||||
float loopImpedance; /* 回路阻抗大小 (mΩ) */
|
||||
float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
uint8_t uniqueDeviceID[7]; /* 设备唯一ID */
|
||||
|
||||
float firstStageProtectionCurr; /* 第一段保护的电流(单位A) */
|
||||
uint16_t firstStageProtectionValue; /* 第一段保护的电流采集的ADC的值 */
|
||||
uint16_t firstStageProtectionDelay; /* 第一段保护的延时时间(单位10uS) */
|
||||
float secondStageProtectionCurr; /* 第二段保护的电流(单位A) */
|
||||
uint32_t secondStageProtectionDelay; /* 第二段保护的延时时间(单位100uS) */
|
||||
float thirdStageProtectionCurr; /* 第三段保护的电流(单位A) */
|
||||
uint32_t thirdStageProtectionDelay; /* 第三段保护的延时时间(单位100uS) */
|
||||
float checkLoopImpedanceChargCurr; /* 检测回路阻抗时的充电电流要大于该值(单位A) */
|
||||
float lowInputLoadDetectionVolt; /* 输入功率较低延时电压(单位V) */
|
||||
uint16_t lowInputLoadDetectionDelay; /* 输入功率较低延时(单位100uS) */
|
||||
float maxChargCurr; /* 最大充电电流(A) */
|
||||
float maxOpenSolarOpenCircuitV; /* 最大充电电压(V) */
|
||||
|
||||
|
||||
// uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 (S) */
|
||||
// uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
uint16_t eLAgainTime; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
// uint16_t softShortTime; /* 软件短路保护延时 时间(100uS) */
|
||||
|
||||
uint32_t collectOpenCircuitVoltageTime; /* 充电时开路电压采集时间间隔(S) */
|
||||
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0xFF:是*/
|
||||
float constantVoltageV; /* 恒压充电阈值电压(V) */
|
||||
float floatI; /* 浮充充电阈值电流(A) */
|
||||
float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */
|
||||
float stopSolarOutputCircuitV; /* 停止充电太阳能板输出电压(V) */
|
||||
uint16_t checkCanStartTime; /* 检测能否启动间隔时间(S) */
|
||||
uint16_t shortCircuitJudgmentDelay; /* 短路判断延时(S) */
|
||||
uint16_t inputPowerLowJudgmentDelay; /* 前端输入功率不足判断延时(S) */
|
||||
uint16_t inputPowerLowAgainOutputDelay; /* 前端输入功率不足再次输出延时(S) */
|
||||
uint16_t firstStageProtectionDelay; /* 第一段保护延时(10uS) */
|
||||
float firstStageProtectionCurr; /* 第一段保护电流(A) */
|
||||
uint16_t firstStageProtectionValue; /* 第一段保护ADC值 */
|
||||
uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */
|
||||
float secondStageProtectionCurr; /* 第二段保护电流(A) */
|
||||
uint32_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
|
||||
float thirdStageProtectionCurr; /* 第三段保护电流(A) */
|
||||
uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */
|
||||
float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */
|
||||
float maxOpenSolarOutputCircuitV; /* 最大太阳能板输出电压(V) */
|
||||
float maxChargCurr; /* 最大充电电流(A) */
|
||||
float minCheckLoopImpedanceChargCurr; /* 检测回路阻抗时的最小充电电流(A) */
|
||||
float fullPowerOutputTemperature; /* 满功率输出温度(℃) */
|
||||
float reducePowerOutputTemperature; /* 降功率输出温度(℃) */
|
||||
float stopPowerOutputTemperature; /* 停止输出温度(℃) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
|
||||
float FloatChargeV; /* 浮充充电时的输出电压(V) */
|
||||
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
|
||||
float reverseChargProtectionCurr; /* 反向充电保护电流 */
|
||||
|
||||
/* SL */
|
||||
uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
uint16_t Communication_Methods; /* 通信方式 */
|
||||
uint16_t Registration_Status; /* 注册状态 */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
uint8_t startFlagSL[2]; /* 起始标志 */
|
||||
uint8_t endFlagSL; /* 结束标志 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
uint8_t startFlagHY; /* 起始码 */
|
||||
uint8_t endFlagHY; /* 结束码 */
|
||||
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
} config_parameter;
|
||||
extern config_parameter g_cfgParameter;
|
||||
typedef struct _otherParameter{
|
||||
|
@ -85,8 +66,11 @@ typedef struct _otherParameter{
|
|||
|
||||
int MPPT_Mode; /* 工作模式 */
|
||||
|
||||
uint8_t versionInformation[13]; /* 软件版本信息 */
|
||||
uint8_t versionInformation[13]; /* 软件版本信息 */
|
||||
|
||||
float loopImpedance; /* 回路阻抗大小 (Ω) */
|
||||
|
||||
uint16_t Registration_Status; /* 注册状态 */
|
||||
}otherParameter;
|
||||
|
||||
// #pragma pack(pop)
|
||||
|
@ -101,6 +85,7 @@ uint8_t getMosTemperState(void);
|
|||
void setMosTemperState(uint8_t state);
|
||||
BOOL getCheckImpedanceState(void);
|
||||
void setCheckImpedanceState(void);
|
||||
void resetCheckImpedanceState(void);
|
||||
void setLastTime(timeInfo time);
|
||||
timeInfo getLastTime(void);
|
||||
|
||||
|
@ -134,8 +119,13 @@ float getChargBatteryCurrent(void);
|
|||
BOOL getChargMosState(void);
|
||||
void setChargMosState(BOOL state);
|
||||
BOOL getDischargMosState(void);
|
||||
uint8_t *getVersionInformation(void);
|
||||
|
||||
uint8_t *getVersionnInformation(void);
|
||||
float getLoopImpedance(void);
|
||||
BOOL setLoopImpedance(float loopImpedance);
|
||||
uint16_t getRegistrationStatus(void);
|
||||
void setRegistrationStatus(uint16_t status);
|
||||
|
||||
void setExChargeCurr(void);
|
||||
float getExChargeCurr(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef BL_SOC_H_
|
||||
#define BL_SOC_H_
|
||||
|
||||
|
||||
int find_soc(float voltage);
|
||||
|
||||
|
||||
#endif
|
|
@ -10,13 +10,14 @@ void task_Init(void);
|
|||
|
||||
void beginStartControlTask(void);
|
||||
void beginSoftStartTask(void);
|
||||
void beginHYconfigMode(void);
|
||||
void uartTaskInit(void);
|
||||
// void beginHYconfigMode(void);
|
||||
// void uartTaskInit(void);
|
||||
|
||||
void startShortCircuitProtection(void);
|
||||
void stopShortCircuitProtection(void);
|
||||
void startExcessiveLoadProtection(void);
|
||||
void startSoftShortCircuitProtection(void);
|
||||
void startEXCHGSCProtection(void);
|
||||
|
||||
void chargRunLed(uint8_t mode);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "pDebug.h"
|
||||
#include "interruptSend.h"
|
||||
#include "FM_RTC.h"
|
||||
#include "SOE.h"
|
||||
|
||||
/**
|
||||
* @brief 初始化外设,同时通过配置文件初始化系统参数
|
||||
|
@ -22,30 +23,46 @@ void Init(void)
|
|||
// HAL_Delay(10000);
|
||||
|
||||
config_info_start();
|
||||
|
||||
Init_debug_uart();
|
||||
|
||||
ADC_Capture_Init();
|
||||
proportionalInt(g_cfgParameter.onlyPower);
|
||||
proportionalInt(g_cfgParameter.powerBoxType);
|
||||
|
||||
g_cfgParameter.firstStageProtectionValue = setfirstStageProtectionValue(g_cfgParameter.firstStageProtectionCurr);
|
||||
|
||||
FM_GPIO_Init();
|
||||
tim_Init();
|
||||
|
||||
FM_RTC_Init();
|
||||
|
||||
Init_debug_uart();
|
||||
Init_BAT485_uart(g_cfgParameter.bat485_Baud);
|
||||
Init_GW485_uart(g_cfgParameter.gw485_Baud);
|
||||
// Init_BAT485_uart(115200);
|
||||
// Init_GW485_uart(115200);
|
||||
// Init_BAT485_uart(115200);
|
||||
// Init_GW485_uart(115200);
|
||||
start_gw485Rx_It();
|
||||
start_bat485Rx_It();
|
||||
|
||||
send_init();
|
||||
eventsOrderRecordStartInit();
|
||||
|
||||
// POW_FF_PCON_Open();
|
||||
// POW_OUT_PCON_Open();
|
||||
|
||||
HAL_Delay(100);
|
||||
setPowerOutput(TRUE);
|
||||
|
||||
// /* 判断有无电池 */
|
||||
// if (getOutputVoltage() > 11.0f) {
|
||||
// setBatteryState(TRUE);
|
||||
// setPowerOutput(TRUE);
|
||||
// } else {
|
||||
// setBatteryState(FALSE);
|
||||
// }
|
||||
|
||||
// EN_PWMOUT_Eable();
|
||||
resetCheckImpedanceState();
|
||||
|
||||
// setDutyRatio(0.5);
|
||||
// while(1);
|
||||
// while (1) {
|
||||
// log_info("Init_debug_uart \n");
|
||||
// HAL_Delay(1000);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
#include "stdio.h"
|
||||
#include "parameter.h"
|
||||
#include "FM_RTC.h"
|
||||
|
||||
#include "flash.h"
|
||||
#include "capture.h"
|
||||
|
||||
#define eventsOrderRecordStartAddr 4096
|
||||
|
||||
|
@ -25,14 +26,21 @@ typedef struct _soeSaveInfo {
|
|||
} soeSaveInfo;
|
||||
|
||||
typedef struct _soeStorageParameters {
|
||||
uint16_t len; //soe记录次数
|
||||
uint16_t len; //soe下次记录距离0的偏移量
|
||||
uint16_t pos; //下次soe记录的位置
|
||||
} soeStorageParameters;
|
||||
|
||||
static soeSaveInfo soeInfo = {0};
|
||||
static soeStorageParameters soeParameters = {0};
|
||||
|
||||
|
||||
/**
|
||||
* @brief 得到一次时间记录的长度
|
||||
* @param
|
||||
*/
|
||||
uint16_t getSoeDataInfoSize(void)
|
||||
{
|
||||
return soeDataInfoSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化事件顺序记录
|
||||
|
@ -40,13 +48,26 @@ static soeStorageParameters soeParameters = {0};
|
|||
*/
|
||||
void eventsOrderRecordStartInit(void)
|
||||
{
|
||||
read_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
|
||||
if (soeParameters.len == 0xFFFF && soeParameters.pos == 0xFFFF) {
|
||||
soeParameters.len = 0;
|
||||
soeParameters.pos = eventsOrderRecordStartAddr + sizeof(soeParameters);
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
}
|
||||
|
||||
else if (soeParameters.len > 100
|
||||
|| soeParameters.pos != eventsOrderRecordStartAddr + sizeof(soeParameters) + soeParameters.len * soeDataInfoSize) {
|
||||
soeParameters.len = 0;
|
||||
soeParameters.pos = eventsOrderRecordStartAddr + sizeof(soeParameters);
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
}
|
||||
|
||||
soeInfo.count = 5;
|
||||
soeInfo.insertPos = 0;
|
||||
soeInfo.outPos = 0;
|
||||
soeInfo.outData = NULL;
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
|
||||
read_Flash((uint8_t *)(&soeParameters), sizeof(soeParameters));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,6 +84,8 @@ void eventsOrderRecordStartInit(void)
|
|||
| overTemperature | mos管温度 |
|
||||
| stopTemperature | mos管温度 |
|
||||
| overchargCurr | 充电电流 |
|
||||
| hardwareShortCircuitProtection| 输出电流 |
|
||||
| abnormalControl | 太阳能板输出电压 |
|
||||
*/
|
||||
void insertEventsOrderRecord(eventsOrderRecordMode mode)
|
||||
{
|
||||
|
@ -72,44 +95,72 @@ void insertEventsOrderRecord(eventsOrderRecordMode mode)
|
|||
}
|
||||
|
||||
soeInfo.count--;
|
||||
soeInfo.insertData->data.mode = mode;
|
||||
soeInfo.insertData->mode = mode;
|
||||
getRTC_Time(&soeInfo.insertData->time);
|
||||
|
||||
if (mode == firstStageProtection) {
|
||||
soeInfo.insertData->data.temp = getDischargCurrent();
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == secondStageProtection) {
|
||||
soeInfo.insertData->data.temp = getDischargCurrent();
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == thirdStageProtection) {
|
||||
soeInfo.insertData->data.temp = getDischargCurrent();
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == lowInputLoad) {
|
||||
soeInfo.insertData->data.temp = getOutputVoltage();
|
||||
soeInfo.insertData->temp = getOutputVoltage();
|
||||
}
|
||||
|
||||
else if (mode == overTemperature) {
|
||||
soeInfo.insertData->data.temp = getHighSideMosTemperature();
|
||||
soeInfo.insertData->temp = getHighSideMosTemperature();
|
||||
}
|
||||
|
||||
else if (mode == stopTemperature) {
|
||||
soeInfo.insertData->data.temp = getHighSideMosTemperature();
|
||||
soeInfo.insertData->temp = getHighSideMosTemperature();
|
||||
}
|
||||
|
||||
else if (mode == overchargCurr) {
|
||||
soeInfo.insertData->data.temp = getChargCurrent();
|
||||
soeInfo.insertData->temp = getChargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == overInputVolt) {
|
||||
soeInfo.insertData->temp = getSolarInCircuitVoltage();
|
||||
}
|
||||
|
||||
else if (mode == hardwareShortCircuitProtection) {
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == hardwareInputProtection) {
|
||||
soeInfo.insertData->temp = get_EXCHG_CURR();
|
||||
}
|
||||
|
||||
else if (mode == InputProtection) {
|
||||
soeInfo.insertData->temp = get_EXCHG_CURR();
|
||||
}
|
||||
|
||||
else if (mode == startEvent) {
|
||||
soeInfo.insertData->temp = 0;
|
||||
}
|
||||
|
||||
else if (mode == abnormalControl) {
|
||||
soeInfo.insertData->temp = getSolarInCircuitVoltage();
|
||||
}
|
||||
|
||||
else {
|
||||
soeInfo.count++;
|
||||
return;
|
||||
}
|
||||
|
||||
soeInfo.insertPos++;
|
||||
if (soeInfo.insertPos >= 5) {
|
||||
soeInfo.insertPos = 0;
|
||||
}
|
||||
|
||||
if (count <= 0) {
|
||||
if (soeInfo.count <= 0) {
|
||||
soeInfo.insertData = NULL;
|
||||
} else {
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
|
@ -128,8 +179,24 @@ void setEventsOrderRecord(void)
|
|||
if (soeInfo.outData == NULL || soeInfo.count >= 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
write_Flash((uint8_t *)(soeInfo.outData), soeParameters.pos, soeDataInfoSize);
|
||||
// read_Flash((uint8_t *)(soeInfo.outData), eventsOrderRecordStartAddr, sizeof(soeStorageParameters));
|
||||
|
||||
// debug_printf("mode = %d \n", soeInfo.outData->mode);
|
||||
// debug_printf("year = %d \n", soeInfo.outData->time.year);
|
||||
// debug_printf("month = %d \n", soeInfo.outData->time.month);
|
||||
// debug_printf("day = %d \n", soeInfo.outData->time.day);
|
||||
// debug_printf("hour = %d \n", soeInfo.outData->time.hour);
|
||||
// debug_printf("minute = %d \n", soeInfo.outData->time.minute);
|
||||
// debug_printf("second = %d \n", soeInfo.outData->time.second);
|
||||
|
||||
// write_Flash((uint8_t *)(&soeInfo.outData), soeDataInfoSize);
|
||||
soeParameters.len++;
|
||||
if (soeParameters.len >= 100) {
|
||||
soeParameters.len = 0;
|
||||
}
|
||||
soeParameters.pos += soeDataInfoSize;
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeStorageParameters));
|
||||
|
||||
soeInfo.outPos++;
|
||||
if (soeInfo.outPos >= 5) {
|
||||
|
@ -145,17 +212,39 @@ void setEventsOrderRecord(void)
|
|||
|
||||
if (soeInfo.insertData == NULL) {
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将事件从flash中依次读取出来
|
||||
* @param
|
||||
* @brief 将事件从flash中依次读取出来
|
||||
* @param offset : 距离下次写入数据的偏移量
|
||||
* *data : 数据的储存位置
|
||||
*/
|
||||
|
||||
void printfEventsOrderRecord(void)
|
||||
void readEventsOrderRecord(uint16_t offset, uint8_t *data)
|
||||
{
|
||||
uint16_t addr;
|
||||
|
||||
if (soeParameters.len - offset < 0) {
|
||||
addr = eventsOrderRecordStartAddr + sizeof(soeStorageParameters)
|
||||
+ (100 + soeParameters.len - offset) * soeDataInfoSize;
|
||||
} else {
|
||||
addr = eventsOrderRecordStartAddr + sizeof(soeStorageParameters)
|
||||
+ (soeParameters.len - offset) * soeDataInfoSize;
|
||||
}
|
||||
|
||||
read_Flash(data, addr, soeDataInfoSize);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 清除SOE所有事件
|
||||
* @param
|
||||
*/
|
||||
void cleanEventsOrderRecord(void)
|
||||
{
|
||||
erase_Sector_Flash((eventsOrderRecordStartAddr / 4096));
|
||||
soeParameters.len = 0;
|
||||
soeParameters.pos = eventsOrderRecordStartAddr + sizeof(soeParameters);
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "configParameter.h"
|
||||
#include "capture.h"
|
||||
#include "bl_chargControl.h"
|
||||
#include "SOE.h"
|
||||
|
||||
//static int checkMode = 0;
|
||||
|
||||
|
@ -45,7 +46,8 @@ void setDisChargOverLoad(void)
|
|||
if (num1 >= g_cfgParameter.thirdStageProtectionDelay) {
|
||||
num1 = 0;
|
||||
setPowerOutput(FALSE);
|
||||
disChargOverLoad = TRUE;
|
||||
disChargOverLoad = TRUE;
|
||||
insertEventsOrderRecord(thirdStageProtection);
|
||||
}
|
||||
|
||||
|
||||
|
@ -60,8 +62,10 @@ void setDisChargOverLoad(void)
|
|||
/* 过载时间过长关闭输出 */
|
||||
if (num2 >= g_cfgParameter.secondStageProtectionDelay) {
|
||||
num2 = 0;
|
||||
// debug_printf("in secondStageProtection \n");
|
||||
setPowerOutput(FALSE);
|
||||
disChargOverLoad = TRUE;
|
||||
insertEventsOrderRecord(secondStageProtection);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,10 +95,14 @@ void setSoftShortCircuit(uint16_t disChargCurrAdcNum)
|
|||
|
||||
/* 20uS内都短路则关闭输出 */
|
||||
if (num >= g_cfgParameter.firstStageProtectionDelay) {
|
||||
num = 0;
|
||||
setPowerOutput(FALSE);
|
||||
shortCircuitFlag = TRUE;
|
||||
shortCircuit++;
|
||||
startSoftShortCircuitProtection();
|
||||
// shortCircuitFlag = TRUE;
|
||||
// shortCircuit++;
|
||||
// debug_printf("in firstStageProtection %d \n", g_cfgParameter.firstStageProtectionValue);
|
||||
// debug_printf("in firstStageProtection %d \n", disChargCurrAdcNum);
|
||||
insertEventsOrderRecord(firstStageProtection);
|
||||
// startSoftShortCircuitProtection();
|
||||
}
|
||||
}
|
||||
void setSoftShortCircuit1(void)
|
||||
|
@ -259,11 +267,16 @@ BOOL getExcessiveLoadFlag(void)
|
|||
*/
|
||||
void setPowerOutput(BOOL state)
|
||||
{
|
||||
// static volatile float temp_OUT_VOLT_IN;
|
||||
// static volatile float temp_PV_VOLT_OUT;
|
||||
// temp_PV_VOLT_OUT = get_PV_VOLT_OUT();
|
||||
// temp_OUT_VOLT_IN = get_OUT_VOLT_IN();
|
||||
if (state == TRUE) {
|
||||
if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) {
|
||||
// if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) {
|
||||
// if (temp_OUT_VOLT_IN < (temp_PV_VOLT_OUT - 0.5f)) {
|
||||
POW_FF_PCON_Open();
|
||||
POW_OUT_PCON_Open();
|
||||
}
|
||||
// }
|
||||
} else {
|
||||
POW_FF_PCON_Close();
|
||||
POW_OUT_PCON_Close();
|
||||
|
@ -286,12 +299,23 @@ void checkFFMOS_CON(void)
|
|||
// FFMOS_CON_Close();
|
||||
// }
|
||||
|
||||
if (getChargCurrent() > 5.0f && FALSE == FFMOS_CON_read()) {
|
||||
FFMOS_CON_Open();
|
||||
static uint8_t num = 100;
|
||||
if (getChargCurrent() > 8.0f && FALSE == FFMOS_CON_read()) {
|
||||
num--;
|
||||
if (!num) {
|
||||
FFMOS_CON_Open();
|
||||
}
|
||||
}
|
||||
else if (getChargCurrent() < 2.0f && TRUE == FFMOS_CON_read()) {
|
||||
// num--;
|
||||
// if (!num) {
|
||||
// FFMOS_CON_Close();
|
||||
// }
|
||||
FFMOS_CON_Close();
|
||||
}
|
||||
else {
|
||||
num = 100;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
|
@ -332,9 +356,10 @@ void setOverLoad(void)
|
|||
startExcessiveLoadProtection();
|
||||
}
|
||||
|
||||
/* 多次进入输出过载,关闭输出 */
|
||||
if (getExcessiveLoad() > 2) {
|
||||
/* 多次进入输出过载,关闭输出 */
|
||||
if (getExcessiveLoad() >= 2) {
|
||||
zeroExcessiveLoad();
|
||||
insertEventsOrderRecord(lowInputLoad);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -346,16 +371,21 @@ void setOverLoad(void)
|
|||
*/
|
||||
void lowInputLoadDetection(void)
|
||||
{
|
||||
static int num = 0;
|
||||
static int num = 0;
|
||||
|
||||
if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < g_cfgParameter.lowInputLoadDetectionVolt) {
|
||||
if (excessiveLoadInterruptFlag == TRUE
|
||||
&& getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt
|
||||
&& getDischargCurrent() < g_cfgParameter.thirdStageProtectionCurr) {
|
||||
num++;
|
||||
// setOverLoad();
|
||||
} else {
|
||||
num = 0;
|
||||
excessiveLoadInterruptFlag = FALSE;
|
||||
}
|
||||
|
||||
if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.lowInputLoadDetectionDelay) {
|
||||
|
||||
if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.inputPowerLowDetectionDelay) {
|
||||
num = 0;
|
||||
excessiveLoadInterruptFlag = FALSE;
|
||||
setOverLoad();
|
||||
}
|
||||
}
|
||||
|
@ -369,8 +399,17 @@ void lowInputLoadDetection(void)
|
|||
*/
|
||||
void judgeChargCurr(void)
|
||||
{
|
||||
static uint16_t num = 0;
|
||||
if (getChargCurrent() > g_cfgParameter.maxChargCurr) {
|
||||
num++;
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
if (num > 500) {
|
||||
num = 0;
|
||||
stopChargWork();
|
||||
insertEventsOrderRecord(overchargCurr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,7 +418,7 @@ void checkAbnormal(void)
|
|||
// checkTimeInit();
|
||||
/* 滤波 */
|
||||
adcCaptureFir();
|
||||
|
||||
|
||||
/* 转换 */
|
||||
setChargCurrent();
|
||||
setDischargCurrent();
|
||||
|
@ -388,12 +427,12 @@ void checkAbnormal(void)
|
|||
|
||||
/* 判断 */
|
||||
checkFFMOS_CON();
|
||||
setDisChargOverLoad();
|
||||
setDisChargOverLoad();
|
||||
setSoftShortCircuit1();
|
||||
lowInputLoadDetection();
|
||||
judgeChargCurr();
|
||||
|
||||
|
||||
|
||||
|
||||
// checkAbnormalTime = getCheckTime();
|
||||
}
|
||||
|
@ -430,23 +469,41 @@ void WORK_VOLT_Interrupt(void)
|
|||
void DSG_PROT_Interrupt(void)
|
||||
{
|
||||
setShortCircuit();
|
||||
setPowerOutput(FALSE);
|
||||
/* 第一次进入输出短路,启动短路任务 */
|
||||
if (getShortCircuit() == 1) {
|
||||
setShortCircuitFlag(TRUE);
|
||||
startShortCircuitProtection();
|
||||
}
|
||||
|
||||
/* 一定时间内第二次进入输出短路保护,关闭输出 */
|
||||
else if (getShortCircuit() >= 2) {
|
||||
stopShortCircuitProtection();
|
||||
setPowerOutput(FALSE);
|
||||
// setPowerOutput(FALSE);
|
||||
zeroShortCircuit();
|
||||
insertEventsOrderRecord(hardwareShortCircuitProtection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 反向充电短路中断,反向充电电流大于一定值
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
|
||||
void EXCHG_PROT_Interrupt(void)
|
||||
{
|
||||
setShortCircuit();
|
||||
setPowerOutput(FALSE);
|
||||
/* 第一次进入输出短路,启动短路任务 */
|
||||
if (getShortCircuit() == 1) {
|
||||
startEXCHGSCProtection();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* 一定时间内第二次进入输出短路保护,关闭输出 */
|
||||
else if (getShortCircuit() >= 2) {
|
||||
stopShortCircuitProtection();
|
||||
insertEventsOrderRecord(hardwareInputProtection);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "comm_types.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "task.h"
|
||||
#include "SOE.h"
|
||||
|
||||
|
||||
static BOOL stopChargConditions(void);
|
||||
|
@ -22,10 +23,24 @@ static void chargControlMode(void);
|
|||
static void BatteryChargControl(void);
|
||||
static void noBatteryChargControl(void);
|
||||
|
||||
static void setPIControlStep(float *PI_step);
|
||||
|
||||
|
||||
static BOOL chargControlFlag = FALSE;
|
||||
// static BOOL getChargControlFlag(void);
|
||||
void setChargControlFlag(BOOL state);
|
||||
|
||||
void setPIControlStep(float *PI_step)
|
||||
{
|
||||
if (*PI_step > PI_CONTROL_MAX) {
|
||||
*PI_step = PI_CONTROL_MAX;
|
||||
}
|
||||
|
||||
else if (*PI_step < PI_CONTROL_MIN) {
|
||||
*PI_step = PI_CONTROL_MIN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 恒定输入电压
|
||||
* @param InVoltage 需要控制到的输入电压
|
||||
|
@ -45,6 +60,7 @@ void mppt_constantVoltage(float InVoltage)
|
|||
error = getSolarInCircuitVoltage() - InVoltage;
|
||||
stepPwm = kp * error + ki * getSolarInCircuitVoltage();
|
||||
|
||||
setPIControlStep(&stepPwm);
|
||||
|
||||
setDutyRatio((getDutyRatio() + stepPwm));
|
||||
// if (getMosTemperState() == mosTemperEnd) {
|
||||
|
@ -71,7 +87,8 @@ void mppt_constantVoltageNoBatteryO(float OutVoltage)
|
|||
outVolt = getOutputVoltage();
|
||||
error = OutVoltage - outVolt;
|
||||
stepPwm = kp * error + ki * outVolt;
|
||||
|
||||
setPIControlStep(&stepPwm);
|
||||
|
||||
setDutyRatio((getDutyRatio() + stepPwm));
|
||||
}
|
||||
|
||||
|
@ -86,7 +103,7 @@ void mppt_constantVoltageO(float OutVoltage)
|
|||
// static float lastVolt = 0;
|
||||
// static float lastStepPwm = 0;
|
||||
static float lastDutyRatio = 0;
|
||||
static float kp = 0.005;
|
||||
static float kp = 0.002;
|
||||
static float ki = 0.00001;
|
||||
static float outVolt;
|
||||
static float error;
|
||||
|
@ -95,6 +112,7 @@ void mppt_constantVoltageO(float OutVoltage)
|
|||
outVolt = getOutputVoltage();
|
||||
error = OutVoltage - outVolt;
|
||||
StepPwm = kp * error + ki * outVolt;
|
||||
setPIControlStep(&StepPwm);
|
||||
|
||||
/* 当有电池时,输出电压的曲线是先上升后下降 */
|
||||
if (lastDutyRatio >= getDutyRatio()) {
|
||||
|
@ -317,20 +335,34 @@ void mppt_readJust(void)
|
|||
// return;
|
||||
|
||||
/* 调节电压,两个电压步调节 */
|
||||
static float stepV1 = 0.2;
|
||||
static float stepV2 = 0.05;
|
||||
static float Power = 0;
|
||||
static float totalPower = 0;
|
||||
static float powerData[50] = {0};
|
||||
static uint8_t powerIndex = 0;
|
||||
// static float totalPower = 0;
|
||||
// static float powerData[50] = {0};
|
||||
// static uint8_t powerIndex = 0;
|
||||
|
||||
/* 获取50次的平均值 */
|
||||
totalPower -= powerData[powerIndex];
|
||||
powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
|
||||
totalPower += powerData[powerIndex];
|
||||
powerIndex++;
|
||||
if (powerIndex >= 50) {
|
||||
powerIndex = 0;
|
||||
static float totalChargeCurr = 0;
|
||||
static float chargeCurrData[50] = {0};
|
||||
static uint8_t chargeCurrIndex = 0;
|
||||
|
||||
/* 获取50次值的和 */
|
||||
totalChargeCurr -= chargeCurrData[chargeCurrIndex];
|
||||
chargeCurrData[chargeCurrIndex] = getChargCurrent();
|
||||
totalChargeCurr += chargeCurrData[chargeCurrIndex];
|
||||
chargeCurrIndex++;
|
||||
if (chargeCurrIndex >= 50) {
|
||||
chargeCurrIndex = 0;
|
||||
}
|
||||
|
||||
// totalPower -= powerData[powerIndex];
|
||||
// powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
|
||||
// totalPower += powerData[powerIndex];
|
||||
// powerIndex++;
|
||||
// if (powerIndex >= 50) {
|
||||
// powerIndex = 0;
|
||||
// }
|
||||
|
||||
static float lPower = 0;
|
||||
static float lLPower = 0;
|
||||
// static float lLLPower = 0;
|
||||
|
@ -339,9 +371,6 @@ void mppt_readJust(void)
|
|||
// static float kp = 0.005;
|
||||
// static float ki = 0.00001;
|
||||
|
||||
static float stepV1 = 0.2;
|
||||
static float stepV2 = 0.1;
|
||||
|
||||
static uint8_t flag1 = 0; //表明上次运算是加还是减
|
||||
|
||||
/* 延时一段时间才判断 */
|
||||
|
@ -360,13 +389,15 @@ void mppt_readJust(void)
|
|||
return;
|
||||
}
|
||||
|
||||
if (getMosTemperState() == mosTemperEnd) {
|
||||
SolarInCircuitV = 16;
|
||||
if (getMosTemperState() == mosTemperReduce) {
|
||||
SolarInCircuitV = 20;
|
||||
}
|
||||
|
||||
|
||||
flag = 0;
|
||||
Power = totalPower / 50.0f;
|
||||
// Power = totalPower / 30.0f;
|
||||
// Power = totalPower;
|
||||
Power = totalChargeCurr * getOutputVoltage();
|
||||
|
||||
static float powerT = 0;
|
||||
powerT = Power - lPower;
|
||||
|
@ -374,10 +405,89 @@ void mppt_readJust(void)
|
|||
powerT = -powerT;
|
||||
}
|
||||
|
||||
/* 滞环值 */
|
||||
float hysteresisValue1;
|
||||
float hysteresisValue2;
|
||||
/* 一段时间内电流都很小则固定电压输出 */
|
||||
static uint8_t currMinFlag = 0;
|
||||
static uint8_t currMinFlag1 = 0;
|
||||
|
||||
// if (getChargCurrent() < 0.8f) {
|
||||
if (totalChargeCurr < 120) {
|
||||
// hysteresisValue1 = getChargCurrent() * 1.7f;
|
||||
// hysteresisValue2 = getChargCurrent() * 12;
|
||||
currMinFlag++;
|
||||
if (currMinFlag == 8) {
|
||||
currMinFlag = 0;
|
||||
SolarInCircuitV = 18.0f;
|
||||
currMinFlag1 = 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// else if (getChargCurrent() < 3 && currMinFlag1) {
|
||||
else if (totalChargeCurr < 150 && currMinFlag1) {
|
||||
currMinFlag1 = 0;
|
||||
currMinFlag = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// else if (getChargCurrent() < 7) {
|
||||
else if (totalChargeCurr < 350) {
|
||||
currMinFlag1 = 0;
|
||||
currMinFlag = 0;
|
||||
// hysteresisValue1 = getChargCurrent() * 1.1f;
|
||||
// hysteresisValue2 = getChargCurrent() * 10;
|
||||
hysteresisValue1 = totalChargeCurr / 40.0f;
|
||||
hysteresisValue2 = totalChargeCurr / 4.0f;
|
||||
}
|
||||
|
||||
// else if (getChargCurrent() < 20) {
|
||||
else if (totalChargeCurr < 1000) {
|
||||
currMinFlag1 = 0;
|
||||
currMinFlag = 0;
|
||||
// hysteresisValue1 = getChargCurrent() * 0.7f;
|
||||
// hysteresisValue2 = getChargCurrent() * 7;
|
||||
hysteresisValue1 = totalChargeCurr / 60.0f;
|
||||
hysteresisValue2 = totalChargeCurr / 6.0f;
|
||||
}
|
||||
|
||||
// else if (getChargCurrent() < 25) {
|
||||
else if (totalChargeCurr < 1250) {
|
||||
currMinFlag1 = 0;
|
||||
currMinFlag = 0;
|
||||
// hysteresisValue1 = getChargCurrent() * 0.5f;
|
||||
// hysteresisValue2 = getChargCurrent() * 5;
|
||||
hysteresisValue1 = totalChargeCurr / 90.0f;
|
||||
hysteresisValue2 = totalChargeCurr / 9.0f;
|
||||
}
|
||||
|
||||
else {
|
||||
currMinFlag1 = 0;
|
||||
currMinFlag = 0;
|
||||
// hysteresisValue1 = getChargCurrent() * 0.3f;
|
||||
// hysteresisValue2 = getChargCurrent() * 3;
|
||||
hysteresisValue1 = totalChargeCurr / 140.0f;
|
||||
hysteresisValue2 = totalChargeCurr / 14.0f;
|
||||
}
|
||||
|
||||
// else {
|
||||
// currMinFlag1 = 0;
|
||||
// currMinFlag = 0;
|
||||
// hysteresisValue1 = 120;
|
||||
// hysteresisValue2 = 100;
|
||||
// }
|
||||
|
||||
|
||||
static uint8_t numFlag = 0;
|
||||
// if ((lPower + 0.8f < Power) && (lLPower + 0.8f < Power) && (lLLPower + 0.8f < Power)) {
|
||||
if ((lPower + 0.1f < Power) && (lLPower + 0.1f < Power)) {
|
||||
// if ((lPower + 0.1f < Power) && (lLPower + 0.1f < Power)) {
|
||||
|
||||
if ((lPower + hysteresisValue1 < Power) && (lLPower + hysteresisValue1 < Power)) {
|
||||
numFlag = 0;
|
||||
// if ((lPower + 0.3f < Power)) {
|
||||
if (powerT > 5) {
|
||||
if (powerT > hysteresisValue2) {
|
||||
if (flag1) {
|
||||
SolarInCircuitV += stepV1;
|
||||
flag1 = 1;
|
||||
|
@ -395,9 +505,11 @@ void mppt_readJust(void)
|
|||
}
|
||||
}
|
||||
// } else if ((lPower - 0.8f > Power) && (lLPower - 0.8f > Power) && (lLLPower - 0.8f > Power)) {
|
||||
} else if ((lPower - 0.1f > Power) && (lLPower - 0.1f > Power)) {
|
||||
} else if ((lPower - hysteresisValue1 > Power) && (lLPower - hysteresisValue1 > Power)) {
|
||||
// } else if ((lPower - 0.3f > Power)) {
|
||||
if (powerT > 5) {
|
||||
numFlag = 0;
|
||||
if (powerT > hysteresisValue2) {
|
||||
numFlag = 0;
|
||||
if (flag1) {
|
||||
SolarInCircuitV -= stepV1;
|
||||
flag1 = 0;
|
||||
|
@ -414,11 +526,30 @@ void mppt_readJust(void)
|
|||
flag1 = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
numFlag++;
|
||||
}
|
||||
|
||||
if (SolarInCircuitV > 20.0f) {
|
||||
SolarInCircuitV = 20.0f;
|
||||
/* 一段时间内都未调节 */
|
||||
if (numFlag == 10) {
|
||||
if (Power < 300) {
|
||||
SolarInCircuitV = 17.0f;
|
||||
}
|
||||
else if (flag1) {
|
||||
SolarInCircuitV -= stepV2;
|
||||
flag1 = 0;
|
||||
}
|
||||
else {
|
||||
SolarInCircuitV += stepV2;
|
||||
flag1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (SolarInCircuitV > 19.0f) {
|
||||
SolarInCircuitV = 19.0f;
|
||||
}
|
||||
|
||||
else if (SolarInCircuitV < 16.0f) {
|
||||
SolarInCircuitV = 16.0f;
|
||||
}
|
||||
|
@ -440,6 +571,7 @@ void endChargWork(void)
|
|||
setDutyRatioToZero();
|
||||
setMPPT_Mode(noWork);
|
||||
beginStartControlTask();
|
||||
EN_PWMOUT_Diseable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -453,6 +585,7 @@ void stopChargWork(void)
|
|||
setChargControlFlag(FALSE);
|
||||
setDutyRatioToZero();
|
||||
setMPPT_Mode(noWork);
|
||||
EN_PWMOUT_Diseable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -464,6 +597,7 @@ void stopChargWork(void)
|
|||
void beginChargWork(void)
|
||||
{
|
||||
beginStartControlTask();
|
||||
EN_PWMOUT_Eable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -475,6 +609,7 @@ void beginChargWork(void)
|
|||
void startChargWork(void)
|
||||
{
|
||||
beginSoftStartTask();
|
||||
EN_PWMOUT_Eable();
|
||||
}
|
||||
|
||||
|
||||
|
@ -487,8 +622,36 @@ void startChargWork(void)
|
|||
*/
|
||||
BOOL stopChargConditions(void)
|
||||
{
|
||||
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOpenCircuitV
|
||||
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOutputCircuitV
|
||||
&& getChargCurrent() < 1) {
|
||||
// log_info("in stopChargConditions stopChargWork");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* 异常情况关闭充电 */
|
||||
static uint16_t flag = 0;
|
||||
if ((getSolarInCircuitVoltage() < (g_cfgParameter.stopSolarOutputCircuitV + 1)
|
||||
|| getSolarInCircuitVoltage() > 18.5f)
|
||||
&& getChargCurrent() < 0.1f
|
||||
&& getMPPT_Mode() == MPPT) {
|
||||
// return TRUE;
|
||||
flag++;
|
||||
}
|
||||
|
||||
// if ((getSolarInCircuitVoltage() < 17.8f
|
||||
// || getSolarInCircuitVoltage() > 20)
|
||||
// && getChargCurrent() < 0.1f
|
||||
// && getMPPT_Mode() == MPPT) {
|
||||
// // return TRUE;
|
||||
// flag++;
|
||||
// }
|
||||
// else {
|
||||
// flag = 0;
|
||||
// }
|
||||
|
||||
if (flag > 20000) {
|
||||
flag = 0;
|
||||
insertEventsOrderRecord(abnormalControl);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -521,7 +684,7 @@ BOOL floatChargConditions(void)
|
|||
BOOL mpptChargConditions(void)
|
||||
{
|
||||
if (((g_cfgParameter.constantVoltageChargeV - 0.2f) > getBatteryVoltage())
|
||||
&& (getChargCurrent() > 0.1f)) {
|
||||
&& (getChargCurrent() > 0.05f)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -600,7 +763,7 @@ void judgeYNBattery(void)
|
|||
*/
|
||||
void noBatteryChargControl(void)
|
||||
{
|
||||
mppt_constantVoltageNoBatteryO(g_cfgParameter.FloatV);
|
||||
mppt_constantVoltageNoBatteryO(g_cfgParameter.FloatChargeV);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -633,7 +796,7 @@ void constantVoltageCharge(void)
|
|||
*/
|
||||
void floatCharge(void)
|
||||
{
|
||||
mppt_constantVoltageO(g_cfgParameter.FloatV);
|
||||
mppt_constantVoltageO(g_cfgParameter.FloatChargeV);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -648,7 +811,8 @@ void BatteryChargControl(void)
|
|||
|
||||
case MPPT:
|
||||
mpptCharge();
|
||||
// mppt_constantVoltage(17.0f);
|
||||
// mppt_constantVoltage(17.5f);
|
||||
// setDutyRatio(0.1f);
|
||||
break;
|
||||
|
||||
case constantVoltage:
|
||||
|
@ -661,7 +825,8 @@ void BatteryChargControl(void)
|
|||
|
||||
default:
|
||||
setMPPT_Mode(noWork);
|
||||
stopChargWork();
|
||||
// stopChargWork();
|
||||
endChargWork();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -682,12 +847,15 @@ void setChargControlFlag(BOOL state)
|
|||
{
|
||||
if (state == TRUE || state == FALSE) {
|
||||
chargControlFlag = state;
|
||||
// debug_printf("chargControlFlag : %d", state);
|
||||
}
|
||||
|
||||
if (state == TRUE) {
|
||||
chargRunLed(runLedChargMode);
|
||||
// debug_printf("setChargControlFlag is true");
|
||||
} else if (state == FALSE) {
|
||||
chargRunLed(runLedOtherMode);
|
||||
// debug_printf("setChargControlFlag is false");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -718,6 +886,7 @@ void bl_chargControl(void)
|
|||
BatteryChargControl();
|
||||
} else {
|
||||
noBatteryChargControl();
|
||||
}
|
||||
}
|
||||
// noBatteryChargControl();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "bl_comm.h"
|
||||
#include "uart_dev.h"
|
||||
#include "interruptSend.h"
|
||||
#include "SOE.h"
|
||||
|
||||
uint8_t rs485_buff[buffLen]={0x00};
|
||||
|
||||
|
@ -65,7 +66,7 @@ void gw485_TxIt(void)
|
|||
/**
|
||||
* @brief bat485串口中断发送回调函数
|
||||
* @param
|
||||
* @retval
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void bat485_TxIt(void)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,422 +0,0 @@
|
|||
|
||||
#include "cfg_protocol.h"
|
||||
#include "uart_dev.h"
|
||||
#include "inFlash.h"
|
||||
#include "parameter.h"
|
||||
#include "string.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "pDebug.h"
|
||||
|
||||
#define cfgBuffLen 200
|
||||
static uint8_t configBuff[cfgBuffLen];
|
||||
static uint8_t cfigLen = 0;
|
||||
|
||||
/* 配置文件中的部分数据放大倍数 */
|
||||
#define enlargeScale 100
|
||||
|
||||
/**
|
||||
* @brief 向配置文件buff中存入一个数据
|
||||
* @param c 数据
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void inConfigBuff(uint8_t c)
|
||||
{
|
||||
if (cfigLen < cfgBuffLen) {
|
||||
configBuff[cfigLen] = c;
|
||||
cfigLen++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 向配置文件buff中丢掉一个数据
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void outConfigBuff(void)
|
||||
{
|
||||
if (cfigLen > 0) {
|
||||
cfigLen--;
|
||||
memcpy(configBuff, configBuff + 1, cfigLen);
|
||||
// memcpy(configBuff, configBuff + 1, sizeof(configBuff) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief modbus的crc校验
|
||||
* @param *arr_buff 需要校验的数据
|
||||
* len 数据长度
|
||||
* @retval crc 校验的结果
|
||||
*/
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
uint16_t i, j;
|
||||
for (j = 0; j < len; ++j) {
|
||||
crc = crc ^ (*arr_buff++);
|
||||
for (i = 0; i < 8; ++i) {
|
||||
if ((crc&0x0001) > 0) {
|
||||
crc = crc >> 1;
|
||||
crc = crc ^ 0xa001;
|
||||
}
|
||||
else {
|
||||
crc = crc >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空配置文件buff
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void zeroConfigBuff(void)
|
||||
{
|
||||
cfigLen = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 判断接收到的配置文件数据是否正确,正确的话存入flash中
|
||||
* @param None
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
void read_and_process_config_data(void)
|
||||
{
|
||||
static config_info save_configInfo = {0};
|
||||
recv_config_info *pack = (recv_config_info *)configBuff;
|
||||
while (cfigLen >= RECV_CONFIG_INFO) {
|
||||
/* 判断起始标志是否正确 */
|
||||
// debug_printf(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
|
||||
if (pack->start_Flag[0] != g_cfgParameter.startFlagSL[0]
|
||||
|| pack->start_Flag[1] != g_cfgParameter.startFlagSL[1]) {
|
||||
debug(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// /* 判断接入节点类型是否正确 */
|
||||
// save_configInfo.Access_Node_Type = (uint16_t)pack->Access_Node_Type[0] << 8
|
||||
// | (uint16_t)pack->Access_Node_Type[1];
|
||||
// if (save_configInfo.Access_Node_Type != POWERBOX) {
|
||||
// // debug(" Access_Node_Type : 0x%x \n", save_configInfo.Access_Node_Type);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
// /* 判断通信方式是否正确 */
|
||||
// save_configInfo.Communication_Methods = (uint16_t)pack->Communication_Methods[0] << 8
|
||||
// | (uint16_t)pack->Communication_Methods[1];
|
||||
// // if (temp_u16 != RS485 || temp_u16 != RJ45) {
|
||||
// if (save_configInfo.Communication_Methods != RS485) {
|
||||
// debug(" Communication_Methods : 0x%x \n", save_configInfo.Communication_Methods);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
/* 判断波特率是否正确 */
|
||||
save_configInfo.gw485_Baud = (uint32_t)pack->gw485_Baud[0] << 24
|
||||
| (uint32_t)pack->gw485_Baud[1] << 16
|
||||
| (uint32_t)pack->gw485_Baud[2] << 8
|
||||
| (uint32_t)pack->gw485_Baud[3];
|
||||
// debug(" gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud);
|
||||
if (save_configInfo.gw485_Baud != 9600
|
||||
&& save_configInfo.gw485_Baud != 115200) {
|
||||
debug(" gw485_Baud : %d\n", save_configInfo.gw485_Baud);
|
||||
goto err;
|
||||
}
|
||||
|
||||
save_configInfo.bat485_Baud = (uint32_t)pack->bat485_Baud[0] << 24
|
||||
| (uint32_t)pack->bat485_Baud[1] << 16
|
||||
| (uint32_t)pack->bat485_Baud[2] << 8
|
||||
| (uint32_t)pack->bat485_Baud[3];
|
||||
if (save_configInfo.bat485_Baud != 9600
|
||||
&& save_configInfo.bat485_Baud!= 115200
|
||||
&& save_configInfo.bat485_Baud!= 0) {
|
||||
debug(" bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断汇源协议类型是否正确 */
|
||||
if (pack->protocolType != 0x01 && pack->protocolType != 0x02) {
|
||||
debug(" protocolType : 0x%x \n", pack->protocolType);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断通信协议类型是否正确 */
|
||||
if (pack->CommunicationProtocolType != 0x00
|
||||
&& pack->CommunicationProtocolType != 0x01) {
|
||||
debug(" CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
/* 判断电源盒类型是否正确 */
|
||||
if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) {
|
||||
debug(" onlyPower : 0x%x \n", pack->onlyPower);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断恒压充电阈值是否正确 */
|
||||
save_configInfo.constantVoltageV =
|
||||
(float)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.constantVoltageV < 14.4f && save_configInfo.constantVoltageV > 13.5f)
|
||||
|| save_configInfo.constantVoltageV == 0)) {
|
||||
debug(" constantVoltageV : %f \n", save_configInfo.constantVoltageV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断浮充充电阈值是否正确 */
|
||||
save_configInfo.floatI = (float)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale;
|
||||
if (save_configInfo.floatI > 0.2f || save_configInfo.floatI < 0) {
|
||||
debug(" floatI : %f \n", save_configInfo.floatI);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断太阳能板开路启动电压是否正确 */
|
||||
save_configInfo.startSolarOpenCircuitV =
|
||||
(float)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.startSolarOpenCircuitV < 24 && save_configInfo.startSolarOpenCircuitV > 14)
|
||||
|| save_configInfo.startSolarOpenCircuitV == 0)) {
|
||||
debug(" startSolarOpenCircuitV : %f \n", save_configInfo.startSolarOpenCircuitV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断太阳能板关闭电压是否正确 */
|
||||
save_configInfo.stopSolarOpenCircuitV =
|
||||
(float)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.stopSolarOpenCircuitV < 17 && save_configInfo.stopSolarOpenCircuitV > 13)
|
||||
|| save_configInfo.stopSolarOpenCircuitV == 0)) {
|
||||
debug(" stopSolarOpenCircuitV : %f \n", save_configInfo.stopSolarOpenCircuitV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断恒压充电时的输出电压是否正确 */
|
||||
save_configInfo.constantVoltageChargeV =
|
||||
(float)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.constantVoltageChargeV < 14.6f && save_configInfo.constantVoltageChargeV > 14)
|
||||
|| save_configInfo.constantVoltageChargeV == 0)) {
|
||||
debug(" constantVoltageChargeV : %f \n", save_configInfo.constantVoltageChargeV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断浮充充电时的输出电压是否正确 */
|
||||
save_configInfo.FloatChargeV =
|
||||
(float)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.FloatChargeV < 14.4f && save_configInfo.FloatChargeV > 13.8f)
|
||||
|| save_configInfo.FloatChargeV == 0)) {
|
||||
debug(" FloatChargeV : %f \n", save_configInfo.FloatChargeV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管停止工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_stop =
|
||||
(float)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_stop < 50 && save_configInfo.HighSideMosTemperature_stop != 0) {
|
||||
debug(" HighSideMosTemperature_stop : %f \n", save_configInfo.HighSideMosTemperature_stop);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管降低工作功率工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_end =
|
||||
(float)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_end < 40 && save_configInfo.HighSideMosTemperature_end != 0) {
|
||||
debug(" HighSideMosTemperature_end : %f \n", save_configInfo.HighSideMosTemperature_end);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管完全恢复工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_start =
|
||||
(float)(pack->HighSideMosTemperature_start[0] << 8 | pack->HighSideMosTemperature_start[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_start > 70 && save_configInfo.HighSideMosTemperature_start != 0) {
|
||||
debug(" HighSideMosTemperature_start : %d \n", save_configInfo.HighSideMosTemperature_start);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// /* 判断启动任务中太阳能板开路电压检测间隔时间是否正确 */
|
||||
// save_configInfo.checkSolarOpenCircuitVTime =
|
||||
// pack->checkSolarOpenCircuitVTime[0] << 8 | pack->checkSolarOpenCircuitVTime[1];
|
||||
// if (save_configInfo.checkSolarOpenCircuitVTime > 1800 || save_configInfo.checkSolarOpenCircuitVTime < 5) {
|
||||
// debug(" checkSolarOpenCircuitVTime : %d \n", save_configInfo.checkSolarOpenCircuitVTime);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
// /* 判断传感器运行再次注册的间隔是否正确 */
|
||||
// save_configInfo.sensorEnableBroadcastTime =
|
||||
// pack->sensorEnableBroadcastTime[0] << 8 | pack->sensorEnableBroadcastTime[1];
|
||||
// if (save_configInfo.sensorEnableBroadcastTime > 60 || save_configInfo.sensorEnableBroadcastTime < 10) {
|
||||
// debug(" sensorEnableBroadcastTime : %d \n", save_configInfo.sensorEnableBroadcastTime);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
/* 判断出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出的间隔是否正确 */
|
||||
save_configInfo.outputAgainFlagTime =
|
||||
pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1];
|
||||
if (!((save_configInfo.outputAgainFlagTime < 30 && save_configInfo.outputAgainFlagTime > 5)
|
||||
|| save_configInfo.outputAgainFlagTime == 0)) {
|
||||
debug(" outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出的间隔是否正确 */
|
||||
save_configInfo.excessiveLoadFlagTime =
|
||||
pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1];
|
||||
if (!((save_configInfo.excessiveLoadFlagTime < 90 && save_configInfo.excessiveLoadFlagTime > 20)
|
||||
|| save_configInfo.excessiveLoadFlagTime == 0)) {
|
||||
debug(" excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断出现过载过载保护后,在该间隔段时间后,再次尝试输出的间隔是否正确 */
|
||||
save_configInfo.eLAgainTime = pack->eLAgainTime[0] << 8 | pack->eLAgainTime[1];
|
||||
if (save_configInfo.eLAgainTime > 3000 || save_configInfo.eLAgainTime < 1000) {
|
||||
debug(" eLAgainTime : %d \n", save_configInfo.eLAgainTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* crc校验 */
|
||||
save_configInfo.crc = pack->crc[0] << 8 | pack->crc[1];
|
||||
if (save_configInfo.crc != checkModebusCrc(configBuff, RECV_CONFIG_INFO - 3)) {
|
||||
debug(" crc : %x%x \n", pack->crc[0], pack->crc[1]);
|
||||
debug(" checkModebusCrc : %x \n", checkModebusCrc(configBuff, RECV_CONFIG_INFO));
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
/* 结束标志 */
|
||||
if (pack->end_Flag != 0x16) {
|
||||
debug(" end_Flag : %x \n", pack->end_Flag);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// debug("address : 0x %x %x %x %x %x %x %x\n", pack->address[0]
|
||||
// , pack->address[1], pack->address[2], pack->address[3]
|
||||
// , pack->address[4], pack->address[5], pack->address[6]);
|
||||
config_info temp_configInfo;
|
||||
read_config_info(&temp_configInfo);
|
||||
|
||||
if (pack->address[0] != 0xFF
|
||||
|| pack->address[1] != 0xFF
|
||||
|| pack->address[2] != 0xFF
|
||||
|| pack->address[3] != 0xFF
|
||||
|| pack->address[4] != 0xFF
|
||||
|| pack->address[5] != 0xFF
|
||||
|| pack->address[6] != 0xFF) {
|
||||
save_configInfo.address[0] = pack->address[0];
|
||||
save_configInfo.address[1] = pack->address[1];
|
||||
save_configInfo.address[2] = pack->address[2];
|
||||
save_configInfo.address[3] = pack->address[3];
|
||||
save_configInfo.address[4] = pack->address[4];
|
||||
save_configInfo.address[5] = pack->address[5];
|
||||
save_configInfo.address[6] = pack->address[6];
|
||||
// debug("address : 0x %x %x %x %x %x %x %x\n", save_configInfo.address[0]
|
||||
// , save_configInfo.address[1], save_configInfo.address[2], save_configInfo.address[3]
|
||||
// , save_configInfo.address[4], save_configInfo.address[5], save_configInfo.address[6]);
|
||||
} else {
|
||||
save_configInfo.address[0] = temp_configInfo.address[0];
|
||||
save_configInfo.address[1] = temp_configInfo.address[1];
|
||||
save_configInfo.address[2] = temp_configInfo.address[2];
|
||||
save_configInfo.address[3] = temp_configInfo.address[3];
|
||||
save_configInfo.address[4] = temp_configInfo.address[4];
|
||||
save_configInfo.address[5] = temp_configInfo.address[5];
|
||||
save_configInfo.address[6] = temp_configInfo.address[6];
|
||||
}
|
||||
|
||||
if (pack->hardwareID[0] != 0xFF
|
||||
|| pack->hardwareID[1] != 0xFF
|
||||
|| pack->hardwareID[2] != 0xFF
|
||||
|| pack->hardwareID[3] != 0xFF
|
||||
|| pack->hardwareID[4] != 0xFF
|
||||
|| pack->hardwareID[5] != 0xFF) {
|
||||
save_configInfo.hardwareID[0] = pack->hardwareID[0];
|
||||
save_configInfo.hardwareID[1] = pack->hardwareID[1];
|
||||
save_configInfo.hardwareID[2] = pack->hardwareID[2];
|
||||
save_configInfo.hardwareID[3] = pack->hardwareID[3];
|
||||
save_configInfo.hardwareID[4] = pack->hardwareID[4];
|
||||
save_configInfo.hardwareID[5] = pack->hardwareID[5];
|
||||
} else {
|
||||
save_configInfo.hardwareID[0] = temp_configInfo.hardwareID[0];
|
||||
save_configInfo.hardwareID[1] = temp_configInfo.hardwareID[1];
|
||||
save_configInfo.hardwareID[2] = temp_configInfo.hardwareID[2];
|
||||
save_configInfo.hardwareID[3] = temp_configInfo.hardwareID[3];
|
||||
save_configInfo.hardwareID[4] = temp_configInfo.hardwareID[4];
|
||||
save_configInfo.hardwareID[5] = temp_configInfo.hardwareID[5];
|
||||
}
|
||||
|
||||
if (pack->communicationID[0] != 0xFF
|
||||
|| pack->communicationID[1] != 0xFF
|
||||
|| pack->communicationID[2] != 0xFF
|
||||
|| pack->communicationID[3] != 0xFF) {
|
||||
save_configInfo.communicationID[0] = pack->communicationID[0];
|
||||
save_configInfo.communicationID[1] = pack->communicationID[1];
|
||||
save_configInfo.communicationID[2] = pack->communicationID[2];
|
||||
save_configInfo.communicationID[3] = pack->communicationID[3];
|
||||
} else {
|
||||
save_configInfo.communicationID[0] = temp_configInfo.communicationID[0];
|
||||
save_configInfo.communicationID[1] = temp_configInfo.communicationID[1];
|
||||
save_configInfo.communicationID[2] = temp_configInfo.communicationID[2];
|
||||
save_configInfo.communicationID[3] = temp_configInfo.communicationID[3];
|
||||
}
|
||||
|
||||
save_configInfo.protocolType = pack->protocolType;
|
||||
|
||||
save_configInfo.CommunicationProtocolType = pack->CommunicationProtocolType;
|
||||
|
||||
save_configInfo.onlyPower = pack->onlyPower;
|
||||
|
||||
|
||||
save_configInfo.crc = checkModebusCrc((uint8_t *)&save_configInfo, CONFIG_INFO_SIZE - 2);
|
||||
// save_backups_config_info(&save_configInfo);
|
||||
// save_config_info(&save_configInfo);
|
||||
saveConfigInfo(&save_configInfo);
|
||||
|
||||
// memset(config_buff, 0, sizeof(config_buff));
|
||||
zeroConfigBuff();
|
||||
|
||||
// /* 返回更改配置文件成功 */
|
||||
// SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
|
||||
|
||||
// SUpdateProfile_pack.start_Flag[0] = g_otherParameter.startFlagSL[0];
|
||||
// SUpdateProfile_pack.start_Flag[1] = g_otherParameter.startFlagSL[1];
|
||||
|
||||
// SUpdateProfile_pack.address[0] = save_configInfo.address[0];
|
||||
// SUpdateProfile_pack.address[1] = save_configInfo.address[1];
|
||||
// SUpdateProfile_pack.address[2] = save_configInfo.address[2];
|
||||
// SUpdateProfile_pack.address[3] = save_configInfo.address[3];
|
||||
// SUpdateProfile_pack.address[4] = save_configInfo.address[4];
|
||||
// SUpdateProfile_pack.address[5] = save_configInfo.address[5];
|
||||
// SUpdateProfile_pack.address[6] = save_configInfo.address[6];
|
||||
|
||||
// SUpdateProfile_pack.function_Code = SL_Function_Code_Update_Profile;
|
||||
|
||||
// SUpdateProfile_pack.state = 0x01;
|
||||
|
||||
// uint16_t crc = CheckFuncSL((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
|
||||
// SUpdateProfile_pack.check_Bit_H = crc >> 8;
|
||||
// SUpdateProfile_pack.check_Bit_L = crc;
|
||||
|
||||
// SUpdateProfile_pack.end_Flag = g_otherParameter.endFlagSL;
|
||||
|
||||
// while (1) {
|
||||
// if (!Check_485_bus_busy(g_gw485_uart4_handle)) {
|
||||
// uart_dev_write(g_gw485_uart4_handle, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE);
|
||||
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
// break;
|
||||
// }
|
||||
// Delay_Ms(randomDelay());
|
||||
// }
|
||||
uart_dev_write(g_gw485_uart2_handle, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
HAL_Delay(1000);
|
||||
|
||||
/* 复位 */
|
||||
NVIC_SystemReset();
|
||||
|
||||
err:
|
||||
// config_buff_pos--;
|
||||
// memcpy(config_buff, config_buff + 1, sizeof(config_buff) - 1);
|
||||
outConfigBuff();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,7 @@
|
|||
#include "inFlash.h"
|
||||
#include "parameter.h"
|
||||
#include "pDebug.h"
|
||||
#include "cfg_protocol.h"
|
||||
//#include "cfg_protocol.h"
|
||||
#include "configParameter.h"
|
||||
|
||||
static void save_config_info(config_info *save_config_info);
|
||||
|
@ -53,27 +53,88 @@ void saveConfigInfo(config_info *configInfo)
|
|||
// save_backups_config_info(config_info);
|
||||
}
|
||||
|
||||
void cfgTest(void)
|
||||
{
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// config_info temp_configInfo;
|
||||
// read_config_info(&temp_configInfo);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// saveConfigInfo(&temp_configInfo);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// read_config_info(&temp_configInfo);
|
||||
// saveConfigInfo(&temp_configInfo);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// float tempF;
|
||||
// readtotalElectricityConsumption(&tempF);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// savetotalElectricityConsumption(&tempF);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// readtotalElectricityConsumption(&tempF);
|
||||
// savetotalElectricityConsumption(&tempF);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// timeInfo tempT;
|
||||
// readTime(&tempT);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// saveTime(&tempT);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// readTime(&tempT);
|
||||
// saveTime(&tempT);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
uint32_t tempTime = HAL_GetTick();
|
||||
uint8_t tempBuf[30];
|
||||
write_Flash((uint8_t *)"hello 12345\n", 2048, sizeof("hello 12345\n"));
|
||||
log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
tempTime = HAL_GetTick();
|
||||
read_Flash(tempBuf, 2048, sizeof("hello 12345\n"));
|
||||
log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
log_info("%s\n", tempBuf);
|
||||
tempTime = HAL_GetTick();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
read_Flash(tempBuf, 2048, sizeof("hello world\n"));
|
||||
write_Flash((uint8_t *)"hello world\n", 2048, sizeof("hello world\n"));
|
||||
}
|
||||
log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 检测flash中是否有配置文件或者文件是否有损坏,若两处flash中都损坏则使用默认文件
|
||||
* @param config_info 读取的配置信息
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
static void readFlashContent(config_info *configInfo)
|
||||
void readFlashContent(config_info *configInfo)
|
||||
{
|
||||
read_config_info(configInfo);
|
||||
/* 配置文件正确就返回 */
|
||||
// static volatile uint16_t tempCrc1, tempCrc2;
|
||||
// static volatile config_info *tempConfigInfo1;
|
||||
// tempConfigInfo1 = configInfo;
|
||||
// tempCrc1 = configInfo->crc;
|
||||
// tempCrc2 = checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2);
|
||||
// if (tempCrc1 == tempCrc2) {
|
||||
// return;
|
||||
// }
|
||||
if (configInfo->crc == checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2)) {
|
||||
return;
|
||||
}
|
||||
read_config_info(configInfo);
|
||||
/* 配置文件正确就返回 */
|
||||
// static volatile uint16_t tempCrc1, tempCrc2;
|
||||
// tempCrc1 = configInfo->crc;
|
||||
// tempCrc2 = checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2);
|
||||
// if (tempCrc1 == tempCrc2) {
|
||||
// return;
|
||||
// }
|
||||
if (configInfo->crc == checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// /* 更深处的配置文件正确就返回 */
|
||||
// read_backups_config_info(config_info);
|
||||
|
@ -83,48 +144,67 @@ static void readFlashContent(config_info *configInfo)
|
|||
// }
|
||||
|
||||
/* 配置文件错误使用默认配置 */
|
||||
configInfo->address[0] = 0x11;
|
||||
configInfo->address[1] = 0x11;
|
||||
configInfo->address[2] = 0x11;
|
||||
configInfo->address[3] = 0x11;
|
||||
configInfo->address[4] = 0x11;
|
||||
configInfo->address[5] = 0x11;
|
||||
configInfo->address[6] = 0x11;
|
||||
// config_info->Access_Node_Type = 0x01;
|
||||
// config_info->Communication_Methods = 0x02;
|
||||
configInfo->uniqueDeviceID[0] = 0x11;
|
||||
configInfo->uniqueDeviceID[1] = 0x11;
|
||||
configInfo->uniqueDeviceID[2] = 0x11;
|
||||
configInfo->uniqueDeviceID[3] = 0x11;
|
||||
configInfo->uniqueDeviceID[4] = 0x11;
|
||||
configInfo->uniqueDeviceID[5] = 0x11;
|
||||
configInfo->uniqueDeviceID[6] = 0x11;
|
||||
|
||||
configInfo->gw485_Baud = 115200;
|
||||
configInfo->bat485_Baud = 115200;
|
||||
|
||||
configInfo->hardwareID[0] = 0x48;
|
||||
configInfo->hardwareID[1] = 0x59;
|
||||
configInfo->hardwareID[2] = 0x30;
|
||||
configInfo->hardwareID[3] = 0x30;
|
||||
configInfo->hardwareID[4] = 0x30;
|
||||
configInfo->hardwareID[5] = 0x31;
|
||||
configInfo->communicationID[0] = 0x00;
|
||||
configInfo->communicationID[1] = 0x00;
|
||||
configInfo->communicationID[2] = 0x00;
|
||||
configInfo->communicationID[3] = 0x01;
|
||||
configInfo->protocolType = 0x01;
|
||||
|
||||
configInfo->CommunicationProtocolType = 0x01;
|
||||
configInfo->onlyPower = 0x01;
|
||||
configInfo->powerBoxType = 0xFF;
|
||||
|
||||
configInfo->constantVoltageV = 14;
|
||||
configInfo->floatI = 0.1f;
|
||||
configInfo->startSolarOpenCircuitV = 17;
|
||||
configInfo->stopSolarOpenCircuitV = 15;
|
||||
configInfo->stopSolarOutputCircuitV = 15;
|
||||
|
||||
configInfo->checkCanStartTime = 5;
|
||||
configInfo->shortCircuitJudgmentDelay = 10;
|
||||
configInfo->inputPowerLowJudgmentDelay = 30;
|
||||
configInfo->inputPowerLowAgainOutputDelay = 1800;
|
||||
|
||||
configInfo->firstStageProtectionDelay = 2;
|
||||
configInfo->firstStageProtectionCurr = 50;
|
||||
configInfo->secondStageProtectionDelay = 50000;
|
||||
configInfo->secondStageProtectionCurr = 35;
|
||||
configInfo->thirdStageProtectionDelay = 600000;
|
||||
configInfo->thirdStageProtectionCurr = 30;
|
||||
|
||||
configInfo->inputPowerLowDetectionDelay = 10;
|
||||
configInfo->inputPowerLowDetectionVolt = 10.0f;
|
||||
|
||||
configInfo->maxOpenSolarOutputCircuitV = 25;
|
||||
configInfo->maxChargCurr = 35;
|
||||
|
||||
configInfo->minCheckLoopImpedanceChargCurr = 5;
|
||||
|
||||
configInfo->stopPowerOutputTemperature = 100;
|
||||
configInfo->reducePowerOutputTemperature = 90;
|
||||
configInfo->fullPowerOutputTemperature = 50;
|
||||
|
||||
configInfo->constantVoltageChargeV = 14.4f;
|
||||
configInfo->FloatChargeV = 14.2f;
|
||||
configInfo->HighSideMosTemperature_stop = 100;
|
||||
configInfo->HighSideMosTemperature_end = 90;
|
||||
configInfo->HighSideMosTemperature_start = 50;
|
||||
configInfo->collectOpenCircuitVoltageTime = 1800;
|
||||
|
||||
configInfo->reverseChargProtectionCurr = 2;
|
||||
|
||||
// configInfo->firstStageProtectionCurr = firstStageProtectionCurrMacro;
|
||||
// configInfo->firstStageProtectionDelay = firstStageProtectionDelayMacro;
|
||||
// configInfo->firstStageProtectionValue = firstStageProtectionValueMacro;
|
||||
// configInfo->secondStageProtectionCurr = secondStageProtectionCurrMacro;
|
||||
// configInfo->secondStageProtectionDelay = secondStageProtectionDelayMacro;
|
||||
// configInfo->thirdStageProtectionCurr = thirdStageProtectionCurrMacro;
|
||||
// configInfo->thirdStageProtectionDelay = thirdStageProtectionDelayMacro;
|
||||
// configInfo->checkLoopImpedanceChargCurr = checkLoopImpedanceChargCurrMacro;
|
||||
// configInfo->lowInputLoadDetectionVolt = lowInputLoadDetectionVoltMacro;
|
||||
// configInfo->lowInputLoadDetectionDelay = lowInputLoadDetectionDelayMacro;
|
||||
// configInfo->maxChargCurr = maxChargCurrMacro;
|
||||
// configInfo->maxOpenSolarOpenCircuitV = maxOpenSolarOpenCircuitVMacro;
|
||||
|
||||
// configInfo->checkSolarOpenCircuitVTime = 10;
|
||||
// configInfo->sensorEnableBroadcastTime = 20;
|
||||
configInfo->outputAgainFlagTime = 10;
|
||||
configInfo->excessiveLoadFlagTime = 60;
|
||||
configInfo->eLAgainTime = 1800;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,99 +220,86 @@ void config_info_start(void)
|
|||
config_info temp_configInfo;
|
||||
readFlashContent(&temp_configInfo);
|
||||
|
||||
g_cfgParameter.constantVoltageV = temp_configInfo.constantVoltageV;
|
||||
g_cfgParameter.floatI = temp_configInfo.floatI;
|
||||
g_cfgParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
|
||||
g_cfgParameter.stopSolarOpenCircuitV = temp_configInfo.stopSolarOpenCircuitV;
|
||||
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
|
||||
g_cfgParameter.FloatV = temp_configInfo.FloatChargeV;
|
||||
g_cfgParameter.HighSideMosTemperature_stop = temp_configInfo.HighSideMosTemperature_stop;
|
||||
g_cfgParameter.HighSideMosTemperature_end = temp_configInfo.HighSideMosTemperature_end;
|
||||
g_cfgParameter.HighSideMosTemperature_start = temp_configInfo.HighSideMosTemperature_start;
|
||||
// g_cfgParameter.sensorEnableBroadcastTime = temp_configInfo.sensorEnableBroadcastTime;
|
||||
// g_cfgParameter.checkSolarOpenCircuitVTime = temp_configInfo.checkSolarOpenCircuitVTime;
|
||||
g_cfgParameter.outputAgainFlagTime = temp_configInfo.outputAgainFlagTime;
|
||||
g_cfgParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime;
|
||||
g_cfgParameter.eLAgainTime = temp_configInfo.eLAgainTime;
|
||||
g_cfgParameter.collectOpenCircuitVoltageTime= 3600;
|
||||
g_cfgParameter.address[0] = temp_configInfo.address[0];
|
||||
g_cfgParameter.address[1] = temp_configInfo.address[1];
|
||||
g_cfgParameter.address[2] = temp_configInfo.address[2];
|
||||
g_cfgParameter.address[3] = temp_configInfo.address[3];
|
||||
g_cfgParameter.address[4] = temp_configInfo.address[4];
|
||||
g_cfgParameter.address[5] = temp_configInfo.address[5];
|
||||
g_cfgParameter.address[6] = temp_configInfo.address[6];
|
||||
// g_cfgParameter.Access_Node_Type = temp_configInfo.Access_Node_Type;
|
||||
// g_cfgParameter.Communication_Methods = temp_configInfo.Communication_Methods;
|
||||
g_cfgParameter.hardwareID[0] = temp_configInfo.hardwareID[0];
|
||||
g_cfgParameter.hardwareID[1] = temp_configInfo.hardwareID[1];
|
||||
g_cfgParameter.hardwareID[2] = temp_configInfo.hardwareID[2];
|
||||
g_cfgParameter.hardwareID[3] = temp_configInfo.hardwareID[3];
|
||||
g_cfgParameter.hardwareID[4] = temp_configInfo.hardwareID[4];
|
||||
g_cfgParameter.hardwareID[5] = temp_configInfo.hardwareID[5];
|
||||
g_cfgParameter.communicationID[0] = temp_configInfo.communicationID[0];
|
||||
g_cfgParameter.communicationID[1] = temp_configInfo.communicationID[1];
|
||||
g_cfgParameter.communicationID[2] = temp_configInfo.communicationID[2];
|
||||
g_cfgParameter.communicationID[3] = temp_configInfo.communicationID[3];
|
||||
g_cfgParameter.protocolType = temp_configInfo.protocolType;
|
||||
// g_cfgParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType;
|
||||
g_cfgParameter.onlyPower = temp_configInfo.onlyPower;
|
||||
|
||||
g_cfgParameter.startFlagSL[0] = 'S';
|
||||
g_cfgParameter.startFlagSL[1] = 'L';
|
||||
g_cfgParameter.endFlagSL = 0x16;
|
||||
g_cfgParameter.startFlagHY = 0x68;
|
||||
g_cfgParameter.endFlagHY = 0x16;
|
||||
|
||||
// if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
|
||||
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
// } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
// if (g_cfgParameter.protocolType == 0x01) {
|
||||
// g_cfgParameter.gw485_Baud = 9600;
|
||||
// } else if (g_cfgParameter.protocolType == 0x02) {
|
||||
// g_cfgParameter.gw485_Baud = 115200;
|
||||
// }
|
||||
// }
|
||||
g_cfgParameter.gw485_Baud = 115200;
|
||||
g_cfgParameter.bat485_Baud = 115200;
|
||||
g_cfgParameter.Access_Node_Type = POWERBOX;
|
||||
g_cfgParameter.Communication_Methods = RS485;
|
||||
|
||||
float fTemp;
|
||||
readLoopImpedance(&fTemp);
|
||||
/* 读取的回路阻抗偏差过大则不使用 */
|
||||
if (fTemp > (float)0.005 && fTemp < (float)1) {
|
||||
g_cfgParameter.loopImpedance = fTemp;
|
||||
}
|
||||
else {
|
||||
g_cfgParameter.loopImpedance = 0;
|
||||
saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
}
|
||||
readtotalElectricityConsumption(&fTemp);
|
||||
totalElectricityConsumptionInt(fTemp);
|
||||
readtotalChargCapacity(&fTemp);
|
||||
totalChargCapacityInt(fTemp);
|
||||
g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
|
||||
g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
// g_cfgParameter.bat485_Baud = 115200;
|
||||
// static volatile uint32_t tempBatBaud;
|
||||
// tempBatBaud = temp_configInfo.bat485_Baud;
|
||||
|
||||
g_cfgParameter.uniqueDeviceID[0] = temp_configInfo.uniqueDeviceID[0];
|
||||
g_cfgParameter.uniqueDeviceID[1] = temp_configInfo.uniqueDeviceID[1];
|
||||
g_cfgParameter.uniqueDeviceID[2] = temp_configInfo.uniqueDeviceID[2];
|
||||
g_cfgParameter.uniqueDeviceID[3] = temp_configInfo.uniqueDeviceID[3];
|
||||
g_cfgParameter.uniqueDeviceID[4] = temp_configInfo.uniqueDeviceID[4];
|
||||
g_cfgParameter.uniqueDeviceID[5] = temp_configInfo.uniqueDeviceID[5];
|
||||
g_cfgParameter.uniqueDeviceID[6] = temp_configInfo.uniqueDeviceID[6];
|
||||
|
||||
timeInfo time;
|
||||
readTime(&time);
|
||||
setLastTime(time);
|
||||
g_cfgParameter.powerBoxType = temp_configInfo.powerBoxType;
|
||||
|
||||
g_cfgParameter.firstStageProtectionCurr = firstStageProtectionCurrMacro;
|
||||
g_cfgParameter.firstStageProtectionDelay = firstStageProtectionDelayMacro;
|
||||
g_cfgParameter.firstStageProtectionValue = firstStageProtectionValueMacro;
|
||||
g_cfgParameter.secondStageProtectionCurr = secondStageProtectionCurrMacro;
|
||||
g_cfgParameter.secondStageProtectionDelay = secondStageProtectionDelayMacro;
|
||||
g_cfgParameter.thirdStageProtectionCurr = thirdStageProtectionCurrMacro;
|
||||
g_cfgParameter.thirdStageProtectionDelay = thirdStageProtectionDelayMacro;
|
||||
g_cfgParameter.checkLoopImpedanceChargCurr = checkLoopImpedanceChargCurrMacro;
|
||||
g_cfgParameter.lowInputLoadDetectionVolt = lowInputLoadDetectionVoltMacro;
|
||||
g_cfgParameter.lowInputLoadDetectionDelay = lowInputLoadDetectionDelayMacro;
|
||||
g_cfgParameter.maxChargCurr = maxChargCurrMacro;
|
||||
g_cfgParameter.maxOpenSolarOpenCircuitV = maxOpenSolarOpenCircuitVMacro;
|
||||
g_cfgParameter.constantVoltageV = temp_configInfo.constantVoltageV;
|
||||
g_cfgParameter.floatI = temp_configInfo.floatI;
|
||||
|
||||
g_cfgParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
|
||||
g_cfgParameter.stopSolarOutputCircuitV = temp_configInfo.stopSolarOutputCircuitV;
|
||||
|
||||
g_cfgParameter.checkCanStartTime = temp_configInfo.checkCanStartTime;
|
||||
g_cfgParameter.shortCircuitJudgmentDelay = temp_configInfo.shortCircuitJudgmentDelay;
|
||||
g_cfgParameter.inputPowerLowJudgmentDelay = temp_configInfo.inputPowerLowJudgmentDelay;
|
||||
g_cfgParameter.inputPowerLowAgainOutputDelay= temp_configInfo.inputPowerLowAgainOutputDelay;
|
||||
|
||||
g_cfgParameter.firstStageProtectionCurr = temp_configInfo.firstStageProtectionCurr;
|
||||
g_cfgParameter.firstStageProtectionDelay = temp_configInfo.firstStageProtectionDelay;
|
||||
g_cfgParameter.secondStageProtectionCurr = temp_configInfo.secondStageProtectionCurr;
|
||||
g_cfgParameter.secondStageProtectionDelay = temp_configInfo.secondStageProtectionDelay;
|
||||
g_cfgParameter.thirdStageProtectionCurr = temp_configInfo.thirdStageProtectionCurr;
|
||||
g_cfgParameter.thirdStageProtectionDelay = temp_configInfo.thirdStageProtectionDelay;
|
||||
|
||||
g_cfgParameter.inputPowerLowDetectionDelay = temp_configInfo.inputPowerLowDetectionDelay;
|
||||
g_cfgParameter.inputPowerLowDetectionVolt = temp_configInfo.inputPowerLowDetectionVolt;
|
||||
|
||||
g_cfgParameter.maxOpenSolarOutputCircuitV = temp_configInfo.maxOpenSolarOutputCircuitV;
|
||||
g_cfgParameter.maxChargCurr = temp_configInfo.maxChargCurr;
|
||||
g_cfgParameter.minCheckLoopImpedanceChargCurr = temp_configInfo.minCheckLoopImpedanceChargCurr;
|
||||
g_cfgParameter.stopPowerOutputTemperature = temp_configInfo.stopPowerOutputTemperature;
|
||||
g_cfgParameter.reducePowerOutputTemperature = temp_configInfo.reducePowerOutputTemperature;
|
||||
g_cfgParameter.fullPowerOutputTemperature = temp_configInfo.fullPowerOutputTemperature;
|
||||
|
||||
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
|
||||
g_cfgParameter.FloatChargeV = temp_configInfo.FloatChargeV;
|
||||
g_cfgParameter.collectOpenCircuitVoltageTime= temp_configInfo.collectOpenCircuitVoltageTime;
|
||||
g_cfgParameter.reverseChargProtectionCurr = temp_configInfo.reverseChargProtectionCurr;
|
||||
|
||||
/* 读取的回路阻抗无效则回路阻抗设置为0 */
|
||||
float fTemp;
|
||||
// fTemp = 0.01f;
|
||||
// saveLoopImpedance(&fTemp);
|
||||
readLoopImpedance(&fTemp);
|
||||
// setLoopImpedance(fTemp);
|
||||
// if (getLoopImpedance() < 0 || getLoopImpedance() > 0.3f) {
|
||||
if (!setLoopImpedance(fTemp)) {
|
||||
setLoopImpedance(0);
|
||||
fTemp = getLoopImpedance();
|
||||
saveLoopImpedance(&fTemp);
|
||||
}
|
||||
|
||||
// readtotalElectricityConsumption(&fTemp);
|
||||
// totalElectricityConsumptionInt(fTemp);
|
||||
// readtotalChargCapacity(&fTemp);
|
||||
// totalChargCapacityInt(fTemp);
|
||||
// timeInfo time;
|
||||
// readTime(&time);
|
||||
// setLastTime(time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 保存回路阻抗在flash中
|
||||
* @param
|
||||
|
@ -305,5 +372,13 @@ void readTime(timeInfo *time)
|
|||
read_Flash((uint8_t *)time, time_SAVE_addr, sizeof(timeInfo));
|
||||
}
|
||||
|
||||
// void saveOtherInfo(other_info *otherInfo)
|
||||
// {
|
||||
// write_Flash((uint8_t *)otherInfo, LoopImpedance_SAVE_addr, sizeof(OTHER_INFO_SIZE));
|
||||
// }
|
||||
|
||||
// void readOtherInfo(other_info *otherInfo)
|
||||
// {
|
||||
// read_Flash((uint8_t *)otherInfo, LoopImpedance_SAVE_addr, sizeof(OTHER_INFO_SIZE));
|
||||
// }
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
#include "interruptSend.h"
|
||||
#include "bl_usart.h"
|
||||
|
||||
|
||||
#define RS485_MAX_PACK_DATA_LEN 60
|
||||
#define RS485_MAX_PACK_DATA_LEN 256
|
||||
|
||||
static uint8_t dataLocation1[RS485_MAX_PACK_DATA_LEN];
|
||||
static uint8_t dataLocation2[RS485_MAX_PACK_DATA_LEN];
|
||||
|
@ -55,7 +56,7 @@ typedef struct _uart_send_info {
|
|||
/* 恢复默认的对齐设置 */
|
||||
#pragma pack(pop)
|
||||
|
||||
static uart_send_info uart_send = {0};
|
||||
uart_send_info uart_send = {0};
|
||||
|
||||
/**
|
||||
* @brief 串口中断发送的初始化,通过空闲中断来判断总线空闲状态
|
||||
|
@ -162,6 +163,20 @@ void setBatState(void)
|
|||
*/
|
||||
void setSendOverStateGw(void)
|
||||
{
|
||||
/* 配置文件传输完成,复位 */
|
||||
if (uart_send.sendDataGw->data[9] = 0xD0
|
||||
&& uart_send.sendDataGw->data[12] == 0xAA) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
#ifdef HY_ChargeControlBox_PROTOCOL_ENABLE
|
||||
/* HY,复位指令 */
|
||||
if (uart_send.sendDataGw->data[11] = 0x66
|
||||
&& uart_send.sendDataGw->data[14] == 0xFF) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif
|
||||
|
||||
uart_send.sendOverStateGw = TRUE;
|
||||
uart_send.sendStateGw = FALSE;
|
||||
uart_send.sendDataGw->dataState = FALSE;
|
||||
|
@ -192,7 +207,7 @@ void setSendOverStateBat(void)
|
|||
uart_send.sendStateBat = FALSE;
|
||||
uart_send.sendDataBat->dataState = FALSE;
|
||||
uart_send.sendDataBat = NULL;
|
||||
uart_send.insertState++;
|
||||
uart_send.insertState++;
|
||||
|
||||
/* 插入指针指向为空时 */
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
|
@ -315,3 +330,46 @@ void uart_interruptSend(device_handle device, uint8_t buff[], uint8_t len)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 得到中断发送插入数据指针
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
uint8_t *getInsertData(void)
|
||||
{
|
||||
return uart_send.insertData->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将数据发送指针的内容发送
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void uart_insertDataSend(device_handle device, uint8_t len)
|
||||
{
|
||||
uart_send.insertData->Counter = 0;
|
||||
uart_send.insertData->dataLen = len;
|
||||
uart_send.insertData->device = device;
|
||||
|
||||
uart_send.insertData->dataState = TRUE;
|
||||
uart_send.insertState--;
|
||||
|
||||
/* 可插入数据大于0时,将插入指针指向空的储存位置,否则指向NULL */
|
||||
if (uart_send.insertState > 0) {
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
}
|
||||
else if (uart_send.data2.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data2;
|
||||
}
|
||||
else if (uart_send.data3.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data3;
|
||||
}
|
||||
} else {
|
||||
uart_send.insertData = NULL;
|
||||
}
|
||||
}
|
|
@ -4,16 +4,20 @@
|
|||
#include "FM_GPIO.h"
|
||||
#include "capture.h"
|
||||
#include "bl_chargControl.h"
|
||||
#include <math.h>
|
||||
#include "soc.h"
|
||||
|
||||
config_parameter g_cfgParameter = {0};
|
||||
static otherParameter g_otherParameter = {0};
|
||||
|
||||
static BOOL batteryState = FALSE; /* 有无电池(估计) */
|
||||
static float dutyRatio = 0; /* 占空比 */
|
||||
static uint8_t mosTemperState = mosTemperStart; /* mos管温度状态 */
|
||||
static uint8_t mosTemperState = mosTemperFull; /* mos管温度状态 */
|
||||
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
|
||||
static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */
|
||||
|
||||
static float exChargeCurr = 0;
|
||||
|
||||
/**
|
||||
* @brief 获取电池状态
|
||||
* @param
|
||||
|
@ -56,8 +60,8 @@ float getDutyRatio(void)
|
|||
*/
|
||||
void setDutyRatio(float DutyRatio)
|
||||
{
|
||||
if (DutyRatio > 0.95f) {
|
||||
dutyRatio = 0.95f;
|
||||
if (DutyRatio > 0.9f) {
|
||||
dutyRatio = 0.9f;
|
||||
}
|
||||
else if (DutyRatio < 0.05f) {
|
||||
dutyRatio = 0.05f;
|
||||
|
@ -76,9 +80,9 @@ void setDutyRatio(float DutyRatio)
|
|||
*/
|
||||
void setDutyRatioToZero(void)
|
||||
{
|
||||
EN_PWMOUT_Diseable();
|
||||
dutyRatio = 0;
|
||||
set_pwmDutyRatio(dutyRatio);
|
||||
EN_PWMOUT_Diseable();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,7 +102,7 @@ uint8_t getMosTemperState(void)
|
|||
*/
|
||||
void setMosTemperState(uint8_t state)
|
||||
{
|
||||
if (state == mosTemperStart || state == mosTemperEnd || state == mosTemperStop) {
|
||||
if (state == mosTemperFull || state == mosTemperReduce || state == mosTemperStop) {
|
||||
mosTemperState = state;
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +129,16 @@ void setCheckImpedanceState(void)
|
|||
checkImpedanceState = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 回路阻抗检测成功后设置回路阻抗检测状态
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void resetCheckImpedanceState(void)
|
||||
{
|
||||
checkImpedanceState = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置上次读取充放电量参数的时间
|
||||
|
@ -165,8 +179,10 @@ float getBatteryVoltage(void)
|
|||
*/
|
||||
void setBatteryVoltage(void)
|
||||
{
|
||||
g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
|
||||
- getChargBatteryCurrent() * g_cfgParameter.loopImpedance;
|
||||
// g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
|
||||
// - getChargBatteryCurrent() * getLoopImpedance();
|
||||
g_otherParameter.Battery_Voltage = getOutputVoltage()
|
||||
- getChargBatteryCurrent() * getLoopImpedance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -365,7 +381,7 @@ void setTotalChargCapacity(void)
|
|||
* @retval
|
||||
*/
|
||||
void totalChargCapacityInt(float totalPower)
|
||||
{
|
||||
{
|
||||
g_otherParameter.totalChargCapacity = totalPower;
|
||||
}
|
||||
|
||||
|
@ -386,7 +402,7 @@ float getSOC(void)
|
|||
*/
|
||||
void setSOC(void)
|
||||
{
|
||||
|
||||
g_otherParameter.SOC = find_soc(getBatteryVoltage()) / 100.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -456,7 +472,7 @@ void setChargMosState(BOOL state)
|
|||
*/
|
||||
BOOL getDischargMosState(void)
|
||||
{
|
||||
if (g_cfgParameter.onlyPower) {
|
||||
if (g_cfgParameter.powerBoxType) {
|
||||
return readOnlyPowerOutputState();
|
||||
} else {
|
||||
return readOutputState();
|
||||
|
@ -468,8 +484,80 @@ BOOL getDischargMosState(void)
|
|||
* @param
|
||||
* @retval softVer 软件版本号
|
||||
*/
|
||||
uint8_t *getVersionInformation(void)
|
||||
uint8_t *getVersionnInformation(void)
|
||||
{
|
||||
return softVer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到回路阻抗大小
|
||||
* @param
|
||||
* @retval 回路阻抗大小
|
||||
*/
|
||||
float getLoopImpedance(void)
|
||||
{
|
||||
return g_otherParameter.loopImpedance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置回路阻抗大小
|
||||
* @param loopImpedance 回路阻抗大小
|
||||
* @retval
|
||||
*/
|
||||
BOOL setLoopImpedance(float loopImpedance)
|
||||
{
|
||||
/* 读取的回路阻抗偏差过大则不使用 */
|
||||
if (loopImpedance < 0 || loopImpedance > 0.3f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (fpclassify(loopImpedance) == FP_NAN) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_otherParameter.loopImpedance = loopImpedance;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到注册状态
|
||||
* @param
|
||||
* @retval 注册状态
|
||||
*/
|
||||
uint16_t getRegistrationStatus(void)
|
||||
{
|
||||
return g_otherParameter.Registration_Status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置注册状态
|
||||
* @param 注册状态
|
||||
* @retval
|
||||
*/
|
||||
void setRegistrationStatus(uint16_t status)
|
||||
{
|
||||
if (status == UNREGISTER || status == REGISTER_FAIL || status == REGISTER_SUCCESS) {
|
||||
g_otherParameter.Registration_Status = status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置反向充电电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setExChargeCurr(void)
|
||||
{
|
||||
exChargeCurr = get_EXCHG_CURR();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到反向充电电流
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
float getExChargeCurr(void)
|
||||
{
|
||||
return exChargeCurr;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
|
||||
#include "soc.h"
|
||||
|
||||
// const float ocv_table[101] = {
|
||||
// 2.80, 2.85, 2.90, 2.95, 3.00, 3.05, 3.10, 3.12, 3.14, 3.16, // 0-9%
|
||||
// 3.18, 3.19, 3.20, 3.20, 3.20, 3.20, 3.21, 3.21, 3.21, 3.21, // 10-19%
|
||||
// 3.22, 3.22, 3.22, 3.22, 3.22, 3.22, 3.23, 3.23, 3.23, 3.23, // 20-29%
|
||||
// 3.23, 3.23, 3.23, 3.23, 3.23, 3.23, 3.23, 3.24, 3.24, 3.24, // 30-39%
|
||||
// 3.24, 3.24, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, 3.25, // 40-49%
|
||||
// 3.25, 3.25, 3.25, 3.25, 3.25, 3.26, 3.26, 3.26, 3.26, 3.26, // 50-59%
|
||||
// 3.26, 3.26, 3.26, 3.26, 3.26, 3.26, 3.27, 3.27, 3.27, 3.27, // 60-69%
|
||||
// 3.28, 3.28, 3.28, 3.29, 3.29, 3.29, 3.30, 3.30, 3.31, 3.31, // 70-79%
|
||||
// 3.32, 3.32, 3.33, 3.34, 3.35, 3.36, 3.38, 3.40, 3.42, 3.45, // 80-89%
|
||||
// 3.48, 3.50, 3.52, 3.54, 3.56, 3.58, 3.60, 3.62, 3.63, 3.64, // 90-99%
|
||||
// 3.65 // 100%
|
||||
// };
|
||||
|
||||
// /**
|
||||
// * 四节串联磷酸铁锂电池组 SOC-OCV 对应表 (SOC步长1%)
|
||||
// * 电压范围:11.2V (0%) ~ 14.6V (100%)
|
||||
// * 注意:
|
||||
// * 1. 假设电池完全均衡,实际需考虑单体差异
|
||||
// * 2. 电压单位:伏特(V)
|
||||
// */
|
||||
// const float ocv_table_4s[101] = {
|
||||
// // 0-9% (单节2.80V~3.16V → 四节11.20V~12.64V)
|
||||
// 11.20, 11.40, 11.60, 11.80, 12.00, 12.20, 12.40, 12.48, 12.56, 12.64, // 0-9%
|
||||
|
||||
// // 10-19% (单节3.18V~3.21V → 四节12.72V~12.84V)
|
||||
// 12.72, 12.76, 12.80, 12.80, 12.80, 12.80, 12.84, 12.84, 12.84, 12.84, // 10-19%
|
||||
|
||||
// // 20-29% (单节3.22V~3.23V → 四节12.88V~12.92V)
|
||||
// 12.88, 12.88, 12.88, 12.88, 12.88, 12.88, 12.92, 12.92, 12.92, 12.92, // 20-29%
|
||||
|
||||
// // 30-39% (单节3.23V~3.24V → 四节12.92V~12.96V)
|
||||
// 12.92, 12.92, 12.92, 12.92, 12.92, 12.92, 12.92, 12.96, 12.96, 12.96, // 30-39%
|
||||
|
||||
// // 40-49% (单节3.24V~3.25V → 四节12.96V~13.00V)
|
||||
// 12.96, 12.96, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, 13.00, // 40-49%
|
||||
|
||||
// // 50-59% (单节3.25V~3.26V → 四节13.00V~13.04V)
|
||||
// 13.00, 13.00, 13.00, 13.00, 13.00, 13.04, 13.04, 13.04, 13.04, 13.04, // 50-59%
|
||||
|
||||
// // 60-69% (单节3.26V~3.27V → 四节13.04V~13.08V)
|
||||
// 13.04, 13.04, 13.04, 13.04, 13.04, 13.04, 13.08, 13.08, 13.08, 13.08, // 60-69%
|
||||
|
||||
// // 70-79% (单节3.28V~3.31V → 四节13.12V~13.24V)
|
||||
// 13.12, 13.12, 13.12, 13.16, 13.16, 13.16, 13.20, 13.20, 13.24, 13.24, // 70-79%
|
||||
|
||||
// // 80-89% (单节3.32V~3.45V → 四节13.28V~13.80V)
|
||||
// 13.28, 13.28, 13.32, 13.36, 13.40, 13.44, 13.52, 13.60, 13.68, 13.80, // 80-89%
|
||||
|
||||
// // 90-100% (单节3.48V~3.65V → 四节13.92V~14.60V)
|
||||
// 13.92, 14.00, 14.08, 14.16, 14.24, 14.32, 14.40, 14.48, 14.52, 14.56, // 90-99%
|
||||
// 14.60 // 100%
|
||||
// };
|
||||
|
||||
|
||||
/**
|
||||
* 四节串联磷酸铁锂电池组 SOC-OCV 对应表 (SOC步长1%)
|
||||
* 电压范围:11.2V (0%) ~ 14.6V (100%)
|
||||
* 注意:
|
||||
* 1. 假设电池完全均衡,实际需考虑单体差异
|
||||
* 2. 电压单位:伏特(V)
|
||||
*/
|
||||
const float ocv_table_4s[21] = {
|
||||
// 0-9% (单节2.80V~3.16V → 四节11.20V~12.64V)
|
||||
12.00, 12.64, // 0-9%
|
||||
|
||||
// 10-19% (单节3.18V~3.21V → 四节12.72V~12.84V)
|
||||
12.80, 12.84, // 10-19%
|
||||
|
||||
// 20-29% (单节3.22V~3.23V → 四节12.88V~12.92V)
|
||||
12.88, 12.92, // 20-29%
|
||||
|
||||
// 30-39% (单节3.23V~3.24V → 四节12.92V~12.96V)
|
||||
12.93, 12.96, // 30-39%
|
||||
|
||||
// 40-49% (单节3.24V~3.25V → 四节12.96V~13.00V)
|
||||
12.98, 13.00, // 40-49%
|
||||
|
||||
// 50-59% (单节3.25V~3.26V → 四节13.00V~13.04V)
|
||||
13.02, 13.04, // 50-59%
|
||||
|
||||
// 60-69% (单节3.26V~3.27V → 四节13.04V~13.08V)
|
||||
13.05, 13.08, // 60-69%
|
||||
|
||||
// 70-79% (单节3.28V~3.31V → 四节13.12V~13.24V)
|
||||
13.16, 13.24, // 70-79%
|
||||
|
||||
// 80-89% (单节3.32V~3.45V → 四节13.28V~13.80V)
|
||||
13.40, 13.80, // 80-89%
|
||||
|
||||
// 90-100% (单节3.48V~3.65V → 四节13.92V~14.60V)
|
||||
13.92, 14.24, // 90-99%
|
||||
14.60 // 100%
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief 得到通过电压得到当前SOC在数组中的位置
|
||||
* @param
|
||||
* @retval soc*100
|
||||
*/
|
||||
int find_soc(float voltage)
|
||||
{
|
||||
// static volatile int soc = 0;
|
||||
// for(soc = 0; soc <= 100; soc++) {
|
||||
for(int soc = 0; soc <= 100; soc++) {
|
||||
if(ocv_table_4s[soc] >= voltage) {
|
||||
return soc * 5;
|
||||
}
|
||||
}
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -5,16 +5,21 @@
|
|||
#include "FM_GPIO.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "bl_chargControl.h"
|
||||
#include "hy_protocol.h"
|
||||
#include "cfg_protocol.h"
|
||||
//#include "hy_protocol.h"
|
||||
//#include "cfg_protocol.h"
|
||||
#include "uart_dev.h"
|
||||
#include "abnormalManage.h"
|
||||
#include "interruptSend.h"
|
||||
#include "configParameter.h"
|
||||
#include "capture.h"
|
||||
#include "bl_usart.h"
|
||||
#include "SOE.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* 控制运行指示灯和喂狗 */
|
||||
#define runled_reloadVal 2000 /* 任务执行间隔 */
|
||||
// static uint16_t runled_reloadVal = 1000; /* 任务执行间隔 */
|
||||
|
@ -41,13 +46,13 @@ static STR_TimeSliceOffset m_startControl;
|
|||
static void Task_startControl(void);
|
||||
|
||||
/* 软启动 */
|
||||
#define softStart_reloadVal 1 /* 任务执行间隔 */
|
||||
#define softStart_reloadVal 10 /* 任务执行间隔 */
|
||||
#define softStart_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_softStart;
|
||||
static void Task_softStart(void);
|
||||
|
||||
/* 回路阻抗检测 */
|
||||
#define impedanceCalculation_reloadVal 20 /* 任务执行间隔 */
|
||||
#define impedanceCalculation_reloadVal 100 /* 任务执行间隔 */
|
||||
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_impedanceCalculation;
|
||||
static void Task_impedanceCalculation(void);
|
||||
|
@ -58,31 +63,31 @@ static void Task_impedanceCalculation(void);
|
|||
STR_TimeSliceOffset m_collectOpenCircuitVoltage;
|
||||
void Task_collectOpenCircuitVoltage(void);
|
||||
|
||||
/* 限时开启HY协议配置模式 */
|
||||
#define beginHYconfigMode_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define beginHYconfigMode_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_beginHYconfigMode;
|
||||
static void Task_beginHYconfigMode(void);
|
||||
// /* 限时开启HY协议配置模式 */
|
||||
// #define beginHYconfigMode_reloadVal 1000 /* 任务执行间隔 */
|
||||
// #define beginHYconfigMode_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_beginHYconfigMode;
|
||||
// static void Task_beginHYconfigMode(void);
|
||||
|
||||
/* 串口数据接收判断 */
|
||||
#define usartJudge_reloadVal 100 /* 任务执行间隔 */
|
||||
#define usartJudge_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartJudge;
|
||||
static void Task_usartJudge(void);
|
||||
// /* 串口数据接收判断 */
|
||||
// #define usartJudge_reloadVal 100 /* 任务执行间隔 */
|
||||
// #define usartJudge_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartJudge;
|
||||
// static void Task_usartJudge(void);
|
||||
|
||||
/* 串口数据解析和处理 */
|
||||
#define usartHandle_reloadVal 20 /* 任务执行间隔 */
|
||||
#define usartHandle_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartHandle;
|
||||
static void Task_usartHandle(void);
|
||||
typedef void (*uartJudgeHandle)(device_handle device);
|
||||
static uartJudgeHandle uart_judge_handle;
|
||||
// /* 串口数据解析和处理 */
|
||||
// #define usartHandle_reloadVal 20 /* 任务执行间隔 */
|
||||
// #define usartHandle_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartHandle;
|
||||
// static void Task_usartHandle(void);
|
||||
// typedef void (*uartJudgeHandle)(device_handle device);
|
||||
// static uartJudgeHandle uart_judge_handle;
|
||||
|
||||
/* 配置文件数据解析和处理 */
|
||||
#define usartCfg_reloadVal 200 /* 任务执行间隔 */
|
||||
#define usartCfg_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartCfg;
|
||||
static void Task_usartCfg(void);
|
||||
// /* 配置文件数据解析和处理 */
|
||||
// #define usartCfg_reloadVal 200 /* 任务执行间隔 */
|
||||
// #define usartCfg_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartCfg;
|
||||
// static void Task_usartCfg(void);
|
||||
|
||||
/* 短路保护 */
|
||||
#define shortCircuitProtection_reloadVal 1000 /* 任务执行间隔 */
|
||||
|
@ -90,6 +95,12 @@ static void Task_usartCfg(void);
|
|||
static STR_TimeSliceOffset m_shortCircuitProtection;
|
||||
static void Task_shortCircuitProtection(void);
|
||||
|
||||
/* 反向充电短路保护 */
|
||||
#define EXCHGSCProtection_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define EXCHGSCProtection_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_EXCHGSCProtection;
|
||||
static void Task_EXCHGSCProtection(void);
|
||||
|
||||
/* 过载保护 */
|
||||
#define excessiveLoad_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define excessiveLoad_offset 0 /* 任务执行偏移量 */
|
||||
|
@ -120,6 +131,21 @@ void Task_busFree(void);
|
|||
STR_TimeSliceOffset m_softShortCircuit;
|
||||
void Task_softShortCircuit(void);
|
||||
|
||||
|
||||
/* 串口任务 */
|
||||
#define uart_reloadVal 10 /* 任务执行间隔 */
|
||||
#define uart_offset 0 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_uart;
|
||||
void Task_uart(void);
|
||||
|
||||
/* 将记录下来的时间存入flash中 */
|
||||
#define SOE_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define SOE_offset 100 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_SOE;
|
||||
void Task_SOE(void);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动时初始化各任务
|
||||
* @param None
|
||||
|
@ -136,10 +162,10 @@ void task_Init(void)
|
|||
TimeSliceOffset_Register(&m_collectOpenCircuitVoltage, Task_collectOpenCircuitVoltage
|
||||
, collectOpenCircuitVoltage_reloadVal, collectOpenCircuitVoltage_offset);
|
||||
|
||||
uartTaskInit();
|
||||
TimeSliceOffset_Register(&m_usartJudge, Task_usartJudge, usartJudge_reloadVal, usartJudge_offset);
|
||||
TimeSliceOffset_Register(&m_usartCfg, Task_usartCfg, usartCfg_reloadVal, usartCfg_offset);
|
||||
TimeSliceOffset_Register(&m_busFree, Task_busFree, busFree_reloadVal, busFree_offset);
|
||||
TimeSliceOffset_Register(&m_uart, Task_uart, uart_reloadVal, uart_offset);
|
||||
TimeSliceOffset_Register(&m_busFree, Task_busFree, busFree_reloadVal, busFree_offset);
|
||||
|
||||
TimeSliceOffset_Register(&m_SOE, Task_SOE, SOE_reloadVal, SOE_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -179,17 +205,20 @@ void Task_wdi(void)
|
|||
{
|
||||
feedDog();
|
||||
|
||||
debug_printf("chargCurrent:%f \n", getChargCurrent());
|
||||
debug_printf("outputVoltage:%f \n", getOutputVoltage());
|
||||
debug_printf("BatteryVoltage:%f \n", getBatteryVoltage());
|
||||
debug_printf("dischargCurrent:%f \n", getDischargCurrent());
|
||||
debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
|
||||
debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
|
||||
debug_printf("InputVoltage:%f \n", getInputVoltage());
|
||||
debug_printf("DischargMosState:%d \n", getDischargMosState());
|
||||
debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
|
||||
debug_printf("loopImpedance:%f \n", g_cfgParameter.loopImpedance);
|
||||
debug_printf("DutyRatio:%f \n", getDutyRatio());
|
||||
debug_printf("chargCurrent:%f \n", getChargCurrent());
|
||||
debug_printf("outputVoltage:%f \n", getOutputVoltage());
|
||||
debug_printf("BatteryVoltage:%f \n", getBatteryVoltage());
|
||||
debug_printf("dischargCurrent:%f \n", getDischargCurrent());
|
||||
debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
|
||||
debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
|
||||
debug_printf("InputVoltage:%f \n", getInputVoltage());
|
||||
debug_printf("DischargMosState:%d \n", getDischargMosState());
|
||||
debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
|
||||
debug_printf("loopImpedance:%f \n", getLoopImpedance());
|
||||
debug_printf("DutyRatio:%f \n", getDutyRatio());
|
||||
// debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN());
|
||||
debug_printf("HAL_GetTick:%d \n", HAL_GetTick());
|
||||
debug_printf("getExChargeCurr:%f \n", getExChargeCurr());
|
||||
|
||||
// char buf[100];
|
||||
// sprintf(buf, "chargCurrent:%f \n", getChargCurrent());
|
||||
|
@ -239,20 +268,22 @@ void Task_wdi(void)
|
|||
// uart_interruptSend(g_gw485_uart2_handle, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
/* 每天复位一次,复位前将电量信息写入flash中 */
|
||||
static uint32_t temp = 60 * 60 * 24;
|
||||
static uint32_t temp = 60 * 60 * 24;
|
||||
// static uint32_t temp = 60 * 30;
|
||||
if (!(--temp)) {
|
||||
temp = 0;
|
||||
float tempF;
|
||||
tempF = getTotalElectricityConsumption();
|
||||
savetotalElectricityConsumption(&tempF);
|
||||
tempF = getTotalChargCapacity();
|
||||
savetotalChargCapacity(&tempF);
|
||||
timeInfo time;
|
||||
time = getLastTime();
|
||||
saveTime(&time);
|
||||
NVIC_SystemReset();
|
||||
// float tempF;
|
||||
// tempF = getTotalElectricityConsumption();
|
||||
// savetotalElectricityConsumption(&tempF);
|
||||
// tempF = getTotalChargCapacity();
|
||||
// savetotalChargCapacity(&tempF);
|
||||
// timeInfo time;
|
||||
// time = getLastTime();
|
||||
// saveTime(&time);
|
||||
// NVIC_SystemReset();
|
||||
resetCheckImpedanceState();
|
||||
temp = 60 * 60 * 24;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -266,6 +297,7 @@ void Task_refreshJudgeData(void)
|
|||
/* 获取数据 */
|
||||
setInputVoltage();
|
||||
setHighSideMosTemperature();
|
||||
setExChargeCurr();
|
||||
|
||||
// static float tempOutV;
|
||||
// tempOutV = get_OUT_VOLT_IN();
|
||||
|
@ -278,8 +310,8 @@ void Task_refreshJudgeData(void)
|
|||
}
|
||||
|
||||
/* 有电池,太阳能输出功率大,电池电压低于14V,同时回路阻抗未测试或需要重新测试 */
|
||||
if ((getCheckImpedanceState() == FALSE || g_cfgParameter.loopImpedance == 0.0f)
|
||||
&& (getBatteryState() == TRUE) && (getChargCurrent() > g_cfgParameter.checkLoopImpedanceChargCurr)
|
||||
if ((getCheckImpedanceState() == FALSE || getLoopImpedance() == 0.0f)
|
||||
&& (getBatteryState() == TRUE) && (getChargCurrent() > g_cfgParameter.minCheckLoopImpedanceChargCurr)
|
||||
&& (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14)
|
||||
&& (getBatteryVoltage() < 14)) {
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
|
@ -287,24 +319,50 @@ void Task_refreshJudgeData(void)
|
|||
}
|
||||
|
||||
/* 温度检测 */
|
||||
if ((getMosTemperState() != mosTemperStart)
|
||||
&& (getHighSideMosTemperature() < g_cfgParameter.HighSideMosTemperature_start)) {
|
||||
if ((getMosTemperState() != mosTemperFull)
|
||||
&& (getHighSideMosTemperature() < g_cfgParameter.fullPowerOutputTemperature)) {
|
||||
/* 状态处于停止运行则打开充电开关 */
|
||||
if (getMosTemperState() == mosTemperStop) {
|
||||
beginChargWork();
|
||||
}
|
||||
setMosTemperState(mosTemperStart);
|
||||
setMosTemperState(mosTemperFull);
|
||||
}
|
||||
else if ((getMosTemperState() == mosTemperStart)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_end) {
|
||||
setMosTemperState(mosTemperEnd);
|
||||
else if ((getMosTemperState() == mosTemperFull)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.reducePowerOutputTemperature) {
|
||||
setMosTemperState(mosTemperReduce);
|
||||
insertEventsOrderRecord(overTemperature);
|
||||
}
|
||||
else if ((getMosTemperState() == mosTemperEnd)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_stop) {
|
||||
else if ((getMosTemperState() == mosTemperReduce)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.stopPowerOutputTemperature) {
|
||||
setMosTemperState(mosTemperStop);
|
||||
/* 停止充电 */
|
||||
stopChargWork();
|
||||
}
|
||||
insertEventsOrderRecord(stopTemperature);
|
||||
}
|
||||
|
||||
/* 反向充电电流检测 */
|
||||
if (getExChargeCurr() > g_cfgParameter.reverseChargProtectionCurr) {
|
||||
setPowerOutput(FALSE);
|
||||
insertEventsOrderRecord(InputProtection);
|
||||
}
|
||||
|
||||
/* 充电输入电压过高 */
|
||||
if (getSolarInCircuitVoltage() >= g_cfgParameter.maxOpenSolarOutputCircuitV) {
|
||||
// log_info("getSolarInCircuitVoltage : %f", getSolarInCircuitVoltage());
|
||||
// log_info("g_cfgParameter.maxOpenSolarOutputCircuitV : %f", g_cfgParameter.maxOpenSolarOutputCircuitV);
|
||||
TimeSliceOffset_Unregister(&m_startControl);
|
||||
m_startControl.runFlag = 0;
|
||||
stopChargWork();
|
||||
insertEventsOrderRecord(overInputVolt);
|
||||
}
|
||||
|
||||
static uint8_t num = 0;
|
||||
if (20 == num++) {
|
||||
num = 0;
|
||||
setSOC();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -318,13 +376,19 @@ void Task_refreshJudgeData(void)
|
|||
*/
|
||||
void Task_startControl(void)
|
||||
{
|
||||
static uint8_t numStart = 0;
|
||||
if (g_cfgParameter.checkCanStartTime > numStart++) {
|
||||
return;
|
||||
}
|
||||
numStart = 0;
|
||||
|
||||
/* 是否达到启动条件 */
|
||||
if (getSolarInCircuitVoltage() > g_cfgParameter.startSolarOpenCircuitV
|
||||
&& getSolarInCircuitVoltage() < g_cfgParameter.maxOpenSolarOpenCircuitV) {
|
||||
&& getSolarInCircuitVoltage() < g_cfgParameter.maxOpenSolarOutputCircuitV) {
|
||||
|
||||
TimeSliceOffset_Unregister(&m_startControl);
|
||||
m_startControl.runFlag = 0;
|
||||
|
||||
|
||||
/* 判断有无电池 */
|
||||
if (getOutputVoltage() > 11.0f) {
|
||||
setBatteryState(TRUE);
|
||||
|
@ -334,6 +398,15 @@ void Task_startControl(void)
|
|||
|
||||
/* 启动软起动任务 */
|
||||
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
|
||||
|
||||
// if (getBatteryState() == TRUE) {
|
||||
// setMPPT_Mode(MPPT);
|
||||
// } else {
|
||||
// setMPPT_Mode(floatCharg);
|
||||
// }
|
||||
|
||||
// setChargControlFlag(TRUE);
|
||||
// EN_PWMOUT_Eable();
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -342,7 +415,7 @@ void Task_startControl(void)
|
|||
* @retval
|
||||
*/
|
||||
void beginStartControlTask(void)
|
||||
{
|
||||
{
|
||||
TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset);
|
||||
m_startControl.runFlag = 1;
|
||||
}
|
||||
|
@ -355,22 +428,59 @@ void beginStartControlTask(void)
|
|||
*/
|
||||
void Task_softStart(void)
|
||||
{
|
||||
// static uint16_t num = 0;
|
||||
// static float dutyRatio = 0;
|
||||
// num++;
|
||||
|
||||
// if (num < 5) {
|
||||
// set_pwmDutyRatio(0.1f);
|
||||
// EN_PWMOUT_Eable();
|
||||
// }
|
||||
|
||||
// else if (num > 70 || dutyRatio > 0.7f) {
|
||||
// TimeSliceOffset_Unregister(&m_softStart);
|
||||
// m_softStart.runFlag = 0;
|
||||
|
||||
// dutyRatio = 0;
|
||||
// num = 0;
|
||||
// setDutyRatio(0.75f);
|
||||
|
||||
// if (getBatteryState() == TRUE) {
|
||||
// setMPPT_Mode(MPPT);
|
||||
// } else {
|
||||
// setMPPT_Mode(floatCharg);
|
||||
// }
|
||||
// setChargControlFlag(TRUE);
|
||||
// }
|
||||
|
||||
// else {
|
||||
// setDutyRatio(getDutyRatio() + 0.01f);
|
||||
// }
|
||||
|
||||
|
||||
static uint16_t num = 0;
|
||||
static float dutyRatio = 0;
|
||||
// static float dutyRatio = 0;
|
||||
num++;
|
||||
|
||||
if (num < 5) {
|
||||
set_pwmDutyRatio(0.1f);
|
||||
EN_PWMOUT_Eable();
|
||||
//最小占空比斩波
|
||||
setDutyRatio(0.0001f);
|
||||
}
|
||||
|
||||
else if (num > 70 || dutyRatio > 0.75f) {
|
||||
else if (num > 80) {
|
||||
TimeSliceOffset_Unregister(&m_softStart);
|
||||
m_softStart.runFlag = 0;
|
||||
|
||||
dutyRatio = 0;
|
||||
num = 0;
|
||||
setDutyRatio(0.75f);
|
||||
|
||||
// debug_printf("getSolarInCircuitVoltage : %f", getSolarInCircuitVoltage());
|
||||
|
||||
//电压过低时不启动
|
||||
if (getSolarInCircuitVoltage() < 18.5f) {
|
||||
TimeSliceOffset_Register(&m_startControl, Task_startControl, startControl_reloadVal, startControl_offset);
|
||||
setDutyRatioToZero();
|
||||
return;
|
||||
}
|
||||
|
||||
if (getBatteryState() == TRUE) {
|
||||
setMPPT_Mode(MPPT);
|
||||
|
@ -378,11 +488,11 @@ void Task_softStart(void)
|
|||
setMPPT_Mode(floatCharg);
|
||||
}
|
||||
setChargControlFlag(TRUE);
|
||||
}
|
||||
|
||||
else {
|
||||
setDutyRatio(getDutyRatio() + 0.01f);
|
||||
}
|
||||
|
||||
// else {
|
||||
// setDutyRatio(0.01f);
|
||||
// }
|
||||
}
|
||||
/**
|
||||
* @brief 启动软启动任务
|
||||
|
@ -435,12 +545,16 @@ void Task_impedanceCalculation(void)
|
|||
float tempLoopImpedance = 0;
|
||||
tempLoopImpedance = (voltOne - voltTwo) / (currOne - currTwo);
|
||||
|
||||
// if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
|
||||
// g_cfgParameter.loopImpedance = tempLoopImpedance;
|
||||
// saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
// setCheckImpedanceState();
|
||||
// }
|
||||
/* 判断回路阻抗是否合理 */
|
||||
if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
|
||||
g_cfgParameter.loopImpedance = tempLoopImpedance;
|
||||
saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
if (setLoopImpedance(tempLoopImpedance) == TRUE) {
|
||||
saveLoopImpedance(&tempLoopImpedance);
|
||||
setCheckImpedanceState();
|
||||
}
|
||||
}
|
||||
|
||||
setMPPT_Mode(MPPT);
|
||||
setChargControlFlag(TRUE);
|
||||
|
@ -454,134 +568,175 @@ void Task_impedanceCalculation(void)
|
|||
*/
|
||||
void Task_collectOpenCircuitVoltage(void)
|
||||
{
|
||||
/* 用于无充电控制时获取开路电压 */
|
||||
static uint32_t collectOpenCircuitVoltageNoNUM = 0;
|
||||
/* 用于有充电控制时获取开路电压 */
|
||||
static uint8_t collectOpenCircuitVoltageYesNUM = 0;
|
||||
// /* 用于无充电控制时获取开路电压 */
|
||||
// static uint32_t collectOpenCircuitVoltageNoNUM = 0;
|
||||
// /* 用于有充电控制时获取开路电压 */
|
||||
// static uint8_t collectOpenCircuitVoltageYesNUM = 0;
|
||||
/* 用于有充电控制时当标志位 */
|
||||
static BOOL collectOpenCircuitVoltageYesFlag = 0;
|
||||
|
||||
|
||||
/* 未进行充电时,3S采集一次开路电压 */
|
||||
if (FALSE == getChargControlFlag()) {
|
||||
if (2 <= collectOpenCircuitVoltageNoNUM++) {
|
||||
setSolarOpenCircuitVoltage();
|
||||
collectOpenCircuitVoltageNoNUM = 0;
|
||||
}
|
||||
collectOpenCircuitVoltageYesNUM = 0;
|
||||
if (collectOpenCircuitVoltageYesFlag == TRUE) {
|
||||
setSolarOpenCircuitVoltage();
|
||||
beginChargWork();
|
||||
collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
collectOpenCircuitVoltageYesNUM++;
|
||||
static uint32_t collectOpenCircuitVoltageNUM = 0;
|
||||
collectOpenCircuitVoltageNUM++;
|
||||
|
||||
/* 到达开路电压检测时间 */
|
||||
if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime) {
|
||||
if (collectOpenCircuitVoltageNUM == g_cfgParameter.collectOpenCircuitVoltageTime) {
|
||||
// if (collectOpenCircuitVoltageNUM == 180) {
|
||||
/* 有电池才进行开路电压检测 */
|
||||
if (getBatteryState()) {
|
||||
collectOpenCircuitVoltageYesFlag = TRUE;
|
||||
stopChargWork();
|
||||
/* 设置延时为(1000-500)ms */
|
||||
m_collectOpenCircuitVoltage.count = 500;
|
||||
}
|
||||
collectOpenCircuitVoltageYesNUM = 0;
|
||||
if (!getBatteryState()) {
|
||||
collectOpenCircuitVoltageNUM = 0;
|
||||
return;
|
||||
}
|
||||
collectOpenCircuitVoltageYesFlag = TRUE;
|
||||
stopChargWork();
|
||||
/* 设置延时为(1000-500)ms */
|
||||
m_collectOpenCircuitVoltage.count = 500;
|
||||
}
|
||||
|
||||
/* 检测开路电压 */
|
||||
if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) {
|
||||
if (collectOpenCircuitVoltageNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) {
|
||||
// if (collectOpenCircuitVoltageNUM == 181) {
|
||||
/* 有电池才进行开路电压检测 */
|
||||
if (getBatteryState()) {
|
||||
if (!getBatteryState()) {
|
||||
collectOpenCircuitVoltageNUM = 0;
|
||||
return;
|
||||
}
|
||||
setSolarOpenCircuitVoltage();
|
||||
beginChargWork();
|
||||
collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
// beginSoftStartTask();
|
||||
collectOpenCircuitVoltageNUM = 0;
|
||||
// setChargControlFlag(TRUE);
|
||||
}
|
||||
|
||||
/* 未进行充电时,3S采集一次开路电压 */
|
||||
if (FALSE == getChargControlFlag() && !collectOpenCircuitVoltageYesFlag) {
|
||||
if (2 <= collectOpenCircuitVoltageNUM) {
|
||||
setSolarOpenCircuitVoltage();
|
||||
beginChargWork();
|
||||
collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
}
|
||||
collectOpenCircuitVoltageNUM = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 开启HY配置模式后,配置完成后120S后自动退出
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_beginHYconfigMode(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
num++;
|
||||
if (num >= 120) {
|
||||
TimeSliceOffset_Unregister(&m_beginHYconfigMode);
|
||||
m_beginHYconfigMode.runFlag = 0;
|
||||
num = 0;
|
||||
setHYconfigModeState(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 开启HY配置模式后启动退出任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void beginHYconfigMode(void)
|
||||
{
|
||||
setHYconfigModeState(TRUE);
|
||||
TimeSliceOffset_Register(&m_beginHYconfigMode, Task_beginHYconfigMode
|
||||
, beginHYconfigMode_reloadVal, beginHYconfigMode_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化串口任务,确定使用的协议
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void uartTaskInit(void)
|
||||
{
|
||||
// if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// uart_judge_handle = read_and_process_uart_data;
|
||||
// } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// /* 未进行充电时,3S采集一次开路电压 */
|
||||
// if (FALSE == getChargControlFlag()) {
|
||||
// if (2 <= collectOpenCircuitVoltageNoNUM++) {
|
||||
// setSolarOpenCircuitVoltage();
|
||||
// collectOpenCircuitVoltageNoNUM = 0;
|
||||
// }
|
||||
// collectOpenCircuitVoltageYesNUM = 0;
|
||||
// if (collectOpenCircuitVoltageYesFlag == TRUE) {
|
||||
// setSolarOpenCircuitVoltage();
|
||||
// beginChargWork();
|
||||
// collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// collectOpenCircuitVoltageYesNUM++;
|
||||
|
||||
// /* 到达开路电压检测时间 */
|
||||
// if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime) {
|
||||
// /* 有电池才进行开路电压检测 */
|
||||
// if (getBatteryState()) {
|
||||
// collectOpenCircuitVoltageYesFlag = TRUE;
|
||||
// stopChargWork();
|
||||
// /* 设置延时为(1000-500)ms */
|
||||
// m_collectOpenCircuitVoltage.count = 500;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /* 检测开路电压 */
|
||||
// if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) {
|
||||
// /* 有电池才进行开路电压检测 */
|
||||
// if (getBatteryState()) {
|
||||
// setSolarOpenCircuitVoltage();
|
||||
// beginChargWork();
|
||||
// collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
// }
|
||||
// collectOpenCircuitVoltageYesNUM = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 检测有无通信数据传来
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartJudge(void)
|
||||
{
|
||||
/* 检测到对上通信串口有数据启动读取并解析任务 */
|
||||
if (uart_dev_char_present(g_gw485_uart2_handle)) {
|
||||
TimeSliceOffset_Register(&m_usartHandle, Task_usartHandle
|
||||
, usartHandle_reloadVal, usartHandle_offset);
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * @brief 开启HY配置模式后,配置完成后120S后自动退出
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_beginHYconfigMode(void)
|
||||
// {
|
||||
// static uint8_t num = 0;
|
||||
// num++;
|
||||
// if (num >= 120) {
|
||||
// TimeSliceOffset_Unregister(&m_beginHYconfigMode);
|
||||
// m_beginHYconfigMode.runFlag = 0;
|
||||
// num = 0;
|
||||
// setHYconfigModeState(FALSE);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 读取并解析对上通讯的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartHandle(void)
|
||||
{
|
||||
TimeSliceOffset_Unregister(&m_usartHandle);
|
||||
m_usartHandle.runFlag = 0;
|
||||
uart_judge_handle(g_gw485_uart2_handle);
|
||||
}
|
||||
// /**
|
||||
// * @brief 开启HY配置模式后启动退出任务
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void beginHYconfigMode(void)
|
||||
// {
|
||||
// setHYconfigModeState(TRUE);
|
||||
// TimeSliceOffset_Register(&m_beginHYconfigMode, Task_beginHYconfigMode
|
||||
// , beginHYconfigMode_reloadVal, beginHYconfigMode_offset);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 读取并解析配置文件的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartCfg(void)
|
||||
{
|
||||
read_and_process_config_data();
|
||||
}
|
||||
// /**
|
||||
// * @brief 初始化串口任务,确定使用的协议
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void uartTaskInit(void)
|
||||
// {
|
||||
// // if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// // uart_judge_handle = read_and_process_uart_data;
|
||||
// // } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// // uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// // }
|
||||
|
||||
// uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 检测有无通信数据传来
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartJudge(void)
|
||||
// {
|
||||
// /* 检测到对上通信串口有数据启动读取并解析任务 */
|
||||
// if (uart_dev_char_present(g_gw485_uart2_handle)) {
|
||||
// TimeSliceOffset_Register(&m_usartHandle, Task_usartHandle
|
||||
// , usartHandle_reloadVal, usartHandle_offset);
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 读取并解析对上通讯的数据
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartHandle(void)
|
||||
// {
|
||||
// TimeSliceOffset_Unregister(&m_usartHandle);
|
||||
// m_usartHandle.runFlag = 0;
|
||||
// uart_judge_handle(g_gw485_uart2_handle);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 读取并解析配置文件的数据
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartCfg(void)
|
||||
// {
|
||||
// read_and_process_config_data();
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 短路保护任务,短路后启动该任务
|
||||
|
@ -593,21 +748,29 @@ void Task_shortCircuitProtection(void)
|
|||
static uint8_t num = 0;
|
||||
num++;
|
||||
|
||||
|
||||
/* 设定输出短路保护时间 */
|
||||
if (num == g_cfgParameter.outputAgainFlagTime) {
|
||||
if (num == 2) {
|
||||
// setPowerOutput(FALSE);
|
||||
setPowerOutput(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* 设定输出短路保护时间 */
|
||||
if (num == g_cfgParameter.shortCircuitJudgmentDelay) {
|
||||
num = 0;
|
||||
zeroShortCircuit();
|
||||
TimeSliceOffset_Unregister(&m_shortCircuitProtection);
|
||||
m_shortCircuitProtection.runFlag = 0;
|
||||
|
||||
/* 仍然过流,彻底关闭输出 */
|
||||
if (readOverCurrState() == FALSE) {
|
||||
setPowerOutput(FALSE);
|
||||
}
|
||||
/* 不过流,则状态位复位 */
|
||||
else {
|
||||
setShortCircuitFlag(FALSE);
|
||||
}
|
||||
// /* 仍然过流,彻底关闭输出 */
|
||||
// if (readOverCurrState() == FALSE) {
|
||||
// setPowerOutput(FALSE);
|
||||
// }
|
||||
// /* 不过流,则状态位复位 */
|
||||
// else {
|
||||
// setShortCircuitFlag(FALSE);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -633,6 +796,53 @@ void stopShortCircuitProtection(void)
|
|||
m_shortCircuitProtection.runFlag = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 反向充电短路保护任务,短路后启动该任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_EXCHGSCProtection(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
num++;
|
||||
|
||||
/* 设定输出短路保护时间 */
|
||||
if (num == 2) {
|
||||
// setPowerOutput(FALSE);
|
||||
setPowerOutput(TRUE);
|
||||
}
|
||||
|
||||
/* 设定输出短路保护时间 */
|
||||
if (num == g_cfgParameter.shortCircuitJudgmentDelay) {
|
||||
num = 0;
|
||||
zeroShortCircuit();
|
||||
TimeSliceOffset_Unregister(&m_EXCHGSCProtection);
|
||||
m_EXCHGSCProtection.runFlag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 启动短路保护任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void startEXCHGSCProtection(void)
|
||||
{
|
||||
TimeSliceOffset_Register(&m_EXCHGSCProtection, Task_EXCHGSCProtection
|
||||
, EXCHGSCProtection_reloadVal, EXCHGSCProtection_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭短路保护任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void stopEXCHGSCProtection(void)
|
||||
{
|
||||
TimeSliceOffset_Unregister(&m_EXCHGSCProtection);
|
||||
m_EXCHGSCProtection.runFlag = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 过载保护任务,输入不够供给输出后启动该任务
|
||||
* @param
|
||||
|
@ -670,7 +880,7 @@ void Task_excessiveLoad(void)
|
|||
}
|
||||
|
||||
/* 仅过载一次,达到时间后关闭该任务 */
|
||||
if (num == g_cfgParameter.excessiveLoadFlagTime) {
|
||||
if (num == g_cfgParameter.inputPowerLowJudgmentDelay) {
|
||||
num = 0;
|
||||
setExcessiveLoadFlag(FALSE);
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
|
@ -681,10 +891,12 @@ void Task_excessiveLoad(void)
|
|||
/* 关闭输出后开始计时 */
|
||||
if (readPOW_OUT_PCON_State() == FALSE) {
|
||||
numLong++;
|
||||
} else {
|
||||
numLong = 0;
|
||||
}
|
||||
|
||||
/* 达到时间就重新尝试输出 */
|
||||
if (numLong == g_cfgParameter.eLAgainTime) {
|
||||
if (numLong == g_cfgParameter.inputPowerLowAgainOutputDelay) {
|
||||
numLong = 0;
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
m_excessiveLoad.runFlag = 0;
|
||||
|
@ -753,9 +965,9 @@ void Task_softShortCircuit(void)
|
|||
setPowerOutput(TRUE);
|
||||
}
|
||||
|
||||
if (num >= g_cfgParameter.outputAgainFlagTime) {
|
||||
if (num >= g_cfgParameter.shortCircuitJudgmentDelay) {
|
||||
num = 0;
|
||||
if (getShortCircuit() == 1) {
|
||||
if (getShortCircuit() == 1) {
|
||||
setShortCircuitFlag(FALSE);
|
||||
}
|
||||
zeroShortCircuit();
|
||||
|
@ -774,4 +986,27 @@ void startSoftShortCircuitProtection(void)
|
|||
{
|
||||
TimeSliceOffset_Register(&m_softShortCircuit, Task_softShortCircuit
|
||||
, softShortCircuit_reloadVal, softShortCircuit_offset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动软件解析任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_uart(void)
|
||||
{
|
||||
gw485DataAnalysis(g_gw485_uart2_handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将记录下来的事件存入flash中
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_SOE(void)
|
||||
{
|
||||
setEventsOrderRecord();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,5 +33,8 @@ BOOL readOutputState(void);
|
|||
|
||||
extern void WORK_VOLT_Interrupt(void);
|
||||
extern void DSG_PROT_Interrupt(void);
|
||||
extern void EXCHG_PROT_Interrupt(void);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,6 +23,7 @@ typedef struct _adcCapture
|
|||
|
||||
void ADC_Capture_Init(void);
|
||||
void proportionalInt(int mode);
|
||||
uint16_t setfirstStageProtectionValue(float curr);
|
||||
|
||||
float get_CHG_CURR(void);
|
||||
float get_PV_VOLT_OUT(void);
|
||||
|
@ -30,10 +31,12 @@ float get_DSG_CURR(void);
|
|||
float get_PV1_VOLT_IN(void);
|
||||
float get_PV_VOLT_IN1(void);
|
||||
float get_MOSFET_Temper(void);
|
||||
float get_OUT_VOLT_IN(void);
|
||||
float get_EXCHG_CURR(void);
|
||||
|
||||
void adcCaptureFir();
|
||||
|
||||
extern void setSoftShortCircuit(uint16_t disChargCurrAdcNum);
|
||||
|
||||
extern void chargControl(void);
|
||||
|
||||
#endif
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "w25qxx.h"
|
||||
// #include "w25q256.h"
|
||||
|
||||
void Flash_Init(void);
|
||||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);
|
||||
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite);
|
||||
void erase_Sector_Flash(uint32_t secpos);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -15,7 +15,8 @@ void FM_GPIO_Init(void)
|
|||
*/
|
||||
void POW_FF_PCON_Open(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_SET);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -25,7 +26,8 @@ void POW_FF_PCON_Open(void)
|
|||
*/
|
||||
void POW_FF_PCON_Close(void)
|
||||
{
|
||||
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_RESET);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,7 +169,7 @@ BOOL readOverCurrState(void)
|
|||
if (HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -178,23 +180,27 @@ BOOL readOverCurrState(void)
|
|||
*/
|
||||
BOOL readOnlyPowerOutputState(void)
|
||||
{
|
||||
static volatile GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
|
||||
// static volatile GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
|
||||
// GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
|
||||
// GPIO_PinState gpioTemp1, gpioTemp2;
|
||||
|
||||
// gpioTemp1 = HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
// gpioTemp2 = HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin);
|
||||
// gpioTemp3 = HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin);
|
||||
|
||||
gpioTemp1 = HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
gpioTemp2 = HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin);
|
||||
gpioTemp3 = HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin);
|
||||
// if (gpioTemp1 == GPIO_PIN_SET
|
||||
// && gpioTemp2 == GPIO_PIN_SET
|
||||
// // && gpioTemp3 == GPIO_PIN_SET) {
|
||||
// ) {
|
||||
// return TRUE;
|
||||
// }
|
||||
|
||||
if (gpioTemp1 == GPIO_PIN_SET
|
||||
&& gpioTemp2 == GPIO_PIN_SET
|
||||
&& gpioTemp3 == GPIO_PIN_SET) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
|
||||
// && HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
|
||||
// && HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
|
||||
// return TRUE;
|
||||
// }
|
||||
if (!HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
|
||||
&& HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
|
||||
&& !HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)
|
||||
&& !HAL_GPIO_ReadPin(EXCHG_CURR_GPIO_Port, EXCHG_CURR_Pin)) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -225,9 +231,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
WORK_VOLT_Interrupt();
|
||||
}
|
||||
|
||||
// else if (GPIO_Pin == DSG_PROT_Pin) {
|
||||
// DSG_PROT_Interrupt();
|
||||
// }
|
||||
else if (GPIO_Pin == DSG_PROT_Pin) {
|
||||
DSG_PROT_Interrupt();
|
||||
}
|
||||
|
||||
else if (GPIO_Pin == EXCHG_PROT_Pin) {
|
||||
EXCHG_PROT_Interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,9 +22,9 @@ void FM_RTC_Init(void)
|
|||
void setRTC_Time(timeInfo *time)
|
||||
{
|
||||
/* 日期结构体 */
|
||||
static RTC_DateTypeDef setData;
|
||||
RTC_DateTypeDef setData;
|
||||
/* 时间结构体 */
|
||||
static RTC_TimeTypeDef setTime;
|
||||
RTC_TimeTypeDef setTime;
|
||||
|
||||
setData.Year = time->year;
|
||||
setData.Month = time->month;
|
||||
|
@ -46,9 +46,9 @@ void setRTC_Time(timeInfo *time)
|
|||
void getRTC_Time(timeInfo *time)
|
||||
{
|
||||
/* 日期结构体 */
|
||||
static RTC_DateTypeDef getData;
|
||||
RTC_DateTypeDef getData;
|
||||
/* 时间结构体 */
|
||||
static RTC_TimeTypeDef getTime;
|
||||
RTC_TimeTypeDef getTime;
|
||||
|
||||
HAL_RTC_GetDate(&hrtc, &getData, RTC_FORMAT_BIN);
|
||||
HAL_RTC_GetTime(&hrtc, &getTime, RTC_FORMAT_BIN);
|
||||
|
|
|
@ -19,7 +19,7 @@ void tim_Init(void)
|
|||
// HAL_TIM_Base_Start(&htim3);
|
||||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
|
||||
|
||||
HD_controlTim_Init();
|
||||
// HD_controlTim_Init();
|
||||
HAL_TIM_Base_Start_IT(&htim7);
|
||||
|
||||
HD_taskBaseTim_Init();
|
||||
|
|
|
@ -98,7 +98,9 @@ enum {
|
|||
CHG_CURR_NUM = 2,
|
||||
PV_VOLT_IN_NUM = 3,
|
||||
};
|
||||
int16_t adcBuff[4];
|
||||
// int16_t adcBuff[4];
|
||||
|
||||
int16_t adcBuff[40];
|
||||
/* 指向adcCapture中的inData16数组中的第一位也是最后一位 */
|
||||
uint8_t pointer;
|
||||
|
||||
|
@ -109,11 +111,11 @@ adcCapture CHG_CURR_capture = {0};
|
|||
|
||||
/* 电流电压采集转换的 */
|
||||
static float P_CHG_CURR = 0;
|
||||
static float P_PV_VOLT_OUT = 0;
|
||||
static float P_EXCHG_CURR = 0;
|
||||
static float P_DSG_CURR = 0;
|
||||
static float P_PV1_VOLT_IN = 0;
|
||||
static float P_PV_VOLT_IN1 = 0;
|
||||
static float P_OUT_VOLT_IN = 0;
|
||||
static float P_PV_VOLT_OUT = 0;
|
||||
|
||||
/* 2.5为adc的电压,4095是2^adc的位数 - 1 */
|
||||
// const float32_t Proportion = 2.5 / 4095;
|
||||
|
@ -132,11 +134,11 @@ const float32_t Proportion = 3.0 / 4095.0;
|
|||
// 0.178709805, 0.3671073616, 0.3671073616, 0.178709805
|
||||
// };
|
||||
|
||||
/* matlab生成的3阶滤波器系数,乘比例使和接近为1 */
|
||||
const int firLen = 4;
|
||||
const float32_t firLP[4] = {
|
||||
0.163708486, 0.336291513, 0.336291513, 0.163708486
|
||||
};
|
||||
// /* matlab生成的3阶滤波器系数,乘比例使和接近为1 */
|
||||
// const int firLen = 4;
|
||||
// const float32_t firLP[4] = {
|
||||
// 0.163708486, 0.336291513, 0.336291513, 0.163708486
|
||||
// };
|
||||
|
||||
|
||||
// void captureFirInit(void);
|
||||
|
@ -161,7 +163,7 @@ void ADC_Capture_Init(void)
|
|||
// captureFirInit();
|
||||
|
||||
HAL_TIM_Base_Start(&htim6);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 40);
|
||||
|
||||
// /* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
// P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
|
@ -194,8 +196,8 @@ void proportionalInt(int mode)
|
|||
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 系统电源电压比例 */
|
||||
P_PV_VOLT_IN1 = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 输出外部电压比例 */
|
||||
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 外部输入电流比例 */
|
||||
P_EXCHG_CURR = P_DSG_CURR;
|
||||
}
|
||||
|
||||
/* 电源盒外还有网关功能 */
|
||||
|
@ -210,10 +212,11 @@ void proportionalInt(int mode)
|
|||
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 系统电源电压比例 */
|
||||
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
/* 输出外部电压比例 */
|
||||
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 外部输入电流比例 */
|
||||
P_EXCHG_CURR = P_DSG_CURR;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// /* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
// P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
// /* 充电控制盒输出电压比例,分压系数 */
|
||||
|
@ -226,6 +229,18 @@ void proportionalInt(int mode)
|
|||
// P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置第一段保护ADC采样的值
|
||||
* @param
|
||||
* @retval None
|
||||
*/
|
||||
uint16_t setfirstStageProtectionValue(float curr)
|
||||
{
|
||||
return (uint16_t)(curr / P_DSG_CURR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define N 4
|
||||
/**
|
||||
* @brief 中位值平均滤波
|
||||
|
@ -420,27 +435,32 @@ float get_MOSFET_Temper(void)
|
|||
* @param
|
||||
* @retval V 电压值
|
||||
*/
|
||||
float get_OUT_VOLT_IN(void)
|
||||
float get_EXCHG_CURR(void)
|
||||
{
|
||||
float V;
|
||||
uint16_t V_ADC;
|
||||
static uint16_t V_ADCTemp = (uint16_t)(0.55f / 3.0f * 4095);
|
||||
float I;
|
||||
uint16_t I_ADC;
|
||||
// static uint16_t V_ADCTemp = (uint16_t)(0.52f / 3.0f * 4095);
|
||||
// static uint16_t V_ADCTemp = (uint16_t)(0.17f / 3.0f * 4095);
|
||||
|
||||
V_ADC = ADC2_Capture(OUT_VOLT_IN_CHANNEL);
|
||||
I_ADC = ADC2_Capture(EXCHG_CURR_CHANNEL);
|
||||
|
||||
I = (float)(I_ADC) * P_EXCHG_CURR;
|
||||
|
||||
if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)) {
|
||||
V = (float)(V_ADC) * P_OUT_VOLT_IN;
|
||||
} else {
|
||||
V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN;
|
||||
}
|
||||
// if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)) {
|
||||
// V = (float)(V_ADC) * P_OUT_VOLT_IN;
|
||||
// } else {
|
||||
// if (V_ADC > V_ADCTemp) {
|
||||
// V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN;
|
||||
// }
|
||||
// V = (float)(V_ADC) * P_OUT_VOLT_IN;
|
||||
// }
|
||||
|
||||
#ifdef enable_Printf_VI
|
||||
debug("\n OUT_VOLT_IN ADC : %d \n", V_ADC);
|
||||
debug(" OUT_VOLT_IN V : %f \n", V);
|
||||
#endif
|
||||
|
||||
return V;
|
||||
return I;
|
||||
}
|
||||
|
||||
|
||||
|
@ -452,37 +472,68 @@ float get_OUT_VOLT_IN(void)
|
|||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
|
||||
{
|
||||
if (hdma->Instance == ADC1) {
|
||||
setSoftShortCircuit(adcBuff[DSG_CURR_NUM]);
|
||||
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_SET);
|
||||
|
||||
WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
|
||||
DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
|
||||
PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
|
||||
CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
|
||||
// setSoftShortCircuit(adcBuff[DSG_CURR_NUM]);
|
||||
|
||||
WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
|
||||
DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
|
||||
PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
|
||||
CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
|
||||
// WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
|
||||
// DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
|
||||
// PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
|
||||
// CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
|
||||
|
||||
WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
|
||||
DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
|
||||
PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
|
||||
CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
|
||||
// WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
|
||||
// DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
|
||||
// PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
|
||||
// CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
|
||||
|
||||
pointer++;
|
||||
if (pointer >= 10) {
|
||||
pointer = 0;
|
||||
}
|
||||
// WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
|
||||
// DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
|
||||
// PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
|
||||
// CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
|
||||
|
||||
arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
|
||||
arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
|
||||
arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
|
||||
arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
|
||||
// pointer++;
|
||||
// if (pointer >= 10) {
|
||||
// pointer = 0;
|
||||
// }
|
||||
|
||||
// arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
|
||||
// arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
|
||||
// arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
|
||||
// arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
|
||||
|
||||
// WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
|
||||
// DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
|
||||
// PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
|
||||
// CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
|
||||
|
||||
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_RESET);
|
||||
|
||||
// WORK_VOLT_capture.outData = (float32_t)(adcBuff[0] + adcBuff[4] + adcBuff[8] + adcBuff[12] + adcBuff[16]
|
||||
// + adcBuff[20] + adcBuff[24] + adcBuff[28] + adcBuff[32] + adcBuff[36]) / indata16_size;
|
||||
// DSG_CURR_capture.outData = (float32_t)(adcBuff[1] + adcBuff[5] + adcBuff[9] + adcBuff[13] + adcBuff[17]
|
||||
// + adcBuff[21] + adcBuff[25] + adcBuff[29] + adcBuff[33] + adcBuff[37]) / indata16_size;
|
||||
// CHG_CURR_capture.outData = (float32_t)(adcBuff[2] + adcBuff[6] + adcBuff[10] + adcBuff[14] + adcBuff[18]
|
||||
// + adcBuff[22] + adcBuff[26] + adcBuff[30] + adcBuff[34] + adcBuff[38]) / indata16_size;
|
||||
// PV_VOLT_IN_capture.outData = (float32_t)(adcBuff[3] + adcBuff[7] + adcBuff[11] + adcBuff[15] + adcBuff[19]
|
||||
// + adcBuff[23] + adcBuff[27] + adcBuff[31] + adcBuff[35] + adcBuff[39]) / indata16_size;
|
||||
|
||||
WORK_VOLT_capture.outData = (adcBuff[0] + adcBuff[4] + adcBuff[8] + adcBuff[12] + adcBuff[16]
|
||||
+ adcBuff[20] + adcBuff[24] + adcBuff[28] + adcBuff[32] + adcBuff[36]) / indata16_size;
|
||||
DSG_CURR_capture.outData = (adcBuff[1] + adcBuff[5] + adcBuff[9] + adcBuff[13] + adcBuff[17]
|
||||
+ adcBuff[21] + adcBuff[25] + adcBuff[29] + adcBuff[33] + adcBuff[37]) / indata16_size;
|
||||
CHG_CURR_capture.outData = (adcBuff[2] + adcBuff[6] + adcBuff[10] + adcBuff[14] + adcBuff[18]
|
||||
+ adcBuff[22] + adcBuff[26] + adcBuff[30] + adcBuff[34] + adcBuff[38]) / indata16_size;
|
||||
PV_VOLT_IN_capture.outData = (adcBuff[3] + adcBuff[7] + adcBuff[11] + adcBuff[15] + adcBuff[19]
|
||||
+ adcBuff[23] + adcBuff[27] + adcBuff[31] + adcBuff[35] + adcBuff[39]) / indata16_size;
|
||||
|
||||
// WORK_VOLT_capture.outData = ;
|
||||
|
||||
setSoftShortCircuit(DSG_CURR_capture.outData);
|
||||
|
||||
chargControl();
|
||||
|
||||
WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
|
||||
DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
|
||||
PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
|
||||
CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,15 +607,15 @@ void adcCaptureFir(void)
|
|||
// PV_VOLT_IN_capture.outData = 1;
|
||||
// CHG_CURR_capture.outData = 1;
|
||||
|
||||
static float32_t outputf;
|
||||
arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
|
||||
WORK_VOLT_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
DSG_CURR_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
|
||||
PV_VOLT_IN_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
CHG_CURR_capture.outData = (int16_t)outputf;
|
||||
// static float32_t outputf;
|
||||
// arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
|
||||
// WORK_VOLT_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
// DSG_CURR_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
|
||||
// PV_VOLT_IN_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
// CHG_CURR_capture.outData = (int16_t)outputf;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "flash.h"
|
||||
// #include "gpio.h"
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief flash初始化
|
||||
|
@ -11,12 +13,60 @@ void Flash_Init(void)
|
|||
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/*Configure GPIO pin : FLASH_CS_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// // GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
||||
// // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// // GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
// /*Configure GPIO pin Output Level */
|
||||
// // HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
|
||||
// HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin, GPIO_PIN_RESET);
|
||||
|
||||
// /*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
|
||||
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// /*Configure GPIO pin : FLASH_MOSI_Pin */
|
||||
// GPIO_InitStruct.Pin = FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
// Flash_GPIO_Init();
|
||||
W25QXX_Init();
|
||||
}
|
||||
|
||||
|
@ -29,6 +79,8 @@ void Flash_Init(void)
|
|||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
||||
{
|
||||
W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
|
||||
// Flash_Read(pBuffer, ReadAddr, NumByteToRead);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,4 +92,16 @@ void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
|||
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||||
}
|
||||
// Flash_Write_MorePage(pBuffer, WriteAddr, NumByteToWrite);
|
||||
// W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 清除flash中secpos扇区的数据
|
||||
*
|
||||
*/
|
||||
void erase_Sector_Flash(uint32_t secpos)
|
||||
{
|
||||
W25QXX_Erase_Sector(secpos);
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@ device_handle g_gw485_uart2_handle;
|
|||
device_handle g_bat485_uart3_handle;
|
||||
device_handle g_debug_uart4_handle;
|
||||
|
||||
static uint8_t Debug_in_buff[200];
|
||||
static uint8_t Gw485_in_buff[200];
|
||||
static uint8_t Bat485_in_buff[200];
|
||||
static uint8_t Debug_in_buff[10];
|
||||
static uint8_t Gw485_in_buff[300];
|
||||
static uint8_t Bat485_in_buff[300];
|
||||
|
||||
uint8_t rx_gw485_buf[1];
|
||||
uint8_t rx_bat485_buf[1];
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "stm32g431xx.h"
|
||||
|
||||
#define SYS_VOLT_IN_CHANNEL ADC_CHANNEL_1
|
||||
#define OUT_VOLT_IN_CHANNEL ADC_CHANNEL_9
|
||||
#define EXCHG_CURR_CHANNEL ADC_CHANNEL_6
|
||||
#define MOSFET_Temper_CHANNEL ADC_CHANNEL_15
|
||||
|
||||
void HD_adc_Init(void);
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef _W25Q256_H
|
||||
#define _W25Q256_H
|
||||
|
||||
#include "gpio.h"
|
||||
#include "main.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* 常量&宏定义 *
|
||||
*******************************************************************************/
|
||||
#define FLASH_CS_GPIO_Port GPIOA
|
||||
#define FLASH_CS_Pin FLASH_CS_Pin
|
||||
#define FLASH_CLK_GPIO_Port GPIOA
|
||||
#define FLASH_CLK_Pin FLASH_CLK_Pin
|
||||
#define FLASH_MISO_GPIO_Port GPIOA
|
||||
#define FLASH_MISO_Pin FLASH_MISO_Pin
|
||||
#define FLASH_MOSI_GPIO_Port GPIOA
|
||||
#define FLASH_MOSI_Pin FLASH_MOSI_Pin
|
||||
|
||||
#define FLASH_CS_ENABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET) /*片选使能*/
|
||||
#define FLASH_CS_DISABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_SET) /*片选失能*/
|
||||
|
||||
#define FLASH_CLK_HIGH HAL_GPIO_WritePin(FLASH_CLK_GPIO_Port, FLASH_CLK_Pin, GPIO_PIN_SET) /*时钟信号高*/
|
||||
#define FLASH_CLK_LOW HAL_GPIO_WritePin(FLASH_CLK_GPIO_Port, FLASH_CLK_Pin, GPIO_PIN_RESET) /*时钟信号低*/
|
||||
|
||||
#define FLASH_MISO_READ HAL_GPIO_ReadPin(FLASH_MISO_GPIO_Port, FLASH_MISO_Pin) /*MISO数据输入*/
|
||||
|
||||
#define FLASH_MOSI_HIGH HAL_GPIO_WritePin(FLASH_MOSI_GPIO_Port, FLASH_MOSI_Pin, GPIO_PIN_SET) /*MOSI数据引脚高电平*/
|
||||
#define FLASH_MOSI_LOW HAL_GPIO_WritePin(FLASH_MOSI_GPIO_Port, FLASH_MOSI_Pin, GPIO_PIN_RESET) /*MOSI数据引脚低电平*/
|
||||
|
||||
#define FLASH_W25Q128
|
||||
#ifdef FLASH_W25Q128
|
||||
#define Flash_ReadData_CMD 0x03
|
||||
#endif
|
||||
#ifdef FLASH_W25Q256
|
||||
#define Flash_ReadData_CMD 0x13
|
||||
#endif
|
||||
|
||||
#define FLASH_WRITE_BUSYBIT 0X01
|
||||
#define Flash_ReadID 0x90 /*读ID***16位*/
|
||||
#define Flash_ReadID_only 0x4b /*读唯一ID***64位*/
|
||||
#define Flash_Chip_Erase_CMD 0xC7 /*片擦除*/
|
||||
#define Flash_WriteEnable_CMD 0x06
|
||||
#define Flash_WriteDisable_CMD 0x04
|
||||
#define Flash_PageProgram_CMD 0x02
|
||||
#define Flash_WriteSR_CMD 0x01
|
||||
#define Flash_ReadSR_CMD 0x05
|
||||
#define Flash_SecErase_CMD 0x20
|
||||
#define Flash_BlockErase_CMD 0xD8
|
||||
#define W25Q_4ByteAddrModeEnable 0xB7
|
||||
#define W25Q_Exit4ByteAddrModeEnable 0xE9
|
||||
#define Flash_PAGEBYTE_LENGTH 256
|
||||
#define EXT_FLASH_SECTOR_SIZE (1024*4)
|
||||
#define EXT_FLASH_BLOCK_SIZE (1024*64)
|
||||
|
||||
/*******************************************************************************
|
||||
* 函数声明 *
|
||||
*******************************************************************************/
|
||||
/* w25q256相关引脚初始化 */
|
||||
void Flash_GPIO_Init(void);
|
||||
/* 扇区擦除 */
|
||||
void Flash_Erase_Block(uint8_t BlockNum);
|
||||
/* 块擦除 */
|
||||
void Flash_Erase_Sector(uint8_t Block_Num,uint8_t Sector_Number);
|
||||
/* 写数据 */
|
||||
void Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
void Flash_Write_MorePage(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
/* 读数据 */
|
||||
void Flash_Read(uint8_t *pBuffer,uint32_t ReadAddr,uint32_t ReadBytesNum);
|
||||
|
||||
void W25Q128_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
|
||||
#endif
|
|
@ -2,57 +2,121 @@
|
|||
|
||||
void HD_GPIO_Init(void)
|
||||
{
|
||||
// MX_GPIO_Init();
|
||||
// // MX_GPIO_Init();
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
// /* GPIO Ports Clock Enable */
|
||||
// __HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
// __HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
// __HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
// HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||||
// /*Configure GPIO pin Output Level */
|
||||
// // HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
|
||||
// /*Configure GPIO pin Output Level */
|
||||
// HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
|
||||
// /*Configure GPIO pin Output Level */
|
||||
// HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin : DSG_PROT_Pin */
|
||||
GPIO_InitStruct.Pin = DSG_PROT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
// /*Configure GPIO pin : DSG_PROT_Pin */
|
||||
// GPIO_InitStruct.Pin = DSG_PROT_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_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);
|
||||
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_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 pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_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);
|
||||
// GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_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 pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
|
||||
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_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 : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
|
||||
// GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_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 pin : WORK_VOLT_INT_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
// /*Configure GPIO pin : WORK_VOLT_INT_Pin */
|
||||
// GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
// HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
// /* EXTI interrupt init*/
|
||||
// HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
|
||||
// HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
// HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, EN_PWMOUT_Pin|FFMOS_CON_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin : DSG_PROT_Pin */
|
||||
GPIO_InitStruct.Pin = DSG_PROT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : FLASH_CS_Pin */
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
|
||||
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_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 : EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_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 : WORK_VOLT_INT_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : EXCHG_PROT_Pin */
|
||||
GPIO_InitStruct.Pin = EXCHG_PROT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(EXCHG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
}
|
|
@ -18,6 +18,29 @@ void HD_RTC_Init(void)
|
|||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
// RTC_TimeTypeDef sTime = {0};
|
||||
// RTC_DateTypeDef sDate = {0};
|
||||
|
||||
// sTime.Hours = 0;
|
||||
// sTime.Minutes = 0;
|
||||
// sTime.Seconds = 0;
|
||||
// sTime.SubSeconds = 0;
|
||||
// sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
// sTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
// if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
// {
|
||||
// Error_Handler();
|
||||
// }
|
||||
// sDate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
// sDate.Month = RTC_MONTH_JANUARY;
|
||||
// sDate.Date = 1;
|
||||
// sDate.Year = 0;
|
||||
|
||||
// if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
// {
|
||||
// Error_Handler();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,318 @@
|
|||
#include <string.h>
|
||||
#include "w25q256.h"
|
||||
|
||||
///@brief Flash相关引脚初始化
|
||||
void Flash_GPIO_Init(void)
|
||||
{
|
||||
FLASH_CS_DISABLE;
|
||||
FLASH_CLK_HIGH;
|
||||
FLASH_MOSI_LOW;
|
||||
}
|
||||
|
||||
///@brief 读取一个字节数据
|
||||
static uint8_t Flash_ReadOneByte(void)
|
||||
{
|
||||
uint8_t retValue = 0;
|
||||
|
||||
FLASH_CLK_HIGH; //时钟线拉高,恢复时钟线为高电平
|
||||
for(uint8_t i= 0; i < 8; i++)
|
||||
{
|
||||
retValue <<= 1;
|
||||
FLASH_CLK_HIGH; //时钟线拉高,恢复时钟线为高电平
|
||||
if(FLASH_MISO_READ)
|
||||
{
|
||||
retValue |= 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
retValue &= 0xFE;
|
||||
}
|
||||
FLASH_CLK_LOW; //时钟线拉低,产生下降沿读出数据
|
||||
}
|
||||
FLASH_CLK_HIGH;
|
||||
|
||||
return (retValue);
|
||||
}
|
||||
|
||||
///@brief 写入一个字节
|
||||
static void Flash_WriteOneByte(uint8_t DataBuffer)
|
||||
{
|
||||
FLASH_CLK_LOW; //时钟线拉低,恢复时钟线为低电平
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
FLASH_CLK_LOW; //时钟线拉低,恢复时钟线为低电平
|
||||
if(DataBuffer & 0x80)
|
||||
{
|
||||
FLASH_MOSI_HIGH;
|
||||
}
|
||||
else
|
||||
{
|
||||
FLASH_MOSI_LOW;
|
||||
}
|
||||
DataBuffer <<= 1;
|
||||
FLASH_CLK_HIGH; //时钟线拉高,产生上升沿写入数据
|
||||
}
|
||||
FLASH_CLK_LOW;
|
||||
FLASH_MOSI_HIGH; //一字节数据传送完毕,MOSI数据线置高表示空闲状态
|
||||
}
|
||||
|
||||
///@brief 写指令
|
||||
static void Flash_Write_CMD(uint8_t *pCMD)
|
||||
{
|
||||
#ifdef FLASH_W25Q256
|
||||
for(uint8_t i = 0; i < 4; i++) //new add
|
||||
{
|
||||
Flash_WriteOneByte(pCMD[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
for(uint8_t i = 0; i < 3; i++) //new add
|
||||
{
|
||||
Flash_WriteOneByte(pCMD[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
///@brief 读取SR
|
||||
static uint8_t Flash_ReadSR(void)
|
||||
{
|
||||
uint8_t retValue = 0;
|
||||
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_ReadSR_CMD);
|
||||
retValue = Flash_ReadOneByte();
|
||||
FLASH_CS_DISABLE;
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
///@brief 等待标志位
|
||||
static void Flash_Wait_Busy(void)
|
||||
{
|
||||
uint32_t i =0;
|
||||
|
||||
while(((Flash_ReadSR() & FLASH_WRITE_BUSYBIT) == 0x01) && (i<0x1ffff))
|
||||
{
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
///@brief 写使能
|
||||
static void Flash_Write_Enable(void)
|
||||
{
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_WriteEnable_CMD);
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
///@brief 进入4字节模式
|
||||
void Enter4ByteAddrMode(void)
|
||||
{
|
||||
FLASH_CS_ENABLE; //使能器件
|
||||
Flash_WriteOneByte(W25Q_4ByteAddrModeEnable); //进入4Byte地址模式W25Q128以上使用
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
|
||||
///@brief 退出4字节模式
|
||||
void Exit4ByteAddrMode(void)
|
||||
{
|
||||
FLASH_CS_ENABLE; //使能器件
|
||||
Flash_WriteOneByte(W25Q_Exit4ByteAddrModeEnable); //进入4Byte地址模式W25Q128以上使用
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
#endif
|
||||
|
||||
///@brief 擦除区域
|
||||
void Flash_Erase_Sector(uint8_t Block_Num,uint8_t Sector_Number)
|
||||
{
|
||||
uint8_t pcmd[3] = {0};
|
||||
Flash_Write_Enable();
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_SecErase_CMD);
|
||||
|
||||
pcmd[0] = Block_Num;
|
||||
pcmd[1] = Sector_Number<<4;
|
||||
pcmd[2] = 0;
|
||||
Flash_Write_CMD(pcmd);
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy();//每次擦除数据都要延时等待写入结束
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
///@brief 擦除块
|
||||
void Flash_Erase_Block(uint8_t BlockNum)
|
||||
{
|
||||
|
||||
uint8_t pcmd[3] = {0};
|
||||
Flash_Write_Enable(); //写使能
|
||||
FLASH_CS_ENABLE; //片选拉低
|
||||
Flash_WriteOneByte(Flash_BlockErase_CMD); //传输Block擦除指令
|
||||
pcmd[0] = BlockNum ; //传24位地址
|
||||
Flash_Write_CMD(pcmd);
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy(); //每次擦除数据都要延时等待写入结束
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
///@brief 页写
|
||||
void Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
uint8_t pcmd[4] = {0};
|
||||
|
||||
Flash_Write_Enable();
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_PageProgram_CMD);
|
||||
#ifdef FLASH_W25Q256
|
||||
pcmd[0] = (uint8_t)((WriteAddr&0xff000000)>>24); //new add
|
||||
pcmd[1] = (uint8_t)((WriteAddr&0x00ff0000)>>16);
|
||||
pcmd[2] = (uint8_t)((WriteAddr&0x0000ff00)>>8);
|
||||
pcmd[3] = (uint8_t)WriteAddr;
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
pcmd[0] = (uint8_t)((WriteAddr&0x00ff0000)>>16);
|
||||
pcmd[1] = (uint8_t)((WriteAddr&0x0000ff00)>>8);
|
||||
pcmd[2] = (uint8_t)WriteAddr;
|
||||
#endif
|
||||
|
||||
Flash_Write_CMD(pcmd);
|
||||
|
||||
for(uint32_t i = 0;i < WriteBytesNum; i++)
|
||||
{
|
||||
|
||||
Flash_WriteOneByte(pBuffer[i]); //向Flash中写入最大一页256bytes字节数据
|
||||
}
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy(); //每次写入一定数量的数据都要延时等待写入结束
|
||||
return;
|
||||
}
|
||||
|
||||
///@brief 连续写入多页
|
||||
void Flash_Write_MorePage(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
uint16_t PageByteRemain = 0;
|
||||
PageByteRemain = Flash_PAGEBYTE_LENGTH - WriteAddr%Flash_PAGEBYTE_LENGTH;
|
||||
if(WriteBytesNum <= PageByteRemain)
|
||||
{
|
||||
PageByteRemain = WriteBytesNum;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
Flash_Write_Page(pBuffer,WriteAddr,PageByteRemain);
|
||||
if(WriteBytesNum == PageByteRemain)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pBuffer += PageByteRemain;
|
||||
WriteAddr += PageByteRemain;
|
||||
WriteBytesNum -= PageByteRemain;
|
||||
if(WriteBytesNum > Flash_PAGEBYTE_LENGTH)
|
||||
{
|
||||
PageByteRemain = Flash_PAGEBYTE_LENGTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
PageByteRemain = WriteBytesNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
///@brief 连续写入多页
|
||||
uint8_t W25QXX_BUFFER[4096];
|
||||
void W25Q128_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
// volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5, timeReadTemp6;
|
||||
|
||||
uint32_t secpos;
|
||||
uint16_t secoff;
|
||||
uint16_t secremain;
|
||||
uint16_t i;
|
||||
uint8_t *W25QXX_BUF;
|
||||
W25QXX_BUF = W25QXX_BUFFER;
|
||||
secpos = WriteAddr / 4096; //扇区地址
|
||||
secoff = WriteAddr % 4096; //在扇区内的偏移
|
||||
secremain = 4096 - secoff; //扇区剩余空间大小
|
||||
if (WriteBytesNum <= secremain)
|
||||
secremain = WriteBytesNum; //不大于4096个字节
|
||||
while (1)
|
||||
{
|
||||
// timeReadTemp1 = HAL_GetTick();
|
||||
Flash_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //校验数据
|
||||
{
|
||||
if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
break; //需要擦除
|
||||
}
|
||||
if (i < secremain) //需要擦除
|
||||
{
|
||||
Flash_Erase_Block(secpos); //擦除这个扇区
|
||||
// timeReadTemp3 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //复制
|
||||
{
|
||||
W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
}
|
||||
Flash_Write_Page(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
// timeReadTemp4 = HAL_GetTick();
|
||||
// timeReadTemp5 = NumByteToWrite;
|
||||
// timeReadTemp6 = WriteAddr;
|
||||
}
|
||||
else
|
||||
Flash_Write_Page(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
if (WriteBytesNum == secremain)
|
||||
break; //写入结束了
|
||||
else //写入未结束
|
||||
{
|
||||
secpos++; //扇区地址增1
|
||||
secoff = 0; //偏移位置为0
|
||||
|
||||
pBuffer += secremain; //指针偏移
|
||||
WriteAddr += secremain; //写地址偏移
|
||||
WriteBytesNum -= secremain; //字节数递减
|
||||
if (WriteBytesNum > 4096)
|
||||
secremain = 4096; //下一个扇区还是写不完
|
||||
else
|
||||
secremain = WriteBytesNum; //下一个扇区可以写完了
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///@brief 读取数据
|
||||
void Flash_Read(uint8_t *pBuffer,uint32_t ReadAddr,uint32_t ReadBytesNum)
|
||||
{
|
||||
uint8_t pcmd[4] = {0};
|
||||
FLASH_CS_ENABLE; //打开spiflash片选
|
||||
Flash_WriteOneByte(Flash_ReadData_CMD);
|
||||
#ifdef FLASH_W25Q256
|
||||
pcmd[0] = (uint8_t)((ReadAddr&0xff000000)>>24); //new add
|
||||
pcmd[1] = (uint8_t)((ReadAddr&0x00ff0000)>>16);
|
||||
pcmd[2] = (uint8_t)((ReadAddr&0x0000ff00)>>8);
|
||||
pcmd[3] = (uint8_t)ReadAddr;
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
pcmd[0] = (uint8_t)((ReadAddr&0x00ff0000)>>16);
|
||||
pcmd[1] = (uint8_t)((ReadAddr&0x0000ff00)>>8);
|
||||
pcmd[2] = (uint8_t)ReadAddr;
|
||||
#endif
|
||||
|
||||
Flash_Write_CMD(pcmd);
|
||||
|
||||
for(uint32_t i = 0;i < ReadBytesNum; i++)
|
||||
{
|
||||
pBuffer[i] = Flash_ReadOneByte(); //读取SPIflash中指定bytes字节数据
|
||||
|
||||
}
|
||||
FLASH_CS_DISABLE;
|
||||
|
||||
return ;
|
||||
}
|
|
@ -161,17 +161,25 @@ void W25QXX_ReadUniqueID(uint8_t UID[8])
|
|||
//NumByteToRead:要读取的字节数(最大65535)
|
||||
void W25QXX_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5;
|
||||
timeReadTemp1 = HAL_GetTick();
|
||||
|
||||
uint16_t i;
|
||||
W25QXX_CS_L(); //使能器件
|
||||
W25QXX_SPI_ReadWriteByte(W25X_ReadData); //发送读取命令
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)((ReadAddr) >> 16)); //发送24bit地址
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)((ReadAddr) >> 8));
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)ReadAddr);
|
||||
timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < NumByteToRead; i++)
|
||||
{
|
||||
pBuffer[i] = W25QXX_SPI_ReadWriteByte(0XFF); //循环读数
|
||||
}
|
||||
W25QXX_CS_H();
|
||||
|
||||
timeReadTemp3 = HAL_GetTick();
|
||||
timeReadTemp4 = NumByteToRead;
|
||||
timeReadTemp5 = ReadAddr;
|
||||
}
|
||||
//SPI在一页(0~65535)内写入少于256个字节的数据
|
||||
//在指定地址开始写入最大256字节的数据
|
||||
|
@ -233,6 +241,8 @@ void W25QXX_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByte
|
|||
uint8_t W25QXX_BUFFER[4096];
|
||||
void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
// volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5, timeReadTemp6;
|
||||
|
||||
uint32_t secpos;
|
||||
uint16_t secoff;
|
||||
uint16_t secremain;
|
||||
|
@ -246,7 +256,10 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
secremain = NumByteToWrite; //不大于4096个字节
|
||||
while (1)
|
||||
{
|
||||
|
||||
// timeReadTemp1 = HAL_GetTick();
|
||||
W25QXX_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //校验数据
|
||||
{
|
||||
if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
|
@ -255,12 +268,15 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
if (i < secremain) //需要擦除
|
||||
{
|
||||
W25QXX_Erase_Sector(secpos); //擦除这个扇区
|
||||
// timeReadTemp3 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //复制
|
||||
{
|
||||
W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
}
|
||||
W25QXX_Write_NoCheck(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
|
||||
// timeReadTemp4 = HAL_GetTick();
|
||||
// timeReadTemp5 = NumByteToWrite;
|
||||
// timeReadTemp6 = WriteAddr;
|
||||
}
|
||||
else
|
||||
W25QXX_Write_NoCheck(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
|
@ -280,6 +296,42 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
secremain = NumByteToWrite; //下一个扇区可以写完了
|
||||
}
|
||||
};
|
||||
|
||||
// while (1) {
|
||||
// W25QXX_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// // for (i = 0; i < secremain; i++) //校验数据
|
||||
// // {
|
||||
// // if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
// // break; //需要擦除
|
||||
// // }
|
||||
// // if (i < secremain) //需要擦除
|
||||
// // {
|
||||
// W25QXX_Erase_Sector(secpos); //擦除这个扇区
|
||||
// for (i = 0; i < secremain; i++) //复制
|
||||
// {
|
||||
// W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
// }
|
||||
// W25QXX_Write_NoCheck(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
|
||||
// // }
|
||||
// // else
|
||||
// // W25QXX_Write_NoCheck(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
// if (NumByteToWrite == secremain)
|
||||
// break; //写入结束了
|
||||
// else //写入未结束
|
||||
// {
|
||||
// secpos++; //扇区地址增1
|
||||
// secoff = 0; //偏移位置为0
|
||||
|
||||
// pBuffer += secremain; //指针偏移
|
||||
// WriteAddr += secremain; //写地址偏移
|
||||
// NumByteToWrite -= secremain; //字节数递减
|
||||
// if (NumByteToWrite > 4096)
|
||||
// secremain = 4096; //下一个扇区还是写不完
|
||||
// else
|
||||
// secremain = NumByteToWrite; //下一个扇区可以写完了
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
||||
//擦除整个芯片
|
||||
|
|
|
@ -60,12 +60,12 @@ void Error_Handler(void);
|
|||
#define DSG_PROT_Pin GPIO_PIN_13
|
||||
#define DSG_PROT_GPIO_Port GPIOC
|
||||
#define DSG_PROT_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define EXCHG_CURR_Pin GPIO_PIN_0
|
||||
#define EXCHG_CURR_GPIO_Port GPIOC
|
||||
#define WORK_VOLT_Pin GPIO_PIN_1
|
||||
#define WORK_VOLT_GPIO_Port GPIOC
|
||||
#define DSG_CURR_Pin GPIO_PIN_2
|
||||
#define DSG_CURR_GPIO_Port GPIOC
|
||||
#define OUT_VOLT_IN_Pin GPIO_PIN_3
|
||||
#define OUT_VOLT_IN_GPIO_Port GPIOC
|
||||
#define SYS_VOLT_IN_Pin GPIO_PIN_0
|
||||
#define SYS_VOLT_IN_GPIO_Port GPIOA
|
||||
#define GW485_RDE_Pin GPIO_PIN_1
|
||||
|
@ -76,8 +76,8 @@ void Error_Handler(void);
|
|||
#define GW485_RX_GPIO_Port GPIOA
|
||||
#define FLASH_CS_Pin GPIO_PIN_4
|
||||
#define FLASH_CS_GPIO_Port GPIOA
|
||||
#define FLASH_CLK_Pin GPIO_PIN_5
|
||||
#define FLASH_CLK_GPIO_Port GPIOA
|
||||
#define FLASH_SCK_Pin GPIO_PIN_5
|
||||
#define FLASH_SCK_GPIO_Port GPIOA
|
||||
#define FLASH_MISO_Pin GPIO_PIN_6
|
||||
#define FLASH_MISO_GPIO_Port GPIOA
|
||||
#define FLASH_MOSI_Pin GPIO_PIN_7
|
||||
|
@ -109,6 +109,9 @@ void Error_Handler(void);
|
|||
#define DEBUG_TX_GPIO_Port GPIOC
|
||||
#define DEBUG_RX_Pin GPIO_PIN_11
|
||||
#define DEBUG_RX_GPIO_Port GPIOC
|
||||
#define EXCHG_PROT_Pin GPIO_PIN_5
|
||||
#define EXCHG_PROT_GPIO_Port GPIOB
|
||||
#define EXCHG_PROT_EXTI_IRQn EXTI9_5_IRQn
|
||||
#define RUN_LED_Pin GPIO_PIN_6
|
||||
#define RUN_LED_GPIO_Port GPIOB
|
||||
#define POW_FF_CON_Pin GPIO_PIN_7
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
|
|
@ -56,6 +56,7 @@ void DebugMon_Handler(void);
|
|||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void DMA1_Channel1_IRQHandler(void);
|
||||
void EXTI9_5_IRQHandler(void);
|
||||
void TIM1_BRK_TIM15_IRQHandler(void);
|
||||
void TIM1_UP_TIM16_IRQHandler(void);
|
||||
void USART2_IRQHandler(void);
|
||||
|
|
|
@ -267,14 +267,14 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**ADC2 GPIO Configuration
|
||||
PC3 ------> ADC2_IN9
|
||||
PC0 ------> ADC2_IN6
|
||||
PA0 ------> ADC2_IN1
|
||||
PB15 ------> ADC2_IN15
|
||||
*/
|
||||
GPIO_InitStruct.Pin = OUT_VOLT_IN_Pin;
|
||||
GPIO_InitStruct.Pin = EXCHG_CURR_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(OUT_VOLT_IN_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(EXCHG_CURR_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = SYS_VOLT_IN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
|
@ -334,11 +334,11 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|||
}
|
||||
|
||||
/**ADC2 GPIO Configuration
|
||||
PC3 ------> ADC2_IN9
|
||||
PC0 ------> ADC2_IN6
|
||||
PA0 ------> ADC2_IN1
|
||||
PB15 ------> ADC2_IN15
|
||||
*/
|
||||
HAL_GPIO_DeInit(OUT_VOLT_IN_GPIO_Port, OUT_VOLT_IN_Pin);
|
||||
HAL_GPIO_DeInit(EXCHG_CURR_GPIO_Port, EXCHG_CURR_Pin);
|
||||
|
||||
HAL_GPIO_DeInit(SYS_VOLT_IN_GPIO_Port, SYS_VOLT_IN_Pin);
|
||||
|
||||
|
|
|
@ -61,16 +61,16 @@ void MX_GPIO_Init(void)
|
|||
|
||||
/*Configure GPIO pin : DSG_PROT_Pin */
|
||||
GPIO_InitStruct.Pin = DSG_PROT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_Pin;
|
||||
/*Configure GPIO pin : FLASH_CS_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_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);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
|
||||
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
|
||||
|
@ -79,13 +79,29 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_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 : WORK_VOLT_INT_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : EXCHG_PROT_Pin */
|
||||
GPIO_InitStruct.Pin = EXCHG_PROT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(EXCHG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
|
||||
|
|
|
@ -95,22 +95,24 @@ int main(void)
|
|||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
// MX_GPIO_Init();
|
||||
// MX_DMA_Init();
|
||||
// MX_ADC1_Init();
|
||||
// MX_ADC2_Init();
|
||||
// MX_SPI1_Init();
|
||||
// MX_TIM3_Init();
|
||||
// MX_TIM6_Init();
|
||||
// MX_UART4_Init();
|
||||
// MX_USART2_UART_Init();
|
||||
// MX_USART3_UART_Init();
|
||||
// MX_TIM7_Init();
|
||||
// MX_TIM16_Init();
|
||||
// MX_TIM15_Init();
|
||||
// MX_RTC_Init();
|
||||
// MX_GPIO_Init();
|
||||
// MX_DMA_Init();
|
||||
// MX_ADC1_Init();
|
||||
// MX_ADC2_Init();
|
||||
// MX_TIM3_Init();
|
||||
// MX_TIM6_Init();
|
||||
// MX_UART4_Init();
|
||||
// MX_USART2_UART_Init();
|
||||
// MX_USART3_UART_Init();
|
||||
// MX_TIM7_Init();
|
||||
// MX_TIM16_Init();
|
||||
// MX_TIM15_Init();
|
||||
// MX_RTC_Init();
|
||||
// MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
// while (1) {
|
||||
// };
|
||||
start();
|
||||
|
||||
|
||||
|
@ -142,17 +144,21 @@ void SystemClock_Config(void)
|
|||
*/
|
||||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Configure LSE Drive Capability
|
||||
*/
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
|
||||
RCC_OscInitStruct.PLL.PLLN = 9;
|
||||
RCC_OscInitStruct.PLL.PLLN = 18;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||
|
@ -190,7 +196,7 @@ void Error_Handler(void)
|
|||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1)
|
||||
{
|
||||
{
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
|
|
@ -101,7 +101,7 @@ void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
|
|||
/** Initializes the peripherals clocks
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
@ -41,16 +41,16 @@ void MX_SPI1_Init(void)
|
|||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 7;
|
||||
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
@ -79,10 +79,10 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
|||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = FLASH_CLK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin;
|
||||
GPIO_InitStruct.Pin = FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
|
@ -108,7 +108,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
|||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, FLASH_CLK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin);
|
||||
HAL_GPIO_DeInit(GPIOA, FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ void NMI_Handler(void)
|
|||
void HardFault_Handler(void)
|
||||
{
|
||||
/* USER CODE BEGIN HardFault_IRQn 0 */
|
||||
|
||||
NVIC_SystemReset();
|
||||
/* USER CODE END HardFault_IRQn 0 */
|
||||
while (1)
|
||||
{
|
||||
|
@ -217,6 +217,20 @@ void DMA1_Channel1_IRQHandler(void)
|
|||
/* USER CODE END DMA1_Channel1_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles EXTI line[9:5] interrupts.
|
||||
*/
|
||||
void EXTI9_5_IRQHandler(void)
|
||||
{
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 0 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 0 */
|
||||
HAL_GPIO_EXTI_IRQHandler(EXCHG_PROT_Pin);
|
||||
/* USER CODE BEGIN EXTI9_5_IRQn 1 */
|
||||
|
||||
/* USER CODE END EXTI9_5_IRQn 1 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles TIM1 break interrupt and TIM15 global interrupt.
|
||||
*/
|
||||
|
|
|
@ -47,7 +47,7 @@ void MX_TIM3_Init(void)
|
|||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 0;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 720;
|
||||
htim3.Init.Period = 719;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim3) != HAL_OK)
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1449,10 +1449,7 @@
|
|||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\cfg_protocol.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\hy_protocol.c</name>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\bl_usart.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c</name>
|
||||
|
@ -1466,6 +1463,12 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\parameter.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\soc.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\SOE.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\task.c</name>
|
||||
</file>
|
||||
|
|
|
@ -109,25 +109,26 @@ Mcu.Pin28=PA14
|
|||
Mcu.Pin29=PC10
|
||||
Mcu.Pin3=PF0-OSC_IN
|
||||
Mcu.Pin30=PC11
|
||||
Mcu.Pin31=PB6
|
||||
Mcu.Pin32=PB7
|
||||
Mcu.Pin33=PB9
|
||||
Mcu.Pin34=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin35=VP_RTC_VS_RTC_Calendar
|
||||
Mcu.Pin36=VP_SYS_VS_Systick
|
||||
Mcu.Pin37=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin38=VP_TIM6_VS_ClockSourceINT
|
||||
Mcu.Pin39=VP_TIM7_VS_ClockSourceINT
|
||||
Mcu.Pin31=PB5
|
||||
Mcu.Pin32=PB6
|
||||
Mcu.Pin33=PB7
|
||||
Mcu.Pin34=PB9
|
||||
Mcu.Pin35=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin36=VP_RTC_VS_RTC_Calendar
|
||||
Mcu.Pin37=VP_SYS_VS_Systick
|
||||
Mcu.Pin38=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin39=VP_TIM6_VS_ClockSourceINT
|
||||
Mcu.Pin4=PF1-OSC_OUT
|
||||
Mcu.Pin40=VP_TIM15_VS_ClockSourceINT
|
||||
Mcu.Pin41=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin42=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
|
||||
Mcu.Pin5=PC1
|
||||
Mcu.Pin6=PC2
|
||||
Mcu.Pin7=PC3
|
||||
Mcu.Pin40=VP_TIM7_VS_ClockSourceINT
|
||||
Mcu.Pin41=VP_TIM15_VS_ClockSourceINT
|
||||
Mcu.Pin42=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin43=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
|
||||
Mcu.Pin5=PC0
|
||||
Mcu.Pin6=PC1
|
||||
Mcu.Pin7=PC2
|
||||
Mcu.Pin8=PA0
|
||||
Mcu.Pin9=PA1
|
||||
Mcu.PinsNb=43
|
||||
Mcu.PinsNb=44
|
||||
Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
|
||||
Mcu.ThirdPartyNb=1
|
||||
Mcu.UserConstants=
|
||||
|
@ -138,6 +139,7 @@ NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
|||
NVIC.DMA1_Channel1_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true
|
||||
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.EXTI15_10_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.EXTI9_5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true
|
||||
NVIC.ForceEnableDMAVector=true
|
||||
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
|
@ -194,20 +196,24 @@ PA3.GPIO_PuPd=GPIO_PULLUP
|
|||
PA3.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
|
||||
PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA4.GPIOParameters=GPIO_Label
|
||||
PA4.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA4.GPIO_Label=FLASH_CS
|
||||
PA4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA4.Locked=true
|
||||
PA4.Signal=GPIO_Output
|
||||
PA5.GPIOParameters=GPIO_Label
|
||||
PA5.GPIO_Label=FLASH_CLK
|
||||
PA5.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA5.GPIO_Label=FLASH_SCK
|
||||
PA5.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA5.Mode=Full_Duplex_Master
|
||||
PA5.Signal=SPI1_SCK
|
||||
PA6.GPIOParameters=GPIO_Label
|
||||
PA6.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA6.GPIO_Label=FLASH_MISO
|
||||
PA6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA6.Mode=Full_Duplex_Master
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.GPIOParameters=GPIO_Label
|
||||
PA7.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA7.GPIO_Label=FLASH_MOSI
|
||||
PA7.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PB0.GPIOParameters=GPIO_Label
|
||||
|
@ -242,6 +248,12 @@ PB15.GPIOParameters=GPIO_Label
|
|||
PB15.GPIO_Label=MOSFET_Temper
|
||||
PB15.Mode=IN15-Single-Ended
|
||||
PB15.Signal=ADC2_IN15
|
||||
PB5.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
|
||||
PB5.GPIO_Label=EXCHG_PROT
|
||||
PB5.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING
|
||||
PB5.GPIO_PuPd=GPIO_PULLDOWN
|
||||
PB5.Locked=true
|
||||
PB5.Signal=GPXTI5
|
||||
PB6.GPIOParameters=GPIO_Label
|
||||
PB6.GPIO_Label=RUN_LED
|
||||
PB6.Locked=true
|
||||
|
@ -254,6 +266,11 @@ PB9.GPIOParameters=GPIO_Label
|
|||
PB9.GPIO_Label=POW_OUT_CON
|
||||
PB9.Locked=true
|
||||
PB9.Signal=GPIO_Output
|
||||
PC0.GPIOParameters=GPIO_Label
|
||||
PC0.GPIO_Label=EXCHG_CURR
|
||||
PC0.Locked=true
|
||||
PC0.Mode=IN6-Single-Ended
|
||||
PC0.Signal=ADC2_IN6
|
||||
PC1.GPIOParameters=GPIO_Label
|
||||
PC1.GPIO_Label=WORK_VOLT
|
||||
PC1.Locked=true
|
||||
|
@ -269,8 +286,8 @@ PC11.Mode=Asynchronous
|
|||
PC11.Signal=UART4_RX
|
||||
PC13.GPIOParameters=GPIO_PuPd,GPIO_Label,GPIO_ModeDefaultEXTI
|
||||
PC13.GPIO_Label=DSG_PROT
|
||||
PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
||||
PC13.GPIO_PuPd=GPIO_PULLUP
|
||||
PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_RISING
|
||||
PC13.GPIO_PuPd=GPIO_PULLDOWN
|
||||
PC13.Locked=true
|
||||
PC13.Signal=GPXTI13
|
||||
PC14-OSC32_IN.Mode=LSE-External-Oscillator
|
||||
|
@ -281,11 +298,6 @@ PC2.GPIOParameters=GPIO_Label
|
|||
PC2.GPIO_Label=DSG_CURR
|
||||
PC2.Mode=IN8-Single-Ended
|
||||
PC2.Signal=ADC1_IN8
|
||||
PC3.GPIOParameters=GPIO_Label
|
||||
PC3.GPIO_Label=OUT_VOLT_IN
|
||||
PC3.Locked=true
|
||||
PC3.Mode=IN9-Single-Ended
|
||||
PC3.Signal=ADC2_IN9
|
||||
PC9.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PC9.GPIO_Label=CHG_CONH
|
||||
PC9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||
|
@ -326,7 +338,7 @@ ProjectManager.ToolChainLocation=
|
|||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM15_Init-TIM15-false-HAL-true,15-MX_RTC_Init-RTC-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true,7-MX_TIM6_Init-TIM6-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USART2_UART_Init-USART2-false-HAL-true,10-MX_USART3_UART_Init-USART3-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_TIM16_Init-TIM16-false-HAL-true,13-MX_TIM15_Init-TIM15-false-HAL-true,14-MX_RTC_Init-RTC-false-HAL-true,15-MX_SPI1_Init-SPI1-false-HAL-true
|
||||
RCC.ADC12Freq_Value=72000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
RCC.APB1Freq_Value=72000000
|
||||
|
@ -347,19 +359,21 @@ RCC.I2C1Freq_Value=72000000
|
|||
RCC.I2C2Freq_Value=72000000
|
||||
RCC.I2C3Freq_Value=72000000
|
||||
RCC.I2SFreq_Value=72000000
|
||||
RCC.IPParameters=ADC12Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,RNGFreq_Value,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
|
||||
RCC.IPParameters=ADC12Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
|
||||
RCC.LPTIM1Freq_Value=72000000
|
||||
RCC.LPUART1Freq_Value=72000000
|
||||
RCC.LSCOPinFreq_Value=32000
|
||||
RCC.LSI_VALUE=32000
|
||||
RCC.MCO1PinFreq_Value=16000000
|
||||
RCC.PLLN=9
|
||||
RCC.PLLN=18
|
||||
RCC.PLLPoutputFreq_Value=72000000
|
||||
RCC.PLLQoutputFreq_Value=72000000
|
||||
RCC.PLLRCLKFreq_Value=72000000
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.PWRFreq_Value=72000000
|
||||
RCC.RNGFreq_Value=72000000
|
||||
RCC.RTCFreq_Value=32000
|
||||
RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE
|
||||
RCC.RTCFreq_Value=32768
|
||||
RCC.SAI1Freq_Value=72000000
|
||||
RCC.SYSCLKFreq_VALUE=72000000
|
||||
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
|
@ -368,7 +382,7 @@ RCC.USART1Freq_Value=72000000
|
|||
RCC.USART2Freq_Value=72000000
|
||||
RCC.USART3Freq_Value=72000000
|
||||
RCC.USBFreq_Value=72000000
|
||||
RCC.VCOInputFreq_Value=16000000
|
||||
RCC.VCOInputFreq_Value=8000000
|
||||
RCC.VCOOutputFreq_Value=144000000
|
||||
RTC.Format=RTC_FORMAT_BIN
|
||||
RTC.IPParameters=Format,WeekDay
|
||||
|
@ -377,15 +391,14 @@ SH.GPXTI12.0=GPIO_EXTI12
|
|||
SH.GPXTI12.ConfNb=1
|
||||
SH.GPXTI13.0=GPIO_EXTI13
|
||||
SH.GPXTI13.ConfNb=1
|
||||
SH.GPXTI5.0=GPIO_EXTI5
|
||||
SH.GPXTI5.ConfNb=1
|
||||
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
|
||||
SH.S_TIM3_CH4.ConfNb=1
|
||||
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
||||
SPI1.CLKPhase=SPI_PHASE_2EDGE
|
||||
SPI1.CLKPolarity=SPI_POLARITY_HIGH
|
||||
SPI1.CalculateBaudRate=18.0 MBits/s
|
||||
SPI1.CalculateBaudRate=36.0 MBits/s
|
||||
SPI1.DataSize=SPI_DATASIZE_8BIT
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPolarity,CLKPhase
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true
|
||||
|
@ -400,7 +413,7 @@ TIM16.PeriodNoDither=999
|
|||
TIM16.Prescaler=71
|
||||
TIM3.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
||||
TIM3.IPParameters=PeriodNoDither,Channel-PWM Generation4 CH4
|
||||
TIM3.PeriodNoDither=720
|
||||
TIM3.PeriodNoDither=719
|
||||
TIM6.IPParameters=Prescaler,PeriodNoDither,TIM_MasterOutputTrigger
|
||||
TIM6.PeriodNoDither=9
|
||||
TIM6.Prescaler=71
|
||||
|
|
|
@ -13,12 +13,11 @@ typedef enum _chargMode{
|
|||
}chargMode;
|
||||
|
||||
typedef enum {
|
||||
mosTemperStart = 0, /* 满功率充电mos状态 */
|
||||
mosTemperEnd = 1, /* 降功率充电mos状态 */
|
||||
mosTemperFull = 0, /* 满功率充电mos状态 */
|
||||
mosTemperReduce = 1, /* 降功率充电mos状态 */
|
||||
mosTemperStop = 2, /* 停止充电mos状态 */
|
||||
}mosTState;
|
||||
|
||||
|
||||
/* 注册状态 */
|
||||
typedef enum {
|
||||
UNREGISTER = 0, /* 未注册 */
|
||||
|
@ -55,7 +54,6 @@ typedef enum {
|
|||
runLedOtherMode = 2, //其他模式
|
||||
}runLedMode;
|
||||
|
||||
|
||||
/* 顺序事件记录 */
|
||||
typedef enum {
|
||||
firstStageProtection = 1, //第一段保护,短路保护
|
||||
|
@ -65,6 +63,12 @@ typedef enum {
|
|||
overTemperature, //过温保护
|
||||
stopTemperature, //停止温度保护
|
||||
overchargCurr, //充电电流过大保护
|
||||
overInputVolt, //太阳能输入电压过大保护
|
||||
hardwareShortCircuitProtection, //硬件短路保护
|
||||
hardwareInputProtection, //硬件防反输入保护
|
||||
InputProtection, //软件防反输入保护
|
||||
startEvent, //启动
|
||||
abnormalControl, //异常控制
|
||||
}eventsOrderRecordMode;
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "comm_types.h"
|
||||
|
||||
|
||||
#define softVer "SV01_24101501"
|
||||
|
||||
// /* 第一段保护的延时时间(单位100uS) */
|
||||
// const uint32_t firstStageProtectionDelay = 2; // 200uS
|
||||
|
@ -64,4 +65,8 @@
|
|||
/* 最大充电电压(V) */
|
||||
#define maxOpenSolarOpenCircuitVMacro 25.0f
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
// #define NDEBUG
|
||||
|
||||
#define log_info_enable 1
|
||||
#define log_warn_enable 0
|
||||
#define log_error_enable 0
|
||||
#define log_warn_enable 1
|
||||
#define log_error_enable 1
|
||||
|
||||
/* Comment out this define to include log messages */
|
||||
// #define NLOG
|
||||
|
|
Loading…
Reference in New Issue