Skip to main content

CAN Transciever MCP2518 - Getting started and Initialization

Arduino library

To install the Arduino library, you can use the Ardino library manager or download it from the GitHub repository:

CAN Transceiver MCP2518 board Arduino library

CAN Bus Breakout with MCP2518 Soldered Arduino Library

ℹ️

First time Arduino user? For a detailed tutorial on how to get started with Arduino, see this section of our docs:

Getting started with Arduino

A full, comprehensive tutorial on how to fully set up and upload code for the first time on an Arduino board, from scratch!


Connections

Below is an example connection diagram for Dasduino CORE. These pins will be used in the examples throughout this documentation.

Dasduino COREBreakout Board
D10 (or any GPIO pin)NCS
D11 (MOSI pin)SDI
D12 (MISO pin)SDO
D13 (SPI CLK pin)SCK
GNDGND
VCCVCC
ℹ️
In the following examples, we will be using TWO MCP2518 modules, they will be connected as follows:
First MCP2518Second MCP2518
CANHCANH
CANLCANL

Initialization

To start using the MCP2518 CAN, you need to include the approperiate libraries, define the SPI Chip select pin, create an instance of CANBus object, and initialize it within the setup() function. This ensures proper communication between the Arduino and The MCP2518 module.

#include "CANBus-SOLDERED.h"
#include <SPI.h>

const int SPI_CS_PIN =10;

CANBus CAN(SPI_CS_PIN);

void setup(){
while(0!=CAN.begin(CAN_125K_500K)){

}
}

CAN.begin()

This function initialises CAN and set speed.

Returns type: int

Returns value: Number

Function parameters:

TypeNameDescription
unt32_tspeedsetData transmision rate.
const byteclocksetFrequency set.