cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Bus Comminucation

Ramazan Gülcan
Associate III
Posted on March 08, 2018 at 10:32

Hi,

Do you have an example of CAN BUS Communication can be done with the current version HAL and CubeMx?

Regards

Ramazan

#can-bus

Note: this post was migrated and contained many threaded conversations, some content may be missing.
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on March 09, 2018 at 14:45

you need a pull up on both Rx pins.

did you set the ABOM bit ?

now you must go out and buy a CANBUS transceiver board and start transmitting from there first.

work on your receiver code first, then transmitter.

I used the CanDo unit to start. Running totally in a few days.

View solution in original post

29 REPLIES 29
Szymon PANECKI
Senior III
Posted on March 08, 2018 at 11:28

Hello Ramazan,

Each STM32 Cube package contains example applications for CAN. I don't know which STM32 MCUs family you want to use, so let me provide you an example for STM32L4. You acn find application under this link:

...\STM32Cube_FW_L4_V1.0\Projects\STM32L476G_EVAL\Examples\CAN

In general you need to go to your Cube package,open Projects folder, select your board, open Examples folder and refer to CAN subfolder. It should contain CAN_Networking example application.This example is not available for all boards, but for many of them it is.

Additionally let me share with you presentation, which guides hwo to develop simple CAN application for STM32L4 MCUs step by step from scratch. Please find this presentation attached. However please note, that this presentation is now a bit obsolete, because it uses not up to date CAN driver. CAN driver was recently updated, so if you would like to use the latest implementation, which is of course recommended, please refer to

https://community.st.com/thread/47095-stm32f4xx-rework-of-hal-can-driver-examples?commentID=186316#comment

.

Regards

Szymon

________________

Attachments :

STM32L4 CAN.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuS&d=%2Fa%2F0X0000000b28%2FOa5m1KEqVQ1Xg4yxLQUNFFR.40q3lDem2bmMMYWL6ns&asPdf=false
Posted on March 08, 2018 at 11:37

Thanks for the answer.

Even I am facing an issue with the CAN communication.

Microcontroller used: STM32F769NI (stm32f769-disc1)

I tried to use the examples from stm32f7cube (contains the CAN old drivers).

I have tried with the CAN_loopback example along with 'System workbench for STM32'. However it didn't workout.

Do you have any suggestions?

Posted on March 08, 2018 at 11:56

HelloGowtham,

Please provide a more detailed description wahtexactly is not working. Otherwise it is difficult to say what could be a root cause of your issue.

Some time ago I wasworking with STM32F7 and CAN. My hardware platform was eval baord with STM32F756NG. I prepared a presentation as well how to develop simple CANapplication. Please find it attached. Please try to follow all steps from slides. I hope you will suceed to run the CAN communication.

Regards

Szymon

________________

Attachments :

STM32F7 CAN.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HxuN&d=%2Fa%2F0X0000000b26%2FL6GGGZ40vPawqPZNzl9HddhGeQVIhDnCe.9jzEfXzL4&asPdf=false
T J
Lead
Posted on March 08, 2018 at 15:53

I can help you if you want. I have implemented CAN on the '767 and '091

I use HAL and the Cube,

I use HAL but short cut the interrupt system.

whereby 'Hal' is left interrupt enabled and always ready to receive a packet.

my short circuit pumps the FiFo data into RxFrames[64] deep, HAL cant see it so its left enabled.

then my foreground process can see the RxFrames count move and processes it.

that way, when my singular foreground process uses printf, the console never has intertwined messages.

But the best starting point, is to purchase a CANBUS transceiver and start it transmitting your required frame every 1 second at first, and when you are ready crank it up to a frame every 10mS

I purchased a CAN DO unit.had 250KHz CAN running in a few days.

then you find out about Bus Contention.

my rule is no two units can transmit the same messageID.

I encode 2 parts of information in the messageID

the Address 0x040x .. 0x06Fx   is my address range for a unit, only 48 units.

then I use 0x0xx0.. 0x0xxF as 16 command channels or endpoints you may say;

a messageID of 0x0415 is from my Terminal Master requesting Unit 2 to echo this next char

a messageID of 0x0416 is from Unit 2 and has the echo response

these messageIDs have a unique known address source and contain instructions/flags pertaining to the contents of the data following.

Posted on March 08, 2018 at 20:52

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6uZ&d=%2Fa%2F0X0000000bxq%2F23D6jRMBjzU2whX5ICI1bO_bn.W5WoNq6qDfbn3hSt0&asPdf=false
Posted on March 09, 2018 at 00:22

ABOM should be enabled,

 hcan1.Init.AutoBusOff = DISABLE; ENABLE

are you using a line driver ?  if not, you need to pull up the Can Rx pin.

Are you running an external third party dongle, like a CanDo unit ?

Do you have a scope ?

Posted on March 09, 2018 at 06:39

I tried it and it worked. 

Posted on March 09, 2018 at 08:03

I made the settings you mentioned, but it did not work again. I do the application on only 2 stm32 boards. I did not use any resistance or circuit element between them. I connected the 2 board cables directly to the rx and tx pins. I used stm32f407vg discovery. 

1. board -> RB8 (RX)  ->   

2. board 

RB9(TX)

1. board 

-> RB9 (TX)  ->   

2. board 

RB8(RX)

Posted on March 09, 2018 at 14:45

you need a pull up on both Rx pins.

did you set the ABOM bit ?

now you must go out and buy a CANBUS transceiver board and start transmitting from there first.

work on your receiver code first, then transmitter.

I used the CanDo unit to start. Running totally in a few days.