3

Many STM32 chipsets support 1 or 2 channel CAN PIN Outs. Is there a CAN bus library for STM32 to direct connect with a CAN transceiver such as MCP2551? But it does not matter what the CAN transceiver is.

lei lei
  • 1,753
  • 4
  • 19
  • 44

2 Answers2

6

A CAN transceiver is just a high speed step down converter. (on a basic level)

CAN protocol works in a variant of voltage ranges. MCP2551 is a set CAN transceiver suitable for 12V and 24V systems. With added features to help with the physical layer like externally-controlled slope for reduced RFI emissions, detection of ground fault, voltage brown-out protection, etc.
It has no dependency on the CAN logic. It is just to help you with the bare physical layer.

To answer your question:
As RishabhHardas recommended, use the HAL library provided by STM32 through CubeMx.

Using CubeMx
This is a software provided by ST-Micro to help you setup the boilerplate code for any peripheral application.
You can also check out the examples projects provided by STM in the Cube. This will give you a kick-start in understanding CAN on STM32

STM32Cube_FW_F4_V1.9.0\Projects\STM324xG_EVAL\Examples\CAN\CAN_Networking

After setting it up, you'll be able to call HAL_CAN_Transmit() and HAL_CAN_Receive() by including the header.
Check out this discussion on STM32-Community.

clamentjohn
  • 3,417
  • 2
  • 18
  • 42
  • Thanks for answering my question. Is there an example of using HAL CAN Library to read and send CAN messages? – lei lei Nov 05 '18 at 06:33
  • @leilei I've updated my answer. I recommend you get started with STM32CubeMx. If you need a example check out: http://mieurekas.blogspot.com/2017/10/stm32f0-can-bus-hal-example.html – clamentjohn Nov 05 '18 at 08:02
0

For software, look for the CANtact open source project on Github. It is an implementation for the STM32F042. I had to adapt the project to build it under Atollic but it was not too hard and it works. It provides a SLCAN type of interface over a virtual COM port over USB, which is very fast and convenient.

There is also CAN code for the STM32F103 (Bluepill) (Google "lawicel-slcan") but that chip is not as convenient because you cannot use both CAN and USB at the same time (they share RAM buffers) so if you want CAN, you will not have USB, and routing the CAN messages over a UART will severely limit the bandwidth. That may be OK if your entire application runs on the STM32.

Didier
  • 36
  • 1
  • 7