Arduino – CAN Bus communicatie

Het is mogelijk een arduino te gebruiken met een CAN Bus interface, met CAN Bus kan je datalijnen gebruiken tot ca. 500m, en apparaten werken peer-to-peer (ipv master – slave) dat is erg interessant!

Wat je nodig hebt is een CAN Bus module met een controller en transciever om het differentiële signaal van de CAN Bus bus om te zetten naar SPI signalen voor de Arduino (en andersom).

Hardware CAN Bus controller module

BESTELLEN

The MCP2515 CAN Bus Controller is a simple Module that supports CAN Protocol version 2.0B and can be used for communication at 1Mbps. In order to setup a complete communication system, you will need two CAN Bus Module.

  • Supports CAN V2.0B specification, with communication speed up to 1Mb/s.
  • 0 to 8-byte data field with standard frame, extended frame and remote frame.
  • 5V DC power supply module, SPI interface protocol control.
  • Onboard 120 Ohm termination resistor.
  • Working current: 5mA (1 microamp standby current).
  • Operating temperature: -40 C – +85 C

This particular module is based on MCP2515 CAN Controller IC and TJA1050 CAN Transceiver IC. The MCP2515 IC is a standalone CAN Controller and has integrated SPI Interface for communication with microcontrollers.

Coming to the TJA1050 IC, it acts as an interface between the MCP2515 CAN Controller IC and the Physical CAN Bus.

The following image shows the components and pins on a typical MCP2515 Module:

MCP2515 datasheet (Microchip)

TJA1050 datasheet (NXP)

Module schema

Before seeing the schematic of the module, you need to understand a couple of things about both the ICs i.e. MCP2515 and TJA1050.

MCP2515 IC is the main controller that internally consists of three main subcomponents: The CAN Module, the Control Logic and the SPI Block.

CAN Module is responsible for transmitting and receiving messages on the CAN Bus. Control Logic handles the setup and operation of the MCP2515 by interfacing all the blocks. The SPI Block is responsible for the SPI Communication interface.

Coming to the TJA1050 IC, since it acts as an interface between MCP2515 CAN Controller and the physical CAN Bus, this IC is responsible for taking the data from the controller and relaying it on to the bus.

The following image shows the schematic of the MCP2515 CAN Module and it shows how MCP2515 IC and TJA1050 IC are connected on the Module.

Schema met component waarden:

Arduino schema

Sluit de CAN Bus Module aan zoals hieronder aangegeven.

Arduino NANO:

Arduino UNO:

In duale opstelling UNO:

In duale opstelling NANO:

For Transmitter (Arduino 1)
MCP2515 Module -> Arduino Nano
MPC2515 – VCC -> +5V
MPC2515 – GND -> GND
MPC2515 – CS -> D10 (SPI_SS)
MPC2515 – SO -> D12 (SPI_MISO)
MPC2515 – S I -> D11 (SPI_MOSI)
MPC2515­ – SCK -> D13 (SPI_SCK)
MPC2515 – INT -> D2

 

For Receiver (Arduino 2)
MCP2515 Module -> Arduino Uno
VCC -> +5V
GND -> GND
CS -> 10 (SPI_SS)
SO -> 12 (SPI_MISO)
SI -> 11 (SPI_MOSI)
SCK -> 13 (SPI_SCK)
INT -> 2

 

Between two MCP2515
MCP2515 on Arduino Nano (Arduino 1) -> MCP2515 on Arduino Nano (Arduino 2)
H -> H
L -> L


Scripts

Wat heb je nodig?

1) Arduino CAN Bus bibliotheek (autowp): https://github.com/autowp/arduino-mcp2515

arduino-mcp2515-1.0.0

arduino-mcp2515-1.0.1

arduino-mcp2515-master (DL @ 2020-12-08)

Transmitter script

Reciever script

Console uitput van de ontvanger:


Met 3 apparaten

Transmitter script 1

Transmitter script 2

Reciever script

Console uitput van de ontvanger:


Bronnen:

https://www.electronicshub.org/arduino-mcp2515-can-bus-tutorial/

https://copperhilltech.com/mcp2515-can-bus-breakout-board-with-spi-interface/

https://create.arduino.cc/projecthub/maurizfa-13216008-arthur-jogy-13216037-agha-maretha-13216095/can-bus-using-arduino-9ce7ba