cancel
Showing results for 
Search instead for 
Did you mean: 

CANBUS communication stops after a while. Is there any solution to make up. (e.g. reset communication)?

KondenserSoketi
Associate II

Hello everyone. I use STM32F4 to transmit CANBUS messages. When i connect Can High and Can Low lines to CAN-USB transformer i see messages coming to computer but after a short while the communication between MCU and computer stops. If i reset the MCU, message flows restarts but the same problem occurs again.

Has anyone encountered and solved such a problem?

Thanks

8 REPLIES 8
JTP1
Lead

Hello. Is it possible to show your code ?

AScha.3
Chief II

>Has anyone encountered and solved such a problem?<

jepp. do you have termination resitors on both line ends ?

-> if errors -> If the "transmit error counter" is above 255, the CAN interface transitions into this state.

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000kGnGSAU

If you feel a post has answered your question, please click "Accept as Solution".
KondenserSoketi
Associate II

This is the part of my code related canbus.

int main(void)

{

 MX_GPIO_Init();

 MX_DMA_Init();

 MX_CAN1_Init();

 HAL_CAN_Start(&hcan1); //CAN başlatılır..

 HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);

 pTxHeader.DLC = 8; //

 pTxHeader.IDE = CAN_ID_EXT; //

 pTxHeader.RTR = CAN_RTR_DATA; // .

 pTxHeader.ExtId = 0x56718119; //

 //Set Transmit Parameters for second mailbox

 pTxHeader1.DLC = 8;

 pTxHeader1.IDE = CAN_ID_EXT;

 pTxHeader1.RTR = CAN_RTR_DATA;

 pTxHeader1.ExtId = 0x55738119;

 //Set Transmit Parameters for third mailbox

 pTxHeader2.DLC = 8;

 pTxHeader2.IDE = CAN_ID_EXT;

 pTxHeader2.RTR = CAN_RTR_DATA;

 pTxHeader2.ExtId = 0x54748119;

 sFilterConfig.FilterActivation = ENABLE;

 sFilterConfig.FilterBank = 0;

 sFilterConfig.FilterFIFOAssignment = CAN_FILTER_FIFO0; /

 sFilterConfig.FilterIdHigh = 0x10121981 >> 13;

 sFilterConfig.FilterIdLow = 0x10121981 << 3 | CAN_IDE_32;

 sFilterConfig.FilterMaskIdLow = 0xAAAAAAAA << 3 | CAN_IDE_32;

 sFilterConfig.FilterMaskIdHigh = 0xAAAAAAAA >> 13;

 sFilterConfig.FilterMode = CAN_FILTERMODE_IDLIST;

 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);

 while (1)

 {

HAL_CAN_AddTxMessage(&hcan1, &pTxHeader, &count, &pTxMailbox);

HAL_CAN_AddTxMessage(&hcan1, &pTxHeader1, &count1, &pTxMailbox1);

HAL_CAN_AddTxMessage(&hcan1, &pTxHeader2, &count2, &pTxMailbox2);

}

Thanks

Hello AScha,

I have ended can high and can low terminals with 120Ohm resistor. High and low terminals were connected to can usb tranciever.

So, you mean i must add one more 120Ohm resistor?

Thank you.

0693W00000aJhBTQA0.pngone 120r on each end . check the can/usb adapter to have a resistor - if not, try and add one there also.

If you feel a post has answered your question, please click "Accept as Solution".

Actually, now it is working well. But i deconnect the usb from one computer and connect the other computer (same can-usb interface exists each computer) the problem i mentioned occurs. It is interesting.

In this context, is it necessary to reset the can communication in the software?

you should make some error handling -> reset/restart ...

https://www.csselectronics.com/pages/can-bus-errors-intro-tutorial

If you feel a post has answered your question, please click "Accept as Solution".

Thanks, by the way. I notice that the reason of the problem was about EMI. When i do shielding correctly, the problem was solved.