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 CORE | Breakout Board |
|---|---|
| D10 (or any GPIO pin) | NCS |
| D11 (MOSI pin) | SDI |
| D12 (MISO pin) | SDO |
| D13 (SPI CLK pin) | SCK |
| GND | GND |
| VCC | VCC |
| First MCP2518 | Second MCP2518 |
|---|---|
| CANH | CANH |
| CANL | CANL |
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:
| Type | Name | Description |
|---|---|---|
unt32_t | speedset | Data transmision rate. |
const byte | clockset | Frequency set. |