cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN on STM32C0: transmitting every 100ms, receiver sees frames only every ~497ms

anuj18ap
Associate II

Post edited by ST moderator to be inline with the community rules for the code sharing. In next time please use </> button to paste your code and a linker script content. Please read this post: How to insert source code.

i, I am using STM32C092CCT6 with FDCAN.
I transmit one CAN frame every 100 ms (even tried 50 ms).
But on the receiver side, I always receive frames only every ~497 ms.

It looks like something is delaying or buffering the frames.

What I want to know:
Which FDCAN settings could cause the frames to appear only every ~497 ms?

My problem summary:

  • Tx interval configured: 100 ms → Rx sees ~497 ms

  • Tx interval configured: 50 ms → Rx still ~497 ms

  • So the transmit timing is not coming out correctly.

Request:
Please check if anything is wrong with my FDCAN configuration (below).

/**
* @brief FDCAN1 Initialization Function
*  None
* @retval None
*/
static void MX_FDCAN1_Init(void)
{

/* USER CODE BEGIN FDCAN1_Init 0 */

/* USER CODE END FDCAN1_Init 0 */

/* USER CODE BEGIN FDCAN1_Init 1 */

/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 16;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 58;
hfdcan1.Init.NominalTimeSeg2 = 1;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */

/* USER CODE END FDCAN1_Init 2 */

}
(Virus scan in progress ...)
7 REPLIES 7
mƎALLEm
ST Employee

Hello,

First, in next time, please use </> button to share your code.

Second, how did you conclude "the frames appear every ~497 ms?"

+ You didn't tell which one is the receiver and which one is the transmitter, how many nodes are availeble on the CAN bus?? and the code above corresponds to which one: receiver or transmitter?

 

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.
anuj18ap
Associate II

As the transmitter, I am using FDCAN1 on the STM32C092CCT6 controller. On the receiver side, for testing purposes, I am using a Korlan USB-CAN Converter.

I concluded that the frames appear every ~497 ms by checking the timestamp difference of the received CAN frames. On the receiver side, I used the canutils command: candump -t d can0. This command prints the time interval between consecutive CAN frames, and it consistently reports about 0.497 seconds between frames.

The code I shared corresponds to the STM32 transmitter. There is only one transmitter (STM32) and one receiver (Korlan USB-CAN) connected on the bus.

Show us a recording of the physical bus signals done with a scope.

> There is only one transmitter (STM32) and one receiver (Korlan USB-CAN) connected on the bus.

If this CAN-USB dongle is in silent mode (listener only), the setup will not work at all.
The STM32 device will quickly reach the "error passive" mode, and after a delay, re-enable transmissions.
Which would explain the "long" delays.

anuj18ap
Associate II

It is not in listener-only mode. The same Korlan USB-CAN device works normally with another controller on the same setup, and I have already tested it with other STM32 series as well, where it works fine. So the dongle is able to acknowledge frames and is not operating as a silent listener.


@Ozone wrote:

Show us a recording of the physical bus signals done with a scope.


+1

 

@Ozone wrote:

If this CAN-USB dongle is in silent mode (listener only), the setup will not work at all.


Except if there is another CAN node on that CAN bus that acknowledges the received frames ;)

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.

Please show also how are you transmitting the frames .. Show the code..

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.
anuj18ap
Associate II

This is how I am transmitting the CAN frames. In the timer interrupt, which runs every 1 ms, I increment a counter and set a flag every 100 ms:

can_temp_Counter++;
if (can_temp_Counter >= 100) {
can_temp_Counter = 0;
txMessage = true;
}

Then in the main loop I check this flag and send the CAN frame:

if (txMessage) {
txMessage = false;
uint8_t txData[8] = "DEADDEAD";
txHeader.Identifier = 0x00A;
txHeader.IdType = FDCAN_STANDARD_ID;
txHeader.TxFrameType = FDCAN_DATA_FRAME;
txHeader.DataLength = FDCAN_DLC_BYTES_8;
txHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
txHeader.BitRateSwitch = FDCAN_BRS_OFF;
txHeader.FDFormat = FDCAN_CLASSIC_CAN;
txHeader.MessageMarker = 0;
HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &txHeader, txData);
}