2024-05-16 12:48 AM - last edited on 2024-05-16 01:16 AM by SofLit
Hello ST community,
I am currently programming an ECU system, using f446re nucleo board. Right now i am trying to communicate with BMS using CAN communication.
So far, everything has been set: CAN Initialization and start, sending works properly.
The issue i am facing is that i cannot receive frames from battery, even though i can communicate with laptop for UDS protocole (Reception works properly in that case), but when i try with the battery, the debug mode doesn't stop at the rx interrupt routine.
I have verified the CANFilter configuration to make sure, i didn't see any mistake, nothing has been changed but i only can communicate with UDS frames and not with batteries.
for example: frame ID 0x586 entering fifo0 with such a filter:
void CAN_Filter_FIFO0(CAN_HandleTypeDef* hcan)
{
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 10;
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
canfilterconfig.FilterIdHigh = 0x580 << 5; // According to the DBC
canfilterconfig.FilterIdLow = 0x0000;
canfilterconfig.FilterMaskIdHigh = 0xfe0<<5;// Calculation of the mask according to the DBC
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 13;
HAL_CAN_ConfigFilter(hcan, &canfilterconfig);
}
Please let me know if anyone has any idea.
Solved! Go to Solution.
2024-05-21 06:11 AM
Alright, found the problem, I was using both fifo0 and fifo1 for receiving whereas i had to use only one for all the frames. Don't know how to use both of them s
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &RxHeader, RxFrame);
{
switch(RxHeader.StdId)
{
case 0x586:
BatteryChargeCurrent_rcv(RxFrame, &rx_BCC); //Receive frame
BatteryChargeCurrent_memHandler(rx_BCC, &h_BCC); //handle memory
BCCFlag++;
break;
case 0x591:
BatteryCurrentLimit_rcv(RxFrame, &rx_BCL); //Receive frame
BatteryCurrentLimit_memHandler(rx_BCL, h_BCL); //handle memory
BCLFlag++;
break;
case 0x587:
BatteryStatusCharge_rcv(RxFrame, &rx_BSC); //Receive frame
BatteryStatusCharge_memHandler(rx_BSC, h_BSC); //handle memory
BSCFlag++;
break;
case 0x580:
BatteryStatusGeneral_rcv(RxFrame, &rx_BSG); //Receive frame
BatteryStatusGeneral_memHandler(rx_BSG, h_BSG); //handle memory
BSGFlag++;
break;
case 0x59f:
BatteryVehicleHandling_rcv(RxFrame, &rx_BVH); //Receive frame
BatteryVehicleHandling_memHandler(rx_BVH, h_BVH); //handle memory
BVHFlag++;
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
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
break;
case 0x60:
EPIC_PMZ_H_rcv(RxFrame, &rx_pmzH); //Receive frame
EPIC_PMZ_H_memHandler(rx_pmzH, h_PMZ_H); //handle memory
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);
UDSFlag ++;
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;
}
}
}
imultaneously. Then i used only one to receive the frames and it works.
2024-05-16 01:13 AM - edited 2024-05-16 01:15 AM
Hello,
Try first with "passing all messages" filter to be sure it's not a filter config issue:
canfilterconfig.FilterIdHigh = 0,
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0;
canfilterconfig.FilterMaskIdLow = 0;
PS: next time please use <\> button to insert your code. Thank you for your understanding.
2024-05-16 02:12 AM
Hello thank you for your quick answer.
I did what you said put 0 to cancel the filter. but nothing changed, here is a code of the following files: main.c; CanfilterConfig.c
main
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &RxHeader, RxFrame);
{
switch(RxHeader.StdId)
{
case 0x586:
BatteryChargeCurrent_rcv(RxFrame, &rx_BCC); //Receive frame
BatteryChargeCurrent_memHandler(rx_BCC, &h_BCC); //handle memory
BCCFlag++;
break;
case 0x591:
BatteryCurrentLimit_rcv(RxFrame, &rx_BCL); //Receive frame
BatteryCurrentLimit_memHandler(rx_BCL, h_BCL); //handle memory
BCLFlag++;
break;
case 0x587:
BatteryStatusCharge_rcv(RxFrame, &rx_BSC); //Receive frame
BatteryStatusCharge_memHandler(rx_BSC, h_BSC); //handle memory
BSCFlag++;
break;
case 0x580:
BatteryStatusGeneral_rcv(RxFrame, &rx_BSG); //Receive frame
BatteryStatusGeneral_memHandler(rx_BSG, h_BSG); //handle memory
BSGFlag++;
break;
case 0x59f:
BatteryVehicleHandling_rcv(RxFrame, &rx_BVH); //Receive frame
BatteryVehicleHandling_memHandler(rx_BVH, h_BVH); //handle memory
BVHFlag++;
break;
default:
sprintf(msg, "Unknown ID in FIFO 0\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
break;
}
}
}
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
DID_Init();
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_CAN1_Init();
MX_ADC1_Init();
MX_TIM6_Init();
/* USER CODE BEGIN 2 */
CAN_Filter_FIFO0(&hcan1); // Filter config for FIFO0
CAN_Filter_FIFO1(&hcan1); // Filter config for FIFO1
HAL_CAN_Start(&hcan1);
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING); // Enable Interrupt at FIFO0 reception
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO1_MSG_PENDING); // Enable Interrupt at FIFO1 reception
HAL_TIM_Base_Start_IT(&htim6); // Start timer for scheduled frame sending
//HAL_ADC_Start_IT(&hadc1); // Start adc
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
uint8_t countpres;
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
// if (uADCConversionCpltFlag) {
// uiADCRawValueBuffer = HAL_ADC_GetValue(&hadc1);
// sprintf(msg, "Throttle: %hu \r\n", uiADCRawValueBuffer);
// HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY);
// }
/*Single channel polling*/
// HAL_ADC_Start(&hadc1);
// HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY);
// uiADCRawValueBuffer = HAL_ADC_GetValue(&hadc1);
// sprintf(msg, "Throttle: %hu \r\n", uiADCRawValueBuffer);
// HAL_UART_Transmit(&huart2, (uint8_t *)msg, strlen(msg), HAL_MAX_DELAY);
/****************** USABLE CODE ******************/
/*SEND UDS RESPONSE*/
if(UDSFlag!=0)
{
UDSFlag = 0;
UDS_Response_mgt(RxFrame, VCU_Response, &TxHeader, TxFrame);
CAN_Send_Periodic();
}
if(BCCFlag!=0)
{
BCCFlag = 0;
Discharge_Battery();
Discharge_DCDC();
sprintf(msg, "BatteryChargeCurrent frame received\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
if(BCLFlag!=0)
{
BCLFlag = 0;
Discharge_Battery();
Discharge_DCDC();
sprintf(msg, "BatteryCurrentLimit frame received\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
if(BSCFlag!=0)
{
BSCFlag = 0;
Discharge_Battery();
Discharge_DCDC();
sprintf(msg, "BatteryStatusCharge frame received\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
if(BSGFlag!=0)
{
BSGFlag = 0;
Discharge_Battery();
Discharge_DCDC();
sprintf(msg, "BatteryStatusGeneral frame received\r\n");
HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
}
}
}
CanFilterConfig
#include "CanFilterConfig.h"
void CAN_Filter_FIFO0(CAN_HandleTypeDef* hcan)
{
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.FilterBank = 10;
canfilterconfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
canfilterconfig.FilterIdHigh = 0x580 << 5; // According to the DBC
canfilterconfig.FilterIdLow = 0x0000;
canfilterconfig.FilterMaskIdHigh = 0xfe0 << 5;// Calculation of the mask according to the DBC
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.SlaveStartFilterBank = 13;
HAL_CAN_ConfigFilter(hcan, &canfilterconfig);
}
Thank you again for your time
2024-05-16 02:16 AM
Hello,
Better to attach your main.c and your ioc files.
+ keep the filters to 0 for the moment.
2024-05-16 02:19 AM
2024-05-16 02:26 AM
Hello,
Thanks for the sharing,
Do you confirm you did a test with:
canfilterconfig.FilterIdHigh = 0,
canfilterconfig.FilterIdLow = 0;
canfilterconfig.FilterMaskIdHigh = 0;
canfilterconfig.FilterMaskIdLow = 0;
and didn't work?
2024-05-16 02:38 AM
Yes, i confirm that it is not working even with every fields set to 0.
2024-05-16 02:49 AM
Ok thank you.
Here I'm just pointing this statement:
"even though i can communicate with laptop for UDS protocole (Reception works properly in that case), but when i try with the battery, the debug mode doesn't stop at the rx interrupt routine."
So as I understand here, the receiving is working well when you send frames from your laptop (with a CAN bridge I suppose) but you couldn't receive any frame from the battery right?
2024-05-16 04:41 AM
Yes, actuallty i tried to communicate with BMS (directly on battery) but debug mode is not possible in that case so i am using the laptop to simulate the behavior but sending the frames i want, to test my state machine.
2024-05-16 06:35 AM
Anyways i just noticed that the frame is sent continuously from the laptop maybe it is the source of the problem. Gonna fix it, thank you very much for your support!