cancel
Showing results for 
Search instead for 
Did you mean: 

CAN BUS CubeMx Settings and Transmit - F091CC

Rachel Duray
Associate II
Posted on July 05, 2018 at 10:42

Greetings everyone,

   I encountered a problem with CAN bus during individual work with STM microcontrollers. First of all I would like to give you some information on what I use.

-I am using a microcontroller STM32f091CCTx

-I use CubeMx software.

   What I want to do is to view the CAN data from the CAN output of my card with PCAN Viewer.However, I can not get a result despite my long efforts and I open this post to discuss its reasons. First I want to share my CubeMx settings.

0690X00000604jiQAA.jpg

I set the PB8 and PB9 outputs to Can Rx and Can Tx in the microcontroller schematic.I have chosen HSE crystal in the RCC as a clock because I have always seen it in similar cases.

When I look at the clock settings, I learned that FCLK is used for the CAN bit rate setting. I set the clock rate to be 36Mhz according to the settings in the prescalar table because the bit rate I want to work is 500kbit/sec.

0690X0000060CCDQA2.png

To adjust the CAN settings, I made the Prescaler settings as seen in the table above.

---------------------------------------------------------------------

After the source code was created, I started coding. I used the HAL library for CAN encoding. The first thing I did was create a variable of type CAN_HandleTypeDef and name it hcan.

0690X0000060CD6QAM.png

Then I made the necessary codings to send the message as below. In this example, ID 0x244 Data was 0x7.

0690X0000060CCIQA2.png

Finally, I sent the message frame using the HAL library(for the transmit) in the main loop at intervals of 100 ms.

0690X0000060CCNQA2.png

Despite all this, I did not find any data on the PCAN Viewer output. The CAN Networks and CAN Loopback examples in st website do not include up-to-date HAL libraries.

Where am I making mistakes. What is missing to send these messages. I will be glad if you help me.

Thanks.

#hal_can_transmit #canbus #hal-libraries #hal-can-driver #cubemx-4.25.1 #hal-li*
1 ACCEPTED SOLUTION

Accepted Solutions
Rachel Duray
Associate II
Posted on July 12, 2018 at 16:16

I resolve my problem. My problem is selecting HSE clock as an Crystal Clock ( 2 pin ). My external clock has 1 pin so  i changed it as BYPASS clock source and it works!!

0690X0000060M9MQAU.png

View solution in original post

2 REPLIES 2
Rachel Duray
Associate II
Posted on July 05, 2018 at 10:44

I forgot the add CAN configurations. I put it below

0690X0000060LZUQA2.png
Rachel Duray
Associate II
Posted on July 12, 2018 at 16:16

I resolve my problem. My problem is selecting HSE clock as an Crystal Clock ( 2 pin ). My external clock has 1 pin so  i changed it as BYPASS clock source and it works!!

0690X0000060M9MQAU.png