2026-06-03 12:03 AM
Hardware connection
CAN Configuration
CAN_HandleTypeDef hcan1;
/* CAN1 init function */
void MX_CAN1_Init(void)
{
/* USER CODE BEGIN CAN1_Init 0 */
/* USER CODE END CAN1_Init 0 */
/* USER CODE BEGIN CAN1_Init 1 */
/* USER CODE END CAN1_Init 1 */
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 8;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_6TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_3TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = ENABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN CAN1_Init 2 */
CAN_FilterTypeDef canfilterconfig;
canfilterconfig.FilterBank = 0;
canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
canfilterconfig.FilterIdHigh = 0x0000;
canfilterconfig.FilterIdLow = 0x0000;
canfilterconfig.FilterMaskIdHigh = 0x0000;
canfilterconfig.FilterMaskIdLow = 0x0000;
canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
canfilterconfig.SlaveStartFilterBank = 14;
if (HAL_CAN_ConfigFilter(&hcan1, &canfilterconfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END CAN1_Init 2 */
}Notification is also enabled.
if (HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK)
{
Error_Handler();
}Callback function
CAN_RxHeaderTypeDef gRxHeader;
uint8_t gRxData[8];
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
printf("Hi from CB\r\n");
if (HAL_CAN_GetRxMessage(&hcan1, CAN_RX_FIFO0, &gRxHeader, gRxData) == HAL_OK){
printf("ID: 0x%03lX DLC: %lu Data:", gRxHeader.StdId, gRxHeader.DLC);
for (uint8_t i = 0; i < gRxHeader.DLC; i++){
printf(" %02X", gRxData[i]);
}
printf("\r\n");
}
}What Works
What Doesn't Work
I have tried changing the filter configuration still that didn't worked.
2026-06-03 5:40 AM
2026-06-03 5:53 AM - edited 2026-06-03 5:53 AM
Thank you for the sharing.
I meant to use this config:
For the clock (if the crystal is at 25MHz). Please ensure you have 25MHz.
and CAN bit timing:
2026-06-03 6:21 AM
Hey ,
Even with the config you sent, the same issue persist.
For you reference i have also attached log for the MSR and MCR register data.
CAN Transm starts fails right after the 3rd transmission everytime as well. and timeout happens when waiting for the HAL_CAN_GetTxMailboxesFreeLevel().
18:43:07:287 -> MCR: 0x00010021 MSR: 0x00000C09
18:43:07:291 -> CAN driver init done
18:43:07:295 -> Start: 0 MSR: 0x00000C08 Err: 0x00000000 CAN State: 2
18:43:07:298 -> CAN_SENT
18:43:08:456 -> CAN_SENT
18:43:09:458 -> CAN_SENT
18:43:11:459 -> Timeout
18:43:11:467 -> CAN_FAIL
18:43:13:462 -> Timeout
18:43:13:463 -> CAN_FAIL
18:43:15:465 -> Timeout
18:43:15:466 -> CAN_FAIL
18:43:17:467 -> Timeout
18:43:17:469 -> CAN_FAIL
18:43:19:495 -> Timeout
18:43:19:496 -> CAN_FAIL
18:43:21:477 -> Timeout
18:43:21:479 -> CAN_FAIL
18:43:23:477 -> Timeout
18:43:23:481 -> CAN_FAIL
18:43:25:479 -> Timeout
18:43:25:482 -> CAN_FAIL
18:43:27:483 -> Timeout
2026-06-03 6:58 AM
Hello,
Sorry I don't know.
Check your Arduino config (CAN config/timings etc ..) as we don't have any idea about your setup from that side and we don't support Arduino hardware/environment.
Check also your Hardware and wiring
Check the filters as I suggested earlier.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.