cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus Not Receiving Messages on STM32F4 + TJA1050 (CJMCU-230)

hamza_enes
Associate

I'm trying to set up CAN communication between two STM32F4 boards using CJMCU-230 transceivers, but I'm not receiving any messages. Here's a full breakdown of the setup and what I've tried:


Hardware Setup:

  • MCU: STM32F4 Discovery (hcan1)

  • Transceiver: CJMCU-230

  • Second Node: Another STM32F4 with same configuration

  • Bitrate: 125 kbit/s on both ends

  • Termination: 120Ω termination resistor is likely present on the transceiver (CJMCU-230) board, but not manually added externally. I haven't removed or measured it directly, but many CJMCU-230 modules include onboard termination resistors by default.


STM32 Configuration:

txHeader.DLC = 1;
txHeader.IDE = CAN_ID_STD;
txHeader.RTR = CAN_RTR_DATA;
txHeader.StdId = 0x245;
sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0;
sFilterConfig.FilterIdHigh = 0x0000;
sFilterConfig.FilterIdLow = 0x0000;
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
sFilterConfig.FilterActivation = ENABLE; HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig); HAL_CAN_Start(&hcan1); HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
  • GPIO, RCC, NVIC configurations are done correctly.

  • HAL_CAN_Start() and HAL_CAN_ActivateNotification() are called.

  • Transmitting messages works fine; HAL_CAN_AddTxMessage() returns HAL_OK.

The Problem:

  • No CAN message is received via CAN1 RX0 interrupt. The CAN1_RX0_IRQHandler() is never triggered.

  • HAL_CAN_GetRxMessage() returns HAL_ERROR when called in the main loop.

  • HAL_CAN_AddTxMessage() sometimes returns HAL_ERROR in the loop, but returns HAL_OK inside an external interrupt.

  • After sending ~9 messages, the internal hcan1.Instance->ESR register gives a value of 0x800003, which includes:

    • EPVF (Error Passive Flag)CAN controller became error-passive

    • Transmission is no longer possible

  • CAN messages are sent with:

     
    txHeader.StdId = 0x245;
    txHeader.IDE = CAN_ID_STD;
    txHeader.RTR = CAN_RTR_DATA;
    txHeader.DLC = 1;
  • CAN filter is configured in mask mode, accepting all messages (all ID and mask bits set to 0).

  • CAN speed: 125 kbps on both devices.

  • Interrupts and NVIC configuration are properly done.

  • HAL_CAN_Start() and HAL_CAN_ActivateNotification() are called.

Any ideas or guidance on how to fix this would be greatly appreciated.

3 REPLIES 3
CTapp.1
Senior III

A transmitting node going error passive is a sign that there is nothing else on the bus capable of sending out "ack" bits, which makes it look like you have a transceiver or bus issue.

Have you verified that you do have termination resistors (measure the resistance between the CAN high and low)?

Have you used a 'scope or logic analyser to see what is getting onto the bus?

Thanks a lot for your detailed reply and guidance!

You were absolutely right — the problem was with the transceiver. I was using a CJMCU-230 module, which apparently doesn't have a TJA1050 on it. After struggling for a while with no ACKs and constant Error Passive status on the STM32 side, I decided to replace the transceiver.

I switched to a standard TJA1050-based module, and boom — everything started working flawlessly. CAN communication is now solid, ACKs are received properly, and the bus is alive.

Your message pointed me in the right direction. Much appreciated!

CTapp.1
Senior III

Glad it helped.

It would be great if you would accept my original post as the "Accepted solution" so that this thread shows as solved.