2024-02-21 01:13 AM - edited 2024-02-21 01:20 AM
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.
I tested this with publishing 100Hz, this problem occurred once a minute.
In normal case, it should be like this.
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.
Solved! Go to Solution.
2024-02-21 03:01 AM
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();
}
2024-02-21 03:15 AM
Sorry I need at least ioc files otherwise I can't help you efficiently.
2024-02-21 03:20 AM - edited 2024-02-21 03:23 AM
OK. I'll upload it later.
2024-02-22 01:18 AM
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.
2024-02-22 02:40 AM
Not sure I understood how you did solve the problem.
You have one F429 board and in the other side there is a CAN analyzer (only two nodes on the bus). So you removed the third board F4! which board? but at first time this board was not connected to the bus!
2024-02-22 03:04 AM
The system actually is rather complicated because this board is one of machine systems. So I couldn't exactly catch the whole system structure.
In fact, STMF4 Board have two another CAN devices. One is STMG4 board which I mentioned, and other is another CAN Device, Battery BMS which I didn't catch. After checked this, I removed the BMS device from CAN BUS and then the problem was recovered.
I'm sorry to gave you some confusing parts.