Skip to main content
Graduate II
January 29, 2024
Solved

I can not send message from PCAN to STM32F407VGT-DISC1 board.

  • January 29, 2024
  • 2 replies
  • 2203 views

Dear all,

I set up a configuration to send message from ST board to PCAN USB and the other way around. When I send message from board to PCAN, it works just fine. I can see in the PCAN-View screen that the message is received successfully as shown below.

 

demir_0-1706501897116.png

On the other hand, I would like to send message from PCAN-View to board as well. But, I dont know how I can do that. I can set up message to transmit as see in below image, but how can I make sure if this message is received by the board? What should be the message ID for the message transmitted ?

demir_1-1706502067615.png

 

Please also see below the configuration of CAN controller.

demir_0-1706502382005.png

 

Could anyone please support me with this ?

I have also attached the main.c file that I use for this task. 

Thanks.

 

 

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

    Hello,

    Confusing CAN config:

     MX_CAN1_Init();
     MX_USART2_UART_Init();
     /* USER CODE BEGIN 2 */
    CAN1_Init();

    You have two CAN1 configs here. And in the second call you configure CAN1 in loopback mode.

    Could you please check?

    2 replies

    mƎALLEmAnswer
    Technical Moderator
    January 29, 2024

    Hello,

    Confusing CAN config:

     MX_CAN1_Init();
     MX_USART2_UART_Init();
     /* USER CODE BEGIN 2 */
    CAN1_Init();

    You have two CAN1 configs here. And in the second call you configure CAN1 in loopback mode.

    Could you please check?

    demirAuthor
    Graduate II
    January 29, 2024

    Thank you it works now!

    One thing I do wonder though, static void MX_CAN1_Init(void) function comes automatically when I generate code via .ioc. Then, I define another function for can initialization. So, I wonder that, which one is valid ? Am I supposed to remove one of them or is that OK if I just modify MX_CAN1_Init(void) as I like and remove the other CAN_Init function ?

    Technical Moderator
    January 29, 2024

    No need to create another function for initialization. What is the purpose of CubeMx if you initialize the peripheral yourself?

    The philosophy behind CubeMx is to configure the peripheral in the CubeMx GUI by the user and it generates the code according to it. Then user can add his application or other initialization. But in your case you initialized the same stuff twice.

    Look at the core of 

    MX_CAN1_Init()

    and 

    CAN1_Init()

     So keep MX_XXX() initialization functions generated by CubeMx and populate your code with your application

    demirAuthor
    Graduate II
    January 29, 2024

    I am using STM32CUBE IDE. 

    Your explanation makes sense, thank you.

    Technical Moderator
    January 29, 2024

    Juts a clarification: STM32CUBE IDE is the toolchain (compiler, debugger ..) and CubeMx is the peripheral configurator/code generator :).