2025-05-25 8:12 AM
Dear Sirs,
I am implementing an interface between an STM32H750 and a CanBus device of an electric bike. I have the FDCAN peripheral configured to 250kbit/s (FDCAN clock is 48MHz)
I have to interface with devices that use Extended Frames, but the speed is fixed to 250bit/s, so I wanted to use normal mode.
First I ninitialize the peripheral as:
// Configure TX Header for FDCAN2
CAN_TxHeader.Identifier = 0x03;
CAN_TxHeader.IdType = FDCAN_EXTENDED_ID;
CAN_TxHeader.TxFrameType = FDCAN_DATA_FRAME;
CAN_TxHeader.DataLength = FDCAN_DLC_BYTES_8;
CAN_TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
CAN_TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
CAN_TxHeader.FDFormat = FDCAN_FD_CAN;
CAN_TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
CAN_TxHeader.MessageMarker = 0;
/* Configure standard ID reception filter to Rx buffer 0 */
CAN_FilterConfig.IdType = FDCAN_EXTENDED_ID;
CAN_FilterConfig.FilterIndex = 0;
CAN_FilterConfig.FilterType = FDCAN_FILTER_DUAL;
CAN_FilterConfig.FilterID2 = 0x0;
CAN_FilterConfig.RxBufferIndex = 0;
if(HAL_FDCAN_ConfigFilter(&hfdcan2, &CAN_FilterConfig) != HAL_OK)
{
Error_Handler();
}
if(HAL_FDCAN_Start(&hfdcan2)!= HAL_OK)
{
Error_Handler();
}
if (HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0) != HAL_OK)
{
/* Notification Error */
Error_Handler();
}
if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &CAN_TxHeader, &CAN_TxData[0]) != HAL_OK)
{
Error_Handler();
}
and then in a FreeRTOS task I send data:
void canBus(void *argument)
{
/* USER CODE BEGIN canBus */
HAL_StatusTypeDef rtv = HAL_ERROR;
/* Infinite loop */
for(;;)
{
// Send the HeartBeat Message to the controller
CAN_TxHeader.DataLength = FDCAN_DLC_BYTES_4;
CAN_TxData[0] = 0x05;
CAN_TxData[1] = 0x03;
CAN_TxData[2] = 0x00;
CAN_TxData[3] = 0x01;
rtv = HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &CAN_TxHeader, &CAN_TxData[0]);
// Check is there are Received Messages in the CAN RX FIFO
if (can_rx_message_available != 0)
{
// Process them
canBusMsgProcess();
can_rx_message_available = 0;
}
osDelay(1000);
}
/* USER CODE END canBus */
}
Debugging the code, placing a breakpoint, I get that rtv is always HAL_OK, and if with the oscilloscope I monitor the CAN_TX pins, there is activity, but then in the bus, there is no activity (CANH/CANL lines)
I have been going back and forth with this for days, and I do not know what can be problem.
Is it something with initialization? Probably with the FIFO?
I do not want to filter Messages on the Bus, as this will interface with a lot of different devices.
Thank you so much in advance,
Best regards