Browse Source

平峰协议更改,BMS电压分两次读取

LAPTOP-KB7QFH2U\ChenJie-PC 2 năm trước cách đây
mục cha
commit
f08b04a104
3 tập tin đã thay đổi với 22 bổ sung11 xóa
  1. 1 1
      FreeRTOS/Source/include/FreeRTOSConfig.h
  2. 20 9
      code/app/AppTaskUart0.c
  3. 1 1
      code/main.c

+ 1 - 1
FreeRTOS/Source/include/FreeRTOSConfig.h

@@ -29,7 +29,7 @@
 #ifndef FREERTOS_CONFIG_H
 #define FREERTOS_CONFIG_H
 //#define SEGGER_SYSTEMVIEW //选择SYSTEM查看
-#define SEGGER_RTT_PRINTF //选择RTT打印
+//#define SEGGER_RTT_PRINTF //选择RTT打印
 #ifdef SEGGER_SYSTEMVIEW
 	#include "SEGGER_SYSVIEW_FreeRTOS.h"
 #endif

+ 20 - 9
code/app/AppTaskUart0.c

@@ -11,7 +11,8 @@
 #ifdef APP_UART0_ENABLE
 static process_Uart0 gProcess_Uart0_Task = PROCESS_UART_STATE_IDLE;
 #define PROC_UART0_STATE_SWITCH(a) (gProcess_Uart0_Task = a)
-bool bmsCellInfoDecode(uint8 *dataPtr);
+bool bmsCellInfoDecode1(uint8 *dataPtr);
+bool bmsCellInfoDecode2(uint8 *dataPtr);
 bool bmsTempInfoDecode(uint8 *dataPtr);
 bool bmsOtherInfoDecode(uint8 *dataPtr);
 void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)(uint8 *dataPtr));
@@ -43,20 +44,22 @@ void Uart0Task(void *pvParameters)
 		case PROCESS_UART_STATE_READ:
 		{
 			/*01 04 00 01 00 38 A0 18
-			01 04 00 64 00 78 B1 F7
+			01 04 00 64 00 3C B1 C4
 			01 04 01 90 00 28 F1 C5 */
 			Dio_FlipChannel(DioConf_DioChannel_PTE1_GPIO_OUT_MCU_LED2);
 			//其他参数读取
 			UartBusReadDataFunc(0x01, 0x38, bmsOtherInfoDecode);
 			//电压读取
-			UartBusReadDataFunc(0x64, 120, bmsCellInfoDecode);
+			UartBusReadDataFunc(0x64, 60, bmsCellInfoDecode1);
+			UartBusReadDataFunc(0x64 + 60, 60, bmsCellInfoDecode2);
 			//温度读取
 			UartBusReadDataFunc(0x190, 40, bmsTempInfoDecode);
 			//没有读到数据时的默认值
 			if (UartNoDataReadCounter > 10)
 			{
 				memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
-				bmsCellInfoDecode(UartAnsData.Data);
+				bmsCellInfoDecode1(UartAnsData.Data);
+				bmsCellInfoDecode2(UartAnsData.Data);
 				bmsTempInfoDecode(UartAnsData.Data);
 				bmsOtherInfoDecode(UartAnsData.Data);
 				PutErrorNum(ErrorArray, sizeof(ErrorArray) / 2, 1);
@@ -122,9 +125,17 @@ void Uart0Task(void *pvParameters)
 		}
 	}
 }
-bool bmsCellInfoDecode(uint8 *dataPtr) //电压数据解码
+bool bmsCellInfoDecode1(uint8 *dataPtr) //电压数据解码1
 {
-	for (uint8 i = 0; i < BMS_CELLNUM; i++)
+	for (uint8 i = 0; i < 60; i++)
+	{
+		battCellU[i] = ((dataPtr[(0x00 + i) * 2] << 8) | dataPtr[(0x00 + i) * 2 + 1]);
+	}
+	return true;
+}
+bool bmsCellInfoDecode2(uint8 *dataPtr) //电压数据解码2
+{
+	for (uint8 i = 60; i < BMS_CELLNUM; i++)
 	{
 		battCellU[i] = ((dataPtr[(0x00 + i) * 2] << 8) | dataPtr[(0x00 + i) * 2 + 1]);
 	}
@@ -182,10 +193,10 @@ void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)
 	uint16 ReadLenTar = 0;
 	uint8 ReadDelayCounter = 0;
 	uint16 CRC_chk_buffer = 0;
-	uint16 pReadLen;
+	uint16 pReadLen = 0;
 	UartAnsType UartAnsData;
 	uint8 UartDataRecv[256];
-	pReadLen = 0;
+
 	Uart0AskMsg.Bms_Address = BMS_ADDRESS_CODE;
 	Uart0AskMsg.Bms_Funcode = UART_READ_CODE;
 	Uart0AskMsg.Reg_Begin_H = RegAddrBegin >> 8;
@@ -195,7 +206,7 @@ void UartBusReadDataFunc(uint16 RegAddrBegin, uint16 Reg_Num, bool (*decodeFunc)
 	CRC_chk_buffer = crc_chk((uint8 *)&Uart0AskMsg, 6);
 	Uart0AskMsg.CRC_L = CRC_chk_buffer;
 	Uart0AskMsg.CRC_H = CRC_chk_buffer >> 8;
-	UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 1000);
+	UART_Send_Data(UART_LPUART0, (uint8 *)&Uart0AskMsg, sizeof(Uart0AskMsg), 100);
 	ReadLenTar = (Reg_Num)*2 + 5;
 	memset((uint8 *)&UartAnsData, 0x00, sizeof(UartAnsData));
 	while (1)

+ 1 - 1
code/main.c

@@ -171,6 +171,7 @@ int main(void)
 
 #ifdef SEGGER_SYSTEMVIEW
 	SEGGER_SYSVIEW_Conf();
+	SEGGER_SYSVIEW_Start();
 #endif
 
 #ifdef SEGGER_RTT_PRINTF
@@ -184,7 +185,6 @@ int main(void)
 	xTaskCreate(CanTask, (const char *const)"CanTask", 512, (void *)0, main_TASK_PRIORITY + 2, NULL);
 	xTaskCreate(GpsTask, (const char *const)"GpsTask", 512, (void *)0, main_TASK_PRIORITY + 1, NULL);
 	xTaskCreate(Uart_4G_Task, (const char *const)"Uart_4G_Task", 2048, (void *)0, main_TASK_PRIORITY + 0, NULL);
-	SEGGER_SYSVIEW_Start();
 	vTaskStartScheduler();
 	for (;;)
 	{