cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F423 bxCAN + Arduino MCP2515 — CAN reception issue

nikhilkrn
Associate II

Hardware connection

  • Node A: STM32F423RHTx, TCAN1462-Q1 transceiver, HSI→PLL→80MHz SYSCLK, 40MHz APB1, PA11/PA12
  • Node B: Arduino Uno + MCP2515 breakout (8MHz xtal, onboard transceiver), mcp_can v1.5. 120Ω termination, wiring verified 
  • CAN Timing (both at 500kbps)

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

  • STM32 → Arduino: Arduino serial monitor shows received frames every 1 second
  • STM32 Loopback mode: receives own frames internally
  • STM32 register dump: IER=0x02 (FMPIE0 armed), MSR shows normal mode, filter active

What Doesn't Work

  • Arduino → STM32: RF0R.FMP permanently 0, REC=0, interrupt never fires
  • Arduino sendMsgBuf returns CAN_SENDMSGTIMEOUT (7), EFLG=0x15 (TXEP+TXWAR+EWARN)
  • STM32's own TX frames show ACK Error (LEC=0x3) and TERR0=1 despite Arduino claiming to receive them — ACK contradiction

I have tried changing the filter configuration still that didn't worked.

13 REPLIES 13
mƎALLEm
ST Employee

Hello @nikhilkrn and welcome to the ST community,


First thing to check is your hardware: the wiring: especially the bad contacts.

Second issue: 


@nikhilkrn wrote:
  • Node A: STM32F423RHTx, TCAN1462-Q1 transceiver, HSI→PLL→80MHz SYSCLK, 40MHz APB1, PA11/PA12

You should avoid using HSI for CAN communication in Normal mode. Use a crystal or you can face comm issues. Please refer to these articles:

CAN reception issues: Reasons and general troubleshooting

Using CAN (bxCAN) in Normal mode with STM32 microcontrollers (Part 1)

Using CAN (bxCAN) in Normal mode with STM32 microcontrollers (Part 2)

Hope that helps.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi @mƎALLEm , 

Thanks for the response. I've since switched to HSE (25 MHz crystal on PH0/PH1 with PLL: M=12, N=96, P=2 → SYSCLK=100 MHz, APB1=50 MHz, CAN Prescaler=10) — no more HSI.
After all fixes, both nodes confirmed at exactly 500 kbps. STM32 → Arduino works reliably. Register-level checks on the STM32 side show:

  • IER = 0x02 
  • MSR = 0x00000C08 (INAK=0, SLAK=0 — normal mode)
  • FA1R confirms filter bank 0 active (catch-all 32-bit mask)
  • Interrupt chain verified: NVIC enabled, IRQHandler wired, notification activated
  • ESR = 0x00000000 consistently: REC=0, TEC=0 — no errors, but also no frames.

I have a doubt that if Transmission works then it shouldn't be hardware issue?

I have checked the articles as well still facing the same issue. 

1- Please share your complete project

2- What are the power supply voltage levels of the TCAN1462-Q1 transceiver: VCC and VIO?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
nikhilkrn
Associate II

Hi,
I have attached the project file.


@nikhilkrn wrote:

Hi,
I have attached the project file.


Thank you for the sharing but you didn't answer my second question.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi,
VIO: 3V3
VCC: 5V
It's a custom board with stm32f423RHT6 mcu. I have tried with other transiver as well separately but still issue is same.
let me know if you need any more information.
Thanks!!

mƎALLEm
ST Employee

You are still pointing to HSI as clock source:

mALLEm_0-1780487324529.png

Even though the clock config in the main configures HSE as clock source for PLL:

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 12;
  RCC_OscInitStruct.PLL.PLLN = 96;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

So there is a mismatch between the ioc file and main. You need to regenerate the code with HSE selected as source clock in the ioc file and retest.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Ozone
Principal III

Assuming you don't have a protocol analyser something similiar, have you tried a lower bitrate ?

mƎALLEm
ST Employee

+

There is a mismatch in the filter config in tha attached project:

  canfilterconfig.FilterBank = 0;
  canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig.FilterIdHigh = 0x0F6<<5;
  canfilterconfig.FilterIdLow = 0x0000;
  canfilterconfig.FilterMaskIdHigh = 0x0F6<<5;
  canfilterconfig.FilterMaskIdLow = 0x0000;
  canfilterconfig.FilterFIFOAssignment = CAN_RX_FIFO0;
  canfilterconfig.FilterActivation = CAN_FILTER_ENABLE;
  canfilterconfig.SlaveStartFilterBank = 14;

And what you have shared in the first post: 

  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;

 So please restore the first filters config:

  canfilterconfig.FilterMode = CAN_FILTERMODE_IDMASK;
  canfilterconfig.FilterScale = CAN_FILTERSCALE_32BIT;
  canfilterconfig.FilterIdHigh = 0x0000;
  canfilterconfig.FilterIdLow = 0x0000;
  canfilterconfig.FilterMaskIdHigh = 0x0000;
  canfilterconfig.FilterMaskIdLow = 0x0000;

Please don't post many configuration for the same issue. So it muddies the waters.

So what I suggest is to provide a complete project on which you did the final test with:

mALLEm_2-1780488241221.png

and

mALLEm_3-1780488254326.png

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Announcement

We’re moving the ST Community to a new platform to give you a better and more reliable community experience.