Skip to main content
Graduate
March 25, 2024
Solved

CAN frame monitoring problem in loopback mode

  • March 25, 2024
  • 2 replies
  • 2224 views

@mƎALLEm hello again,

 

So , i am facing a problem to display the frame i am supposed to send from CAN_Tx pin in loopback mode. I am using picoscope to display.

Here is the function i wrote to configure the Header, and send the data:

void CAN_send(void)

{

char msg[50];

CAN_TxHeaderTypeDef TxHeader;

uint32_t TxMailbox;

uint8_t TxData[4] = {'T','E','S','T'};

 

TxHeader.DLC = 4; // 4 data byte

TxHeader.ExtId = 0; // Not used so far

TxHeader.IDE = CAN_ID_STD; // Standard ID

TxHeader.RTR = CAN_RTR_DATA; // Data and not remote frame

TxHeader.StdId = 0x103; // Data ID

TxHeader.TransmitGlobalTime = DISABLE;

 

if(HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox)!=HAL_OK)

{

Error_Handler();

}

while( HAL_CAN_IsTxMessagePending(&hcan1, TxMailbox));

 

sprintf(msg, "Message transmitted\r\n");

HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);

}

 

In the Main function, i am calling it after the HAL_CAN_Start function. The uart connexion tells me that the frame is sent but i can't see it though.

Thank you again for your precious help!

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Thank you for the shared main file:

    I noticed two issues:

    In the timing configuration:

    hcan1.Init.TimeSeg1 = CAN_BS1_1TQ;
    hcan1.Init.TimeSeg2 = CAN_BS2_8TQ;

    And with the filter configuration:

    canfilterconfig.FilterBank = 10;
    canfilterconfig.SlaveStartFilterBank = 0;

    So try these configurations:

     hcan1.Init.TimeSeg1 = CAN_BS1_7TQ;
     hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;

    and

     canfilterconfig.FilterBank = 0;
     canfilterconfig.SlaveStartFilterBank = 14;

    2 replies

    mƎALLEmAnswer
    Technical Moderator
    March 25, 2024

    Thank you for the shared main file:

    I noticed two issues:

    In the timing configuration:

    hcan1.Init.TimeSeg1 = CAN_BS1_1TQ;
    hcan1.Init.TimeSeg2 = CAN_BS2_8TQ;

    And with the filter configuration:

    canfilterconfig.FilterBank = 10;
    canfilterconfig.SlaveStartFilterBank = 0;

    So try these configurations:

     hcan1.Init.TimeSeg1 = CAN_BS1_7TQ;
     hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;

    and

     canfilterconfig.FilterBank = 0;
     canfilterconfig.SlaveStartFilterBank = 14;
    Erwan03Author
    Graduate
    March 25, 2024

    Nothing changed: 

    Erwan03_0-1711377842439.png

    Let me inform you than i got it to work once but several weeks ago and when i added some structures and other functions in order to fit it into a real project then it couldn't work anymore. And the parameters you asked me to change were the same unfortunately.

    Erwan03Author
    Graduate
    March 25, 2024

    Wait Wait! It works actually.

    The debug mode does not allow us to see a frame. Only run mode. Thank you for your help!

     

    Erwan03_0-1711378661796.png

     

    Have a nice day!

    Technical Moderator
    March 25, 2024

    @Erwan03 wrote:

    Wait Wait! It works actually.

    The debug mode does not allow us to see a frame. Only run mode. Thank you for your help!

     

    Erwan03_0-1711378661796.png

     

    Have a nice day!


    Nice! You're welcome :smiling_face_with_smiling_eyes: .. But still strange it could not be running in debug mode!

    Which Toolchain are you using? I will try it with a NUCLEO-F446RE board when I have one on hands.