2024-07-04 07:37 AM - last edited on 2024-07-05 03:16 AM by SofLit
Hello all,
I am trying to receive CAN frames from a BMS, each frame is sent every 100ms and i am running the MCU's clock frequency at 180MHz (max speed) for Nucleo F446RE.
Unfortunately, i am missing some frames randomly and it makes my stateflow not working properly.
The CAN filter is set to 0 everywhere so all the frames from the BMS can be handled.
Does anyone know what i could do to solve the problem?
Thanks in advance
Solved! Go to Solution.
2024-07-05 12:48 AM
i am not sure that the CAN speed config is the problem, since i receive some of them.
Please modify the parameters as suggested even if you received some of them. We need to eliminate as much as possible the issues.
Meanwhile, I can suspect a CAN hardware issue linked to EMC. Try to use a shielded cable (refer to this paper for more information).
Also connect the GNDs between the CAN nodes (common GND): your "BMS" and your "F4 node"
2024-07-04 08:13 AM
Hello,
Not sure what do you mean by "BMS", in next time please avoid to use the abbreviations so all here we can understand. Could you please give more details about this device and more specifically the HW?
Start by modifying the bitrate settings. I propose the following:
CAN prescaler = 5
BS1 = 14
BS2 = 3
2024-07-04 11:54 PM
Well, BMS means "Battery Management System" (hardware used on battery to send frames on CAN Bus).
So, the point is that it is sending frames 0x586; 0x591; 0x587; 0x582; 0x5C0; 0x580 and more of them.
The issue is i can receive only a few of them.
Each frame is sent every 100ms, but there are a lot of different frames between those 100 ms and i am not sure that the CAN speed config is the problem, since i receive some of them.
if(CAN_FIFO_Status == FIFO_BUSY) //
{ //
CAN_FIFO_Status = FIFO_EMPTY; //RAZ interrupt flag //
switch(RxHeader.StdId) //
{ //
case 0x586: //
BatteryChargeCurrent_rcv(RxFrame, &rx_BCC); //Receive frame //
BatteryChargeCurrent_memHandler(rx_BCC, &h_BCC); //handle memory //
/***********************/ //
Discharge_Battery(); //
Discharge_DCDC(); //
Charge_BatteryDCDC(); //
sprintf(msg, "586 in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
case 0x591: //
BatteryCurrentLimit_rcv(RxFrame, &rx_BCL); //Receive frame //
BatteryCurrentLimit_memHandler(rx_BCL, h_BCL); //handle memory //
/***********************/ //
Discharge_Battery(); //
Discharge_DCDC(); //
Charge_BatteryDCDC(); //
sprintf(msg, "591 in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
case 0x587: //
BatteryStatusCharge_rcv(RxFrame, &rx_BSC);
BatteryStatusCharge_memHandler(rx_BSC, h_BSC); //handle memory //
/***********************/ //
Discharge_Battery(); //
Discharge_DCDC(); //
Charge_BatteryDCDC(); //
sprintf(msg, "587 in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
case 0x580: //
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_SET);
BatteryStatusGeneral_rcv(RxFrame, &rx_BSG); //Receive frame //
BatteryStatusGeneral_memHandler(rx_BSG, h_BSG); //handle memory //
/***********************/ //
Discharge_Battery(); //
Discharge_DCDC(); //
Charge_BatteryDCDC(); //
sprintf(msg, "580 in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
sprintf(msg, "Element %d\t: %d\t: %d\t: %d\t: %d\t: %d\t: %d\t: %d\r\n", rx_BSG.BatteryStatusCounter, rx_BSG.vide,
rx_BSG.BatteryInstVoltage_lsb, rx_BSG.BatteryInstVoltage_msb, rx_BSG.BatteryInstTemperature,
rx_BSG.BatterySOC, rx_BSG.Battery_PCS__H__S, rx_BSG.BatteryStatusCRC);
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
break; //
case 0x59f: //
BatteryVehicleHandling_rcv(RxFrame, &rx_BVH); //Receive frame //
BatteryVehicleHandling_memHandler(rx_BVH, h_BVH); //handle memory //
/***********************/ //
Discharge_Battery(); //
Discharge_DCDC(); //
Charge_BatteryDCDC(); //
sprintf(msg, "59f in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
case 0x582: //
BatteryStatusEnergy_rcv(RxFrame, &rx_BSE); //
BatteryStatusEnergy_memHandler(rx_BSE, h_BSE); //
//
sprintf(msg, "582 in FIFO \r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
case 0x24: //
EPIC_PMZ_A_rcv(RxFrame, &rx_pmzA); //Receive frame //
EPIC_PMZ_A_memHandler(rx_pmzA, h_PMZ_A); //handle memory //
break; //
case 0x50: //
EPIC_PMZ_C_rcv(RxFrame, &rx_pmzC); //Receive frame //
EPIC_PMZ_C_memHandler(rx_pmzC, h_PMZ_C); //handle memory + CRC compute //
if(PMZ_C_crc(rx_pmzC) != 0x00) //
{ //
//Stateflow //
} //
break; //
case 0x5A: //
EPIC_PMZ_E_rcv(RxFrame, &rx_pmzE); //Receive frame //
EPIC_PMZ_E_memHandler(rx_pmzE, h_PMZ_E); //handle memory //
break; //
case 0x5E: //
EPIC_PMZ_G_rcv(RxFrame, &rx_pmzG); //Receive frame //
EPIC_PMZ_G_memHandler(rx_pmzG, h_PMZ_G); //handle memory + CRC compute //
if(PMZ_G_crc(rx_pmzG)!=0x00) //
{ //
//Stateflow //
} //
break; //
case 0x60: //
EPIC_PMZ_H_rcv(RxFrame, &rx_pmzH); //Receive frame //
EPIC_PMZ_H_memHandler(rx_pmzH, h_PMZ_H); //handle memory + CRC compute //
if(PMZ_H_crc(rx_pmzH)!=0x00) //
{ //
//Stateflow //
} //
break; //
case 0x4e2: //
EPIC_PMZ_I_rcv(RxFrame, &rx_pmzI); //Receive frame //
EPIC_PMZ_I_memHandler(rx_pmzI, &h_PMZ_I); //handle memory //
break; //
case 0x621: //
HMI_DATA1_rcv(RxFrame, &rx_cluster); //Receive frame //
HMI_DATA1_memHandler(rx_cluster, h_HMI); //handle memory //
break; //
case 0x719: //
UDS_DIAG_rcv(RxFrame); //
UDS_Response_mgt(RxFrame, VCU_Response, &TxHeader, TxFrame); //
CAN_Send_Periodic(); // spontaneous sending //
break; //
case 0x700: //
DCDC700_rcv(RxFrame, &rx_dcdc700); //Receive frame //
DCDC700_memHandler(rx_dcdc700, DCDC_700); //handle memory //
break; //
case 0x703: //
DCDC703_rcv(RxFrame, &rx_dcdc703); //Receive frame //
break; //
default: //
sprintf(msg, "Unknown ID in FIFO 1\r\n"); //
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY); //
break; //
} //
} //
/****************************************************************************************************/
2024-07-05 12:48 AM
i am not sure that the CAN speed config is the problem, since i receive some of them.
Please modify the parameters as suggested even if you received some of them. We need to eliminate as much as possible the issues.
Meanwhile, I can suspect a CAN hardware issue linked to EMC. Try to use a shielded cable (refer to this paper for more information).
Also connect the GNDs between the CAN nodes (common GND): your "BMS" and your "F4 node"