2023-03-25 02:40 AM
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
2023-03-25 03:55 AM
Hello. Is it possible to show your code ?
2023-03-25 04:02 AM
>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
2023-03-25 04:56 AM
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
2023-03-25 05:01 AM
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.
2023-03-25 05:20 AM
one 120r on each end . check the can/usb adapter to have a resistor - if not, try and add one there also.
2023-03-25 06:00 AM
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?
2023-03-25 06:14 AM
you should make some error handling -> reset/restart ...
https://www.csselectronics.com/pages/can-bus-errors-intro-tutorial
2023-03-29 04:18 AM
Thanks, by the way. I notice that the reason of the problem was about EMI. When i do shielding correctly, the problem was solved.