Electronic – What additional components/boards are needed to use CAN with an STM32

canstm32

I have a STM32F103C8T6 (later I want to more to STM32F407VET6). Both have support for CAN. But what does this mean?

I bought (not received yet) an MCP2551 CAN Controller.
Do I need this or is this functionality already built in my STM?

And I think I also need a CAN transceiver like TJA1050?

According to this Example circuit both are used and the input of the MCP2551 but that has a SPI as input and the STM has RX/TX as CAN input/output which is similar as the 'connectors' for MCP2551. But I think this example circuit is not meant for STM32 (since SPI is not used for CAN on STM32).

(I want to make a CAN bus of a few meters, just two, later maybe 3 devices, with preferably 1 mbps speed).

Best Answer

You should have at least two nodes and a twisted pair with 120 ohm terminations at each end. Identifiers must be unique. Read up on the various formats (11/29 bit) and CAN-FD vs. CAN. I suggest starting with 11 bits. The lower numbered identifier is the higher priority.

Typically when a microcontroller supports CAN it means that the 2nd network layer (data link) is supported by a CAN MAC. Usually you have to supply a transceiver (the physical layer). CAN has (electrically) demanding requirements for maximum voltage tolerance that would typically be incompatible with low-cost monolithic processes that support microcontroller complexity. You can also buy chips with serial interfaces that implement the MAC, which you can connect to almost any microcontroller with (eg.) SPI.

There are various high level protocols that can go above the 2 layers specified by CAN, or for a simple application you can implement your own. CAN messages are essentially broadcast and can be used or discarded by each node- like multicast or broadcast.

A CAN protocol analyzer can be helpful- you can buy them for the value of an hour or two debugging.