cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-144 CAN bus example code?

Dick Lin
Senior
Posted on May 30, 2018 at 21:08

Hi,

I am using STM32L496 with Nucleo-144/STM32CubeMX.

Is there any CAN BUS example with HAL Drivers? I can't even find how to setup the baudrate.

Thanks,

****

Note: this post was migrated and contained many threaded conversations, some content may be missing.
12 REPLIES 12
Posted on May 31, 2018 at 21:36

I found this on the internet for 48 MHz clock. Why the setting is different than what you said?

/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;
CAN_InitStructure.CAN_ABOM = DISABLE;
CAN_InitStructure.CAN_AWUM = DISABLE;
CAN_InitStructure.CAN_NART = ENABLE;
CAN_InitStructure.CAN_RFLM = DISABLE;
CAN_InitStructure.CAN_TXFP = ENABLE;
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;
/* CAN Baudrate = 500kbps (CAN clocked at 48 MHz) */
CAN_InitStructure.CAN_BS1 = CAN_BS1_6tq;
CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;
CAN_InitStructure.CAN_Prescaler = 16;
CAN_Init(CAN1, &CAN_InitStructure);
// 48Mhz / ( 8 * ( 1 + 6 + 5) ) = 500Kbps
// 48Mhz / 96

Posted on June 20, 2018 at 20:49

Three weeks later...

https://community.st.com/0D50X00009XkYGHSA3

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 20, 2018 at 21:18

Yeah. First we are using our own dev kit which CANH./L 5V. Then I wasn't get the SystemClock_Config() function correctly.

Then purchase CAN transceiver, enable PEAK termination.

It's painful. 

Now I am moving to flash. Thx