Skip to main content
Aaronium
Associate III
December 26, 2020
Question

Nucleo-F446RE - CAN Bus not initializing.

  • December 26, 2020
  • 1 reply
  • 3993 views

Hello!

I have been trying to get the CAN system on this to work unsuccessfully for some time now, and in trying to debug the code have added some SWV ITM console printf's. In running the code, the HAL_CAN_Init, HAL_CAN_ConfigFilter, HAL_CAN_ActivateNotification, and HAL_CAN_AddTxMessage are all getting errors. I have no idea what I am doing wrong, I have used other posts on this forum as a reference, but am still lost.

Thank y'all for your time.

This topic has been closed for replies.

1 reply

KnarfB
Super User
December 26, 2020

Your code does not look bad. Some details: HAL_CAN_Start is commented out? Put it after HAL_CAN_ActivateNotification.

HAL_CAN_RxFifo0MsgPendingCallback gets already a *hcan parameter, so taking &hcan1 in your call to HAL_CAN_GetRxMessage is wrong.

For testing, put the CAN1_TX in the loop with some delay after each call. What do you have attached to the pins?

What are your specific error messages?

I attach some M0 code for reference, works in loopback when the pins left open.

good luck

KnarfB

Aaronium
AaroniumAuthor
Associate III
December 26, 2020

I appreciate the help so much. The error notifications I'm getting are from the printf statements inside the if's that link to Error_Handler(). The outputs are listed next to their corresponding functions:

Error initializing CAN -- HAL_CAN_Init

Error configurating filter -- HAL_CAN_ConfigFilter

Error activating notifications -- HAL_CAN_ActivateNotification

Error launching CAN -- HAL_CAN_Start

Error adding TX Message -- HAL_CAN_AddTxMessage

Error adding TX Message

Error adding TX Message

I tweaked the code trying to mimic the example you gave (I appreciate it!), but still am having no luck. Also, how could one call HAL_CAN_GetRxMessage without the &hcan1 argument? There is nothing attached to the pins, the CAN is in loopback mode, which I understand that it means that the CAN TX and RX pins are bound internally?

Thank you again.

KnarfB
Super User
December 26, 2020

Start a debug session and step through the code. Step into HAL_CAN_Init and into HAL_CAN_MspInit to see what exactly causes the error.

> how could one call HAL_CAN_GetRxMessage without the &hcan1 argument

No, the first argument should be hcan1 because thats already a pointer. Check code compilation for warnings, try to understand and fix all warnings.

> There is nothing attached to the pins, the CAN is in loopback mode, which I understand that it means that the CAN TX and RX pins are bound internally?

Yes, leaving RX and TX unconnected should work.