diff --git a/APP/businessLogic/Inc/abnormalManage.h b/APP/businessLogic/Inc/abnormalManage.h index a8593e6..37f8327 100644 --- a/APP/businessLogic/Inc/abnormalManage.h +++ b/APP/businessLogic/Inc/abnormalManage.h @@ -28,6 +28,6 @@ void checkAbnormal(void); void WORK_VOLT_Interrupt(void); void DSG_PROT_Interrupt(void); - +void EXCHG_PROT_Interrupt(void); #endif \ No newline at end of file diff --git a/APP/businessLogic/Inc/bl_usart.h b/APP/businessLogic/Inc/bl_usart.h index 7f54be5..8f55528 100644 --- a/APP/businessLogic/Inc/bl_usart.h +++ b/APP/businessLogic/Inc/bl_usart.h @@ -14,7 +14,7 @@ /* SL协议读取寄存器最小地址 */ #define minReadRegAddrMacro 0x0100 /* SL协议读取寄存器最大长度 */ -#define maxReadRegAddrNumMacro 10 +#define maxReadRegAddrNumMacro 80 /* SL协议写入寄存器最大地址 */ @@ -30,7 +30,7 @@ /* SL协议下发配置文件内容最长长度 */ #define maxDistributionCfgLen 230 /* SL协议读取配置文件内容最长长度 */ -#define maxReadCfgLen 32 +#define maxReadCfgLen 80 #define floatMagnification 10.0f diff --git a/APP/businessLogic/Inc/inFlash.h b/APP/businessLogic/Inc/inFlash.h index 22403ff..709302b 100644 --- a/APP/businessLogic/Inc/inFlash.h +++ b/APP/businessLogic/Inc/inFlash.h @@ -86,7 +86,7 @@ typedef struct _config_info{ uint8_t uniqueDeviceID[7]; /* 设备唯一ID */ uint32_t gw485_Baud; /* 串口波特率 */ - uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */ + uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */ uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0x01:是*/ float constantVoltageV; /* 恒压充电阈值电压(V) */ float floatI; /* 浮充充电阈值电流(A) */ @@ -113,7 +113,8 @@ typedef struct _config_info{ float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */ float FloatChargeV; /* 浮充充电时的输出电压(V) */ uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */ - + float reverseChargProtectionCurr; /* 反向充电保护电流 */ + uint16_t crc; /* 校验 */ }config_info; #define CONFIG_INFO_SIZE (sizeof(config_info)) @@ -148,8 +149,8 @@ void config_info_start(void); void readFlashContent(config_info *configInfo); void cfgTest(void); -void saveLoopImpedance(); -BOOL readLoopImpedance(); +void saveLoopImpedance(float *loopImpedance); +void readLoopImpedance(float *loopImpedance); void savetotalElectricityConsumption(float *totalElectricityConsumption); void readtotalElectricityConsumption(float *totalElectricityConsumption); void savetotalChargCapacity(float *totalChargCapacity); diff --git a/APP/businessLogic/Inc/parameter.h b/APP/businessLogic/Inc/parameter.h index 26bf846..35d15a8 100644 --- a/APP/businessLogic/Inc/parameter.h +++ b/APP/businessLogic/Inc/parameter.h @@ -14,7 +14,7 @@ typedef struct _config_parameter{ uint32_t gw485_Baud; /* 串口波特率 */ uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */ - uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0x01:是*/ + uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0xFF:是*/ float constantVoltageV; /* 恒压充电阈值电压(V) */ float floatI; /* 浮充充电阈值电流(A) */ float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */ @@ -28,7 +28,7 @@ typedef struct _config_parameter{ uint16_t firstStageProtectionValue; /* 第一段保护ADC值 */ uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */ float secondStageProtectionCurr; /* 第二段保护电流(A) */ - uint16_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */ + uint32_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */ float thirdStageProtectionCurr; /* 第三段保护电流(A) */ uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */ float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */ @@ -41,13 +41,13 @@ typedef struct _config_parameter{ float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */ float FloatChargeV; /* 浮充充电时的输出电压(V) */ uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */ + float reverseChargProtectionCurr; /* 反向充电保护电流 */ /* SL */ uint16_t Access_Node_Type; /* 接入节点类型 */ uint16_t Communication_Methods; /* 通信方式 */ uint8_t startFlagSL[2]; /* 起始标志 */ uint8_t endFlagSL; /* 结束标志 */ - } config_parameter; extern config_parameter g_cfgParameter; typedef struct _otherParameter{ @@ -124,5 +124,7 @@ BOOL setLoopImpedance(float loopImpedance); uint16_t getRegistrationStatus(void); void setRegistrationStatus(uint16_t status); +void setExChargeCurr(void); +float getExChargeCurr(void); #endif \ No newline at end of file diff --git a/APP/businessLogic/Src/SOE.c b/APP/businessLogic/Src/SOE.c index 89b12a5..0ad82c6 100644 --- a/APP/businessLogic/Src/SOE.c +++ b/APP/businessLogic/Src/SOE.c @@ -4,6 +4,7 @@ #include "parameter.h" #include "FM_RTC.h" #include "flash.h" +#include "capture.h" #define eventsOrderRecordStartAddr 4096 @@ -83,6 +84,7 @@ void eventsOrderRecordStartInit(void) | overTemperature | mos管温度 | | stopTemperature | mos管温度 | | overchargCurr | 充电电流 | +| hardwareShortCircuitProtection| 输出电流 | */ void insertEventsOrderRecord(eventsOrderRecordMode mode) { @@ -127,6 +129,18 @@ void insertEventsOrderRecord(eventsOrderRecordMode mode) 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 == hardwareShortCircuitProtection) { + soeInfo.insertData->temp = get_EXCHG_CURR(); + } + else { soeInfo.count++; return; diff --git a/APP/businessLogic/Src/abnormalManage.c b/APP/businessLogic/Src/abnormalManage.c index d0c589d..7500dc9 100644 --- a/APP/businessLogic/Src/abnormalManage.c +++ b/APP/businessLogic/Src/abnormalManage.c @@ -443,6 +443,7 @@ void DSG_PROT_Interrupt(void) setShortCircuit(); /* 第一次进入输出短路,启动短路任务 */ if (getShortCircuit() == 1) { + setPowerOutput(FALSE); setShortCircuitFlag(TRUE); startShortCircuitProtection(); } @@ -452,12 +453,13 @@ void DSG_PROT_Interrupt(void) stopShortCircuitProtection(); setPowerOutput(FALSE); zeroShortCircuit(); + insertEventsOrderRecord(hardwareShortCircuitProtection); } } - - - - - +void EXCHG_PROT_Interrupt(void) +{ + setPowerOutput(FALSE); + insertEventsOrderRecord(hardwareInputProtection); +} diff --git a/APP/businessLogic/Src/bl_chargControl.c b/APP/businessLogic/Src/bl_chargControl.c index 19f93e4..3d23212 100644 --- a/APP/businessLogic/Src/bl_chargControl.c +++ b/APP/businessLogic/Src/bl_chargControl.c @@ -735,6 +735,7 @@ void bl_chargControl(void) BatteryChargControl(); } else { noBatteryChargControl(); - } + } + // noBatteryChargControl(); } diff --git a/APP/businessLogic/Src/bl_usart.c b/APP/businessLogic/Src/bl_usart.c index 9a285a2..95a8f28 100644 --- a/APP/businessLogic/Src/bl_usart.c +++ b/APP/businessLogic/Src/bl_usart.c @@ -99,6 +99,7 @@ typedef enum { constant_Voltage_Charge_V = 0x0117, /* (2字节)恒压充电时的输出电压(*10再强转u16(V)) */ float_ChargeV = 0x0118, /* (2字节)浮充充电时的输出电压(*10再强转u16(V)) */ collect_OpenCircuit_Voltage_Time = 0x0119, /* (2字节)充电时采集开路电压的间隔时间(S) */ + reverse_Charge_Protection_Curr = 0x011A, /* (2字节)反向充电保护电流(A) */ }cfgFileType; #define gw485RxBufferSize 256 @@ -588,7 +589,7 @@ BOOL analysisFunctionCodeSL(void) uint32_t tempCfgLen = 0; tempCfgLen = (gw485RxBuffer[10] << 8) | gw485RxBuffer[11]; - if (tempCfgLen < RegAddrNumMacro && tempCfgLen > 0) { + if (tempCfgLen < maxReadCfgLen && tempCfgLen > 0) { state = readCfgLengthSL; frameLength = 15 + tempCfgLen; return TRUE; @@ -1194,7 +1195,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) temp->gw485_Baud = 115200; return (pMsg + 3); default: - return NULL; + return NULL; } } @@ -1228,13 +1229,13 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == power_Box_Type) { switch (pMsg[2]) { case 0x00: - temp->bat485_Baud = 0x00; + temp->powerBoxType = 0x00; return (pMsg + 3); case 0xFF: - temp->bat485_Baud = 0xFF; + temp->powerBoxType = 0xFF; return (pMsg + 3); default: - return NULL; + return NULL; } } @@ -1294,6 +1295,18 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) return (pMsg + 4); } + /* 配置 短路判断延时 */ + else if (dataType == short_Circuit_Judgment_Delay) { + uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3); + + if (tempU16 > 100 || tempU16 < 3) { + return NULL; + } + + temp->inputPowerLowJudgmentDelay = tempU16; + return (pMsg + 4); + } + /* 配置 前端输入功率不足判断延时 */ else if (dataType == input_Power_Low_Judgment_Delay) { uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3); @@ -1344,7 +1357,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) /* 配置 软件第二段保护延时 */ else if (dataType == second_Stage_Protection_Delay) { uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3); - if (tempU16 > 10000 || tempU16 < 10) { + if (tempU16 > 60000 || tempU16 < 10) { return NULL; } @@ -1366,19 +1379,21 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) /* 配置 软件第三段保护延时 */ else if (dataType == third_Stage_Protection_Delay) { - uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3); - if (tempU16 > 10000 || tempU16 < 10) { + uint32_t tempU32 = (*(pMsg + 2) << 24) | (*(pMsg + 3) << 16) | (*(pMsg + 4) << 8) | *(pMsg + 5); + if (tempU32 > 1000000 || tempU32 < 10) { + // debug_printf("third_Stage_Protection_Delay = %d\n", tempU32); return NULL; } - temp->thirdStageProtectionDelay = tempU16; - return (pMsg + 4); + temp->thirdStageProtectionDelay = tempU32; + return (pMsg + 6); } /* 配置 软件第三段保护阈值电流 */ else if (dataType == third_Stage_Protection_Curr) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 50 || tempFloat < 1) { + // debug_printf("third_Stage_Protection_Curr\n"); return NULL; } @@ -1390,6 +1405,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == input_Power_Low_Detection_Delay) { uint16_t tempU16 = (*(pMsg + 2) << 8) | *(pMsg + 3); if (tempU16 > 1000 || tempU16 < 2) { + // debug_printf("input_Power_Low_Detection_Delay\n"); return NULL; } @@ -1401,6 +1417,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == input_Power_Low_Detection_Volt) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 13 || tempFloat < 8) { + // debug_printf("input_Power_Low_Detection_Volt\n"); return NULL; } @@ -1412,6 +1429,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == max_Open_Solar_Output_Circuit_V) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 27 || tempFloat < 22) { + // debug_printf("max_Open_Solar_Output_Circuit_V\n"); return NULL; } @@ -1423,17 +1441,31 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == max_Charg_Curr) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 40 || tempFloat < 30) { + // debug_printf("max_Charg_Curr\n"); return NULL; } temp->maxChargCurr = tempFloat; return (pMsg + 4); } - + + /* 配置 检测回路阻抗时的最小充电电流 */ + else if (dataType == min_Check_Loop_Impedance_Charg_Curr) { + float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; + if (tempFloat > 20 || tempFloat < 2) { + // debug_printf("min_Check_Loop_Impedance_Charg_Curr\n"); + return NULL; + } + + temp->maxChargCurr = tempFloat; + return (pMsg + 4); + } + /* 配置 满功率输出温度 */ else if (dataType == full_Power_Output_Temperature) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 100 || tempFloat < 30) { + // debug_printf("full_Power_Output_Temperature\n"); return NULL; } @@ -1445,6 +1477,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == reduce_Power_Output_Temperature) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 100 || tempFloat < 30) { + // debug_printf("reduce_Power_Output_Temperature\n"); return NULL; } @@ -1456,6 +1489,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == stop_PowerOutput_Temperature) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 100 || tempFloat < 30) { + // debug_printf("stop_PowerOutput_Temperature\n"); return NULL; } @@ -1467,6 +1501,7 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) else if (dataType == constant_Voltage_Charge_V) { float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; if (tempFloat > 14.5f || tempFloat < 14) { + // debug_printf("constant_Voltage_Charge_V\n"); return NULL; } @@ -1495,6 +1530,17 @@ uint8_t *analysisDistributionProfile(uint8_t *pMsg, config_info *temp) temp->collectOpenCircuitVoltageTime = tempU16; return (pMsg + 4); } + + /* 配置 反向充电保护电流 */ + else if (dataType == reverse_Charge_Protection_Curr) { + float tempFloat = ((*(pMsg + 2) << 8) | *(pMsg + 3)) / floatMagnification; + if (tempFloat > 10.0f || tempFloat < 0.1f) { + return NULL; + } + + temp->reverseChargProtectionCurr = tempFloat; + return (pMsg + 4); + } return NULL; } @@ -1811,7 +1857,7 @@ uint8_t *analysisReadProfile(uint8_t *pMsg, uint8_t **outData, uint16_t *dataLen /* 读取 满功率输出温度 */ else if (dataType == full_Power_Output_Temperature) { - uint16_t tempU16 = (uint16_t)(g_cfgParameter.minCheckLoopImpedanceChargCurr * floatMagnification); + uint16_t tempU16 = (uint16_t)(g_cfgParameter.fullPowerOutputTemperature * floatMagnification); *(*outData + 2) = (uint8_t)(tempU16 >> 8); *(*outData + 3) = (uint8_t)(tempU16 & 0x00FF); *outData += 4; @@ -1861,7 +1907,17 @@ uint8_t *analysisReadProfile(uint8_t *pMsg, uint8_t **outData, uint16_t *dataLen /* 读取 充电时采集开路电压的间隔时间 */ else if (dataType == collect_OpenCircuit_Voltage_Time) { - uint16_t tempU16 = (uint16_t)(g_cfgParameter.collectOpenCircuitVoltageTime * floatMagnification); + uint16_t tempU16 = g_cfgParameter.collectOpenCircuitVoltageTime; + *(*outData + 2) = (uint8_t)(tempU16 >> 8); + *(*outData + 3) = (uint8_t)(tempU16 & 0x00FF); + *outData += 4; + *dataLen += 4; + return (pMsg + 2); + } + + /* 读取 反向充电保护电流 */ + else if (dataType == reverse_Charge_Protection_Curr) { + uint16_t tempU16 = (uint16_t)(g_cfgParameter.reverseChargProtectionCurr * floatMagnification); *(*outData + 2) = (uint8_t)(tempU16 >> 8); *(*outData + 3) = (uint8_t)(tempU16 & 0x00FF); *outData += 4; @@ -2081,6 +2137,9 @@ void SL_MsgProcFunc_Distribution_Profile(device_handle device, void *pMsg, uint3 } if (((HAL_GetTick() - tickstart1) >= 100) || (analysisData == NULL)) { + // if (analysisData == NULL) { + // debug_printf("analysisData == NULL\n"); + // } goto singlePackageError; } @@ -2118,14 +2177,14 @@ wholePackageCorrect: cfgInfo.crc = checkModebusCrc((uint8_t *)&cfgInfo, CONFIG_INFO_SIZE - 2); saveConfigInfo(&cfgInfo); - // float tempF; - // tempF = getTotalElectricityConsumption(); - // savetotalElectricityConsumption(&tempF); - // tempF = getTotalChargCapacity(); - // savetotalChargCapacity(&tempF); - // timeInfo time; - // time = getLastTime(); - // saveTime(&time); + float tempF; + tempF = getTotalElectricityConsumption(); + savetotalElectricityConsumption(&tempF); + tempF = getTotalChargCapacity(); + savetotalChargCapacity(&tempF); + timeInfo time; + time = getLastTime(); + saveTime(&time); return; diff --git a/APP/businessLogic/Src/inFlash.c b/APP/businessLogic/Src/inFlash.c index a50b286..1d755b9 100644 --- a/APP/businessLogic/Src/inFlash.c +++ b/APP/businessLogic/Src/inFlash.c @@ -155,7 +155,7 @@ void readFlashContent(config_info *configInfo) configInfo->gw485_Baud = 115200; configInfo->bat485_Baud = 115200; - configInfo->powerBoxType = 0x01; + configInfo->powerBoxType = 0xFF; configInfo->constantVoltageV = 14; configInfo->floatI = 0.1f; @@ -189,6 +189,8 @@ void readFlashContent(config_info *configInfo) configInfo->constantVoltageChargeV = 14.4f; configInfo->FloatChargeV = 14.2f; configInfo->collectOpenCircuitVoltageTime = 1800; + + configInfo->reverseChargProtectionCurr = 2; // configInfo->firstStageProtectionCurr = firstStageProtectionCurrMacro; // configInfo->firstStageProtectionDelay = firstStageProtectionDelayMacro; @@ -227,7 +229,10 @@ void config_info_start(void) 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]; @@ -269,14 +274,21 @@ void config_info_start(void) 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 */ - if (readLoopImpedance() == FALSE) { - setLoopImpedance(0); - saveLoopImpedance(); - } - float fTemp; + // fTemp = 0.01f; + // saveLoopImpedance(&fTemp); + readLoopImpedance(&fTemp); + setLoopImpedance(fTemp); + // if (getLoopImpedance() < 0 || getLoopImpedance() > 0.3f) { + if (!setLoopImpedance(fTemp)) { + setLoopImpedance(0.01f); + fTemp = getLoopImpedance(); + saveLoopImpedance(&fTemp); + } + readtotalElectricityConsumption(&fTemp); totalElectricityConsumptionInt(fTemp); readtotalChargCapacity(&fTemp); @@ -293,22 +305,18 @@ void config_info_start(void) * @brief 保存回路阻抗在flash中 * @param */ -void saveLoopImpedance(void) +void saveLoopImpedance(float *loopImpedance) { - float loopImpedance; - loopImpedance = getLoopImpedance(); - write_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float)); + write_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float)); } /** * @brief 读取flash中的回路阻抗 * @param */ -BOOL readLoopImpedance(void) +void readLoopImpedance(float *loopImpedance) { - float loopImpedance; - read_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float)); - return setLoopImpedance(loopImpedance); + read_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float)); } /** diff --git a/APP/businessLogic/Src/parameter.c b/APP/businessLogic/Src/parameter.c index 871a5e1..503ff6f 100644 --- a/APP/businessLogic/Src/parameter.c +++ b/APP/businessLogic/Src/parameter.c @@ -14,6 +14,8 @@ static uint8_t mosTemperState = mosTemperFull; /* mos管温度状态 */ static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */ static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */ +static float exChargeCurr = 0; + /** * @brief 获取电池状态 * @param @@ -165,8 +167,10 @@ float getBatteryVoltage(void) */ void setBatteryVoltage(void) { - g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage - - getChargBatteryCurrent() * getLoopImpedance(); + // g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage + // - getChargBatteryCurrent() * getLoopImpedance(); + g_otherParameter.Battery_Voltage = getOutputVoltage() + - getChargBatteryCurrent() * getLoopImpedance(); } /** @@ -519,4 +523,25 @@ void setRegistrationStatus(uint16_t status) if (status == UNREGISTER || status == REGISTER_FAIL || status == REGISTER_SUCCESS) { g_otherParameter.Registration_Status = status; } -} \ No newline at end of file +} + +/** + * @brief 设置反向充电电流 + * @param + * @retval + */ +void setExChargeCurr(void) +{ + exChargeCurr = get_EXCHG_CURR(); +} + +/** + * @brief 得到反向充电电流 + * @param + * @retval + */ +float getExChargeCurr(void) +{ + return exChargeCurr; +} + diff --git a/APP/businessLogic/Src/task.c b/APP/businessLogic/Src/task.c index 356df86..84680eb 100644 --- a/APP/businessLogic/Src/task.c +++ b/APP/businessLogic/Src/task.c @@ -200,19 +200,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", 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("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]; @@ -289,6 +290,7 @@ void Task_refreshJudgeData(void) /* 获取数据 */ setInputVoltage(); setHighSideMosTemperature(); + setExChargeCurr(); // static float tempOutV; // tempOutV = get_OUT_VOLT_IN(); @@ -329,7 +331,13 @@ void Task_refreshJudgeData(void) /* 停止充电 */ stopChargWork(); insertEventsOrderRecord(stopTemperature); - } + } + + /* 反向充电电流检测 */ + if (getExChargeCurr() > g_cfgParameter.reverseChargProtectionCurr) { + setPowerOutput(FALSE); + insertEventsOrderRecord(InputProtection); + } } /** @@ -472,7 +480,7 @@ void Task_impedanceCalculation(void) // } /* 判断回路阻抗是否合理 */ if (setLoopImpedance(tempLoopImpedance) == TRUE) { - saveLoopImpedance(); + saveLoopImpedance(&tempLoopImpedance); setCheckImpedanceState(); } @@ -634,14 +642,14 @@ void Task_shortCircuitProtection(void) TimeSliceOffset_Unregister(&m_shortCircuitProtection); m_shortCircuitProtection.runFlag = 0; - /* 仍然过流,彻底关闭输出 */ - if (readOverCurrState() == FALSE) { - setPowerOutput(FALSE); - } - /* 不过流,则状态位复位 */ - else { - setShortCircuitFlag(FALSE); - } + // /* 仍然过流,彻底关闭输出 */ + // if (readOverCurrState() == FALSE) { + // setPowerOutput(FALSE); + // } + // /* 不过流,则状态位复位 */ + // else { + // setShortCircuitFlag(FALSE); + // } } } diff --git a/APP/functionalModule/Inc/FM_GPIO.h b/APP/functionalModule/Inc/FM_GPIO.h index faf9af4..caa0f02 100644 --- a/APP/functionalModule/Inc/FM_GPIO.h +++ b/APP/functionalModule/Inc/FM_GPIO.h @@ -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 diff --git a/APP/functionalModule/Inc/capture.h b/APP/functionalModule/Inc/capture.h index 45f3c1d..e42a844 100644 --- a/APP/functionalModule/Inc/capture.h +++ b/APP/functionalModule/Inc/capture.h @@ -31,7 +31,7 @@ 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(); diff --git a/APP/functionalModule/Src/FM_GPIO.c b/APP/functionalModule/Src/FM_GPIO.c index 9cc485f..87ac01d 100644 --- a/APP/functionalModule/Src/FM_GPIO.c +++ b/APP/functionalModule/Src/FM_GPIO.c @@ -167,7 +167,7 @@ BOOL readOverCurrState(void) if (HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) { return TRUE; } - + return FALSE; } @@ -226,9 +226,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(); + } } diff --git a/APP/functionalModule/Src/capture.c b/APP/functionalModule/Src/capture.c index ec077dd..45d35ed 100644 --- a/APP/functionalModule/Src/capture.c +++ b/APP/functionalModule/Src/capture.c @@ -111,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; @@ -196,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; } /* 电源盒外还有网关功能 */ @@ -212,8 +212,8 @@ 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; } @@ -435,31 +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.52f / 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 { - if (V_ADC > V_ADCTemp) { - V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN; - } - V = (float)(V_ADC) * 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; } @@ -509,20 +510,27 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma) // 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 = (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; + setSoftShortCircuit(DSG_CURR_capture.outData); - setSoftShortCircuit(DSG_CURR_capture.outData); - - chargControl(); + chargControl(); } } diff --git a/APP/functionalModule/Src/uart_dev.c b/APP/functionalModule/Src/uart_dev.c index 43df124..d663748 100644 --- a/APP/functionalModule/Src/uart_dev.c +++ b/APP/functionalModule/Src/uart_dev.c @@ -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]; diff --git a/APP/hardwareDriver/Inc/HD_ADC.h b/APP/hardwareDriver/Inc/HD_ADC.h index 76e3d12..070a4f3 100644 --- a/APP/hardwareDriver/Inc/HD_ADC.h +++ b/APP/hardwareDriver/Inc/HD_ADC.h @@ -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); diff --git a/APP/hardwareDriver/Src/HD_GPIO.c b/APP/hardwareDriver/Src/HD_GPIO.c index 407ee0b..ee399bd 100644 --- a/APP/hardwareDriver/Src/HD_GPIO.c +++ b/APP/hardwareDriver/Src/HD_GPIO.c @@ -2,57 +2,118 @@ 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(EXTI15_10_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); } \ No newline at end of file diff --git a/Core/Inc/main.h b/Core/Inc/main.h index 8d7627e..1eaae35 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -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 @@ -109,6 +109,8 @@ 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 RUN_LED_Pin GPIO_PIN_6 #define RUN_LED_GPIO_Port GPIOB #define POW_FF_CON_Pin GPIO_PIN_7 diff --git a/Core/Src/adc.c b/Core/Src/adc.c index e32a714..86edbc8 100644 --- a/Core/Src/adc.c +++ b/Core/Src/adc.c @@ -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); diff --git a/Core/Src/gpio.c b/Core/Src/gpio.c index 70ee1fe..60dcbe7 100644 --- a/Core/Src/gpio.c +++ b/Core/Src/gpio.c @@ -61,8 +61,8 @@ 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 pin : FLASH_CS_Pin */ @@ -92,6 +92,12 @@ void MX_GPIO_Init(void) 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(EXTI15_10_IRQn, 0, 0); HAL_NVIC_EnableIRQ(EXTI15_10_IRQn); diff --git a/Core/Src/main.c b/Core/Src/main.c index e847c51..9745e9d 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -73,7 +73,6 @@ void SystemClock_Config(void); */ int main(void) { - /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ @@ -111,6 +110,8 @@ int main(void) // MX_SPI1_Init(); /* USER CODE BEGIN 2 */ +// while (1) { +// }; start(); diff --git a/chargeController.ioc b/chargeController.ioc index efe95a4..bb203d8 100644 --- a/chargeController.ioc +++ b/chargeController.ioc @@ -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= @@ -246,6 +247,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 @@ -258,6 +265,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 @@ -273,8 +285,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 @@ -285,11 +297,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 @@ -330,7 +337,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_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 +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 @@ -382,6 +389,8 @@ 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.CalculateBaudRate=36.0 MBits/s diff --git a/tools/chargControlTypes.h b/tools/chargControlTypes.h index b6f03e4..85d78fe 100644 --- a/tools/chargControlTypes.h +++ b/tools/chargControlTypes.h @@ -65,6 +65,9 @@ typedef enum { stopTemperature, //停止温度保护 overchargCurr, //充电电流过大保护 overInputVolt, //太阳能输入电压过大保护 + hardwareShortCircuitProtection, //硬件短路保护 + hardwareInputProtection, //硬件防反输入保护 + InputProtection, //软件防反输入保护 }eventsOrderRecordMode;