Skip to main content
Associate II
February 21, 2024
Solved

Some of CAN packet have trouble.

  • February 21, 2024
  • 2 replies
  • 8012 views

Hello. 

I am developing CAN communication protocols using STM32F429.
However there is a problem in sending CAN frame data.

 

Here is a picture which I captured in CAN TX using logic analyzer, and as you can see, the series of data is losted after first data.

interactics_ST_0-1708505983865.png

I tested this with publishing 100Hz, this problem occurred once a minute.

In normal case, it should be like this.

interactics_ST_1-1708506289458.png

 

And also I add my code for helping to understanding.

 

 __disable_irq();

	motorCANTxMailBox = HAL_CAN_GetTxMailboxesFreeLevel(&hcan1);
 HAL_CAN_AddTxMessage(&MTRL_CAN, &motorCANTxHeader, &motorCANTxData[0], &motorCANTxMailBox);

 __enable_irq();

 

I disabled the non-automatic retransimission and enabled automatic bus-off feature.

But I wonder why the retransimission did not occur.

 

 

 

This topic has been closed for replies.
Best answer by interactics_ST

I found a trouble in my system.

I had added one more CAN Slave which received the data frames from the STMF4 board, and this was the reason why the CAN BUS didn't work.

After I eliminated this board, the system worked well.

 

Thank you so much for looking into my problem.

 

 

 

2 replies

mƎALLEm
Technical Moderator
February 21, 2024

Hello,

You need to provide more details:

  • Your HW: which board? Your own HW or ST board?
  • If possible schematics
  • Bus configuration, used transceivers.. termination resistors etc ..
  • What is the system clock source you're using: HSE or HSI?
  • Are you seeing some acknowledgement for the send messages?

Thank you.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate II
February 21, 2024

Thank you for your fast answer.

This is my own board.

Firstly, here is the schematic about CAN

interactics_ST_1-1708507490365.png

The clock source is HSE and it provide 45Mhz to APB.

I set up the configuration like below.

 

interactics_ST_3-1708507760267.png

 

Add : 

I disabled the non-automatic retransmission and enabled automatic bus-off feature.
But I wonder why the retransmission did not occur.

and attach another packet loss below

interactics_ST_0-1708508088147.png

 

mƎALLEm
Technical Moderator
February 21, 2024

What is connected in the other side of the bus? does it have the same bitrate config 100kb/s?

What is the purpose of R23/C21 and R24/C22? it was the recommendation in DS transceiver?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
mƎALLEm
Technical Moderator
February 21, 2024

Please check my points before.

Also share your two projects: STM32F429 and STM32G0 (at least the ioc files) so I can look at them later.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Associate II
February 21, 2024

I can't show all my code because of the confidential. Instead, I show the CAN part of my codes.

 

here is the G0 code which is responsible for receiving the CAN frame.  

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs){
	if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET){

		HAL_StatusTypeDef ref;

		ref = HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData);
		if (ref == HAL_OK){

			RxSLCANFrame.can_id = RxHeader.Identifier;
			tester = RxSLCANFrame.can_id;
			if ((RxSLCANFrame.can_id & uint32_t(0x0f)) == NODE_ID){

				RxSLCANFrame.can_id = (RxSLCANFrame.can_id & 0xfffffff0);

				memcpy(RxSLCANFrame.data, RxData, CAN_Frame_len);

				CB_push(&cb_can_frame, &RxSLCANFrame);
				RxCANFrameFlag = true;
			}
		} else {
			Error_Handler();
		}

		ref = HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);

		if (ref == HAL_OK){
		} else {
			Error_Handler();
		}
	}
}

 

and here is F4 code which is in charge of transmitting the packets. and changed some name of the variables.

void CANCmd(const uint32_t node_id, const float rad1, const float rad2){
 uint32_t diriect_ID = 0x700 + node_id;
 uint8_t data[8] ={0,};
 
 data_frame64_t position_cmd_data;

 position_cmd_data.data_float_t[0] = rad1;
 position_cmd_data.data_float_t[1] = rad2;

 CANPacketCreate(diriect_ID, position_cmd_data.data8_t);
 CANWrite();
}

void CANPacketCreate(uint32_t id, uint8_t *data){
 CANTxHeader.StdId = id;
 CANTxHeader.RTR = CAN_RTR_DATA;
 CANTxHeader.IDE = CAN_ID_STD;
 CANTxHeader.DLC = 8;

 memset(CANTxData, 0, 8);
 memcpy(CANTxData, data, 8);

 CANTxMailBox = HAL_CAN_GetTxMailboxesFreeLevel(&MTRL_CAN);
}

void motorCANWrite(){
 CANTxMailBox = HAL_CAN_GetTxMailboxesFreeLevel(&MTRL_CAN);
 __disable_irq();
 HAL_CAN_AddTxMessage(&MTRL_CAN, &CANTxHeader, &CANTxData[0], &CANTxMailBox);
 __enable_irq();

}

 

mƎALLEm
Technical Moderator
February 21, 2024

Sorry I need at least ioc files otherwise I can't help you efficiently.

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