cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Loopback on STM32L431KCU Issue

tom21
Associate II

I am trying to get the CAN Loopback up and running on my STM32L431KCU (CAN1), I have tried to follow the: Guide to CAN (bxCAN/CAN2.0) configuration in Loop back mode on STM32 MCUs. But I am getting stuck in the "HAL_CAN_Start()" function where its waiting for the acknowledgement: 

/* Wait the acknowledge */

while ((hcan->Instance->MSR & CAN_MSR_INAK) != 0U)

{

/* Check for the Timeout */

if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)

{

/* Update error code */

hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;



/* Change CAN state */

hcan->State = HAL_CAN_STATE_ERROR;



return HAL_ERROR;

}

}

I then created a new project following the CAN loopback project listed here to get a working project and around my issue: Solved: CAN bus doesn't work in loopback mode - STMicroelectronics Community

Using the same MX CAN config, APB1 of 80MHz, example program, and I still run into being stuck in the "HAL_CAN_Start()". I am using STM32CubeIDE 2.0.0 and MX 6.16.1, any help would be much appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

I didn't catch any issue in your code.

The remaining question: is there something connected on PA11 or PA12? if yes, you shoud absolutely disconnect any external hardware from these pins except if you have a CAN tranceiver on these pins.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
mƎALLEm
ST Employee

Hello @tom21 and welcome to the ST community,

You can refer to this knowledge base article: Guide to CAN (bxCAN/CAN2.0) configuration in Loop back mode on STM32 MCUs

If you followed that guide and didn't work I'm sure you missed something on that guide!

In next time please use </> button to paste your code.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Hi @mƎALLEm ,

I started clean and walked through the guide again step-by-step, did not have any luck it still errors out in the HAL_CAN_START() function waiting for the INAK to clear. Any other suggestions? 

Thanks

Could you please share your project?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Sure thing, see attached.

Hello,

I didn't catch any issue in your code.

The remaining question: is there something connected on PA11 or PA12? if yes, you shoud absolutely disconnect any external hardware from these pins except if you have a CAN tranceiver on these pins.

 

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

@mƎALLEm after talking the board layout over it looks like we might have connected PA11 pin to a wakeup pin on another component on the board. Thanks for your help!


@tom21 wrote:

we might have connected PA11 pin to a wakeup pin on another component on the board. Thanks for your help!


Indeed that explains the behavior.

I need to update this article (Troubleshooting bxCAN issues in Loop back mode on STM32 MCUs) with this constraint..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.