4
\$\begingroup\$

I have spent days studying and trying to achieve simple communications with CAN bus from scratch using stm32f1, but I still have not achieved the desired results and it is difficult to understand and program.

On the other hand, there are CAN bus modules that communicate with a microcontroller by SPI like this: https://www.ebay.com/itm/283953770322?hash=item421cf6af52:g:JHAAAOSwIeVfQ7HI

and there are many libraries to handle these modules, but the official microchip page does not recommend continuing to use the MCP2515.

My Doubt is: What difference is there in using CAN bus from scratch (STM32) than using a separate module? using a stand alone module affects the security of the CAN bus? Should a stand alone module be used in industry?

\$\endgroup\$
3
  • \$\begingroup\$ Probably same as an internal vs external ADC. Interrupts and registers are faster for the internal. No SPI message to do something. You just do it. \$\endgroup\$
    – DKNguyen
    Commented Dec 7, 2021 at 1:51
  • 1
    \$\begingroup\$ By "from scratch" do you mean a software CAN controller as opposed to a hardware CAN peripheral (be it integrated into the MCU or external via SPI) ? \$\endgroup\$ Commented Dec 7, 2021 at 2:06
  • \$\begingroup\$ Have a look:electronics.stackexchange.com/questions/304076/… \$\endgroup\$
    – Mike
    Commented Dec 7, 2021 at 7:56

3 Answers 3

5
\$\begingroup\$

What difference is there in using CAN bus from scratch (STM32) than using a separate module?

External CAN controllers is mainly a thing of the past. In the 1990s, it was about the only way to use CAN, before microcontrollers started supporting on-chip CAN controllers.

Since then, the only reason to use an external CAN controller is that you have specialized project requirements leading to a very specialized MCU - one that doesn't come with a CAN version.

using a stand alone module affects the security of the CAN bus?

Not security as in protection from malicious use. But it makes the whole design slightly more sensitive to EMI since SPI isn't nearly as rugged as CAN. The external controller also introduces a lot of latency, BoM costs and overall extra pointless complexity.

but the official microchip page does not recommend continuing to use the MCP2515

That would mostly be because Microchip has made a new generation of all their transceivers and controllers with support for CAN FD. The new modern parts are backwards-compatible and also have better immunity and ESD protection etc.

\$\endgroup\$
3
\$\begingroup\$

If your MCU has an on-chip CAN peripheral, using it is preferable over external module. In addition to latency mentioned by Ralph, consider the cost, availability and reliability of using a module.

Think about it this way. There are many IO expander chips available on the market. Would you use one, if you had many spare pins on the MCU? Probably not. On the other hand, if all your pins are used up, then an I2C port expander may be a more viable option than getting the MCU in a bigger package.

\$\endgroup\$
2
\$\begingroup\$

Generally, devices on a CAN Bus have requirements that the messages be delivered from one device to another at a very low time latency. For example, communicating the position of a rotating motor shaft from a motor drive device to a controller over the bus. The data is not useful unless delivered within a short delay. If there is a device between your processor and the CAN Bus with which you must communicate via SPI, this device-in-the-middle communication will delay every message, increasing the latency of its arrival to other devices on the CAN Bus.

A CAN controller built into a micro controller which communicates directly on the CAN Bus is the best way to interact with other devices at low latency. Most micro controller CAN peripherals can handle the low-level communications and only interrupt the micro when necessary, avoiding the need for polling or message filtering.

If the application does not have low-latency communication requirements, then I suppose the SPI-connected external peripheral can meet those requirements.

So the main reason not to use the external module would be to communicate on the CAN bus with low-latency.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.