Skip to main content
Visitor II
March 25, 2023
Question

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

  • March 25, 2023
  • 3 replies
  • 4011 views

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

    This topic has been closed for replies.

    3 replies

    Graduate II
    March 25, 2023

    Hello. Is it possible to show your code ?

    Super User
    March 25, 2023

    >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

    Visitor II
    March 25, 2023

    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.

    Super User
    March 25, 2023

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

    Visitor II
    March 25, 2023

    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