Skip to main content
Visitor II
June 26, 2021
Question

STM32F103 CAN CYCLE TIME

  • June 26, 2021
  • 1 reply
  • 984 views

Hi,

I am STM32F103 with 72Mhz clock and am trying to send the CAN messages (MCP2561 as CAN transceiver) with 500kbps and am using CAN BUS ANALYZER to check the CAN msgs.

Here am sending 3 CAN msgs for every 100ms using timer interrupt but some times some msgs are missing so that am getting the CAN cycle time as 200ms.

Here am attaching some code.

what I have to do eliminate this error ?

Thanks

void MX_CAN_Init(void)
{
 hcan.Instance = CAN1;
 hcan.Init.Prescaler = 9;
 hcan.Init.Mode = CAN_MODE_NORMAL;
 hcan.Init.SyncJumpWidth = CAN_SJW_1TQ;
 hcan.Init.TimeSeg1 = CAN_BS1_3TQ;
 hcan.Init.TimeSeg2 = CAN_BS2_4TQ;
 hcan.Init.TimeTriggeredMode = DISABLE;
 hcan.Init.AutoBusOff = DISABLE;
 hcan.Init.AutoWakeUp = DISABLE;
 hcan.Init.AutoRetransmission = DISABLE;
 hcan.Init.ReceiveFifoLocked = DISABLE;
 hcan.Init.TransmitFifoPriority = DISABLE;
 if (HAL_CAN_Init(&hcan) != HAL_OK)
 {
 Error_Handler();
 }
 
}
 
void Send_msg1(void)
{
 txHeader.IDE = CAN_ID_EXT;
 txHeader.ExtId = 0x14244050;
 txHeader.RTR = CAN_RTR_DATA;
 txHeader.DLC = 8;
 txHeader.TransmitGlobalTime = DISABLE;
 if (HAL_CAN_AddTxMessage(&hcan, &txHeader,msg1,&canTxMailbox1) != HAL_OK)
 {
 Error_Handler();
 }
 }
	
void Send_msg2(void)
{
 txHeader.IDE = CAN_ID_EXT;
 txHeader.ExtId = 0x10281050;
 txHeader.RTR = CAN_RTR_DATA;
 txHeader.DLC = 8;
 txHeader.TransmitGlobalTime = DISABLE;
 if (HAL_CAN_AddTxMessage(&hcan,&txHeader,msg2,&canTxMailbox2) != HAL_OK)
 {
 Error_Handler();
 }
 }
 
 void Send_msg3(void)
{
 txHeader.IDE = CAN_ID_EXT;
 txHeader.ExtId = 0x14234050;
 txHeader.RTR = CAN_RTR_DATA;
 txHeader.DLC = 8;
 txHeader.TransmitGlobalTime = DISABLE;
 if (HAL_CAN_AddTxMessage(&hcan,&txHeader,msg3,&canTxMailbox3) != HAL_OK)
 {
 Error_Handler();
 }
 
}

    This topic has been closed for replies.

    1 reply

    Visitor II
    October 18, 2024

    Hey,

    I am getting the same issue i am using STM32G0B1, still not able to find the issue.
    is this resolved at your end?

    bhupendersingh_0-1729252179670.png

    the above cycle time fluctuate between 200ms and 300ms. 

    Any feedback will be appreciated.

    Technical Moderator
    October 18, 2024

    Hello @bhupender-singh and welcome to the community,

    I invite you to open a new thread as this dates from 2021 and provide more information not only a screenshot.

    Share code using </> button or attach your project in zip or rar format.

    Thank you