Skip to main content
Associate
November 4, 2024
Solved

CAN Communication Issue

  • November 4, 2024
  • 2 replies
  • 1133 views

Hi,

I am using STM32F446RE Nucleo and a Peak CAN Usb to test the CAN functionality of the microcontroller. I have connected the Microcontroller to a CAN Transceiver (TJA1050) and added a 120ohm resistor between the CANH and CANL line. I have attached the config of the CAN hardware below

 

 hcan1.Instance = CAN1;
 hcan1.Init.Prescaler = 42;
 hcan1.Init.Mode = CAN_MODE_NORMAL;
 hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
 hcan1.Init.TimeSeg1 = CAN_BS1_2TQ;
 hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;
 hcan1.Init.TimeTriggeredMode = DISABLE;
 hcan1.Init.AutoBusOff = DISABLE;
 hcan1.Init.AutoWakeUp = DISABLE;
 hcan1.Init.AutoRetransmission = DISABLE;
 hcan1.Init.ReceiveFifoLocked = DISABLE;
 hcan1.Init.TransmitFifoPriority = DISABLE;

 

When I transmit a message using the Peak CAN, I get  "Frame stuff error (Rx)". I have already attempted to

  • Change the baud rate
  • Remove the resistor
  • Tried a different Peak CAN
  • Changed the Transceiver (3 times)

 

Is the issue from the Transceiver or the microcontroller? Is there any way to check the functionality of the transceiver?

Thanks in advance!

Best answer by mƎALLEm

Hello @SriramK34  and welcome to the community,

 hcan1.Init.Prescaler = 42;
 hcan1.Init.TimeSeg1 = CAN_BS1_2TQ;
 hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;

These are very bad config parameters: BS1 is very low and < BS2.

Need to decrease the prescaler as much as possible and increase BS1 and BS2 as much as possible to fit your bitrate where BS1 = ~(70% to 85%) (BS1+BS2).

2 replies

mƎALLEm
mƎALLEmAnswer
Technical Moderator
November 4, 2024

Hello @SriramK34  and welcome to the community,

 hcan1.Init.Prescaler = 42;
 hcan1.Init.TimeSeg1 = CAN_BS1_2TQ;
 hcan1.Init.TimeSeg2 = CAN_BS2_1TQ;

These are very bad config parameters: BS1 is very low and < BS2.

Need to decrease the prescaler as much as possible and increase BS1 and BS2 as much as possible to fit your bitrate where BS1 = ~(70% to 85%) (BS1+BS2).

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
SriramK34Author
Associate
April 30, 2025

Hi, 

Seems like the issue was from using HSI oscillator for the clock source. When setting the bitrate to 250KHz, I was getting a lower frequency (which I assume is due to error in the HSI oscillator). Adding an external crystal with the correct capacitors to generate exact 16MHz has fixed the issue. 

PS. we have also changed the parameters to match the sample point of CANOPEN, as we have a CANOPEN device on the bus. 

Regards Sriram.