NMEA2000 Library  0.1
Library to handle NMEA 2000 Communication written in C++
NMEA2000_CAN.h File Reference

Automatic library selection according to the selected board. More...

#include "N2kMsg.h"
#include "NMEA2000.h"
#include <SPI.h>
#include <mcp_can.h>
#include <NMEA2000_mcp.h>
Include dependency graph for NMEA2000_CAN.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MCP_CAN_CLOCK_SET   MCP_16MHz
 The Clock frequency for the MCP CAN is 16MHz. More...
 
#define MCP_CAN_RX_BUFFER_SIZE   1
 Definition of the MCP RX Buffer Size Value of 1 is a small buffer size to save memory. More...
 
#define N2k_CAN_INT_PIN   0xff
 Definition of the CAN Interrupt Pin This defines the number of the CAN Interrupt PIN. Default Value 0xff means not Interrupt PIN in use. More...
 
#define N2k_SPI_CS_PIN   53
 Definition of the SPI ChipSelectPin for the CAN Transceiver This defines the the I/O Pin uses for the Chip Select Line to the corresponding CAN Transceiver. More...
 
#define USE_MCP_CAN_CLOCK_SET   16
 Definition of the Clock frequency for the MCP CAN. More...
 
#define USE_N2K_ARDUINO_CAN   9
 Use the Official Arduino CAN Library. More...
 
#define USE_N2K_AVR_CAN   4
 Use the AVR CAN Library. More...
 
#define USE_N2K_CAN   USE_N2K_MCP_CAN
 Selector for the right board. More...
 
#define USE_N2K_DUE_CAN   2
 Use the Arduino Due CAN Library. More...
 
#define USE_N2K_ESP32_CAN   7
 Use the ESP32 CAN Library. More...
 
#define USE_N2K_MBED_CAN   6
 Use the MBED CAN Library. More...
 
#define USE_N2K_MCP_CAN   1
 Use the mcp_can library. More...
 
#define USE_N2K_SOCKET_CAN   5
 Use the Linux Socket CAN Library. More...
 
#define USE_N2K_TEENSY_CAN   3
 Use the Teensy3.x CAN Library. More...
 
#define USE_N2K_TEENSYX_CAN   8
 Use the Teensy4.x CAN Library. More...
 

Variables

tNMEA2000NMEA2000 =*(new tNMEA2000_mcp(N2k_SPI_CS_PIN,MCP_CAN_CLOCK_SET,N2k_CAN_INT_PIN,MCP_CAN_RX_BUFFER_SIZE))
 

Detailed Description

Automatic library selection according to the selected board.

Just include this <NMEA2000_CAN.h> to your project and it will automatically select suitable CAN library according to board selected on Arduino development environment. You can still force library by adding one of next defines before including NMEA2000_CAN.h:

#define USE_N2K_CAN 1 // for use with SPI and MCP2515 can bus controller
#define USE_N2K_CAN 2 // for use with due based CAN
#define USE_N2K_CAN 3 // for use with Teensy 3.1/3.2/3.5/3.6 boards
#define USE_N2K_CAN 4 // for use with avr boards
#define USE_N2K_CAN 5 // for use with socketCAN (linux, etc) systems
#define USE_N2K_CAN 6 // for use with MBED (ARM) systems
#define USE_N2K_CAN 7 // for use with ESP32
#define USE_N2K_CAN 8 // for use with Teensy 3.1/3.2/3.5/3.6/4.0/4.1 boards
#define USE_N2K_CAN 9 // for use with Arduino CAN API (e.g. UNO R4 or Portenta C33)

Depending of your board you will need to also install "driver" libraries:

see also Hardware depended libraries

Arduino CAN shield (mcp_can) with MCP2515 chip:

Arduino DUE internal CAN:

Teensy 3.2-3.6 internal CAN:

Teensy 4.X internal CAN:

ESP32 internal CAN:

AVR:

MBED (note that there may be problem with fastpackets on MBED):

RPi socket CAN:

There are also library specific defines:

mcp_can:

#define N2k_SPI_CS_PIN 53 // Pin for SPI Can Select
#define N2k_CAN_INT_PIN 21 // Use interrupt and it is connected to pin 21
#define USE_MCP_CAN_CLOCK_SET 8 // possible values 8 for 8Mhz and 16 for 16 Mhz clock

esp32:

#define ESP32_CAN_TX_PIN GPIO_NUM_16
#define ESP32_CAN_RX_PIN GPIO_NUM_4

Teensy:

#define NMEA2000_TEENSY_CAN_BUS 1 // Select second CAN bus for Teensy 3.5 or 3.6

Teensyx:

#define NMEA2000_TEENSYX_CAN_BUS tNMEA2000_Teensyx::CAN2 // select CAN bus 2
#define NMEA2000_TEENSYX_TX_PIN tNMEA2000_Teensyx::pinAlternate // Use selected CAN alternate Tx pin
#define NMEA2000_TEENSYX_RX_PIN tNMEA2000_Teensyx::pinAlternate // Use selected CAN alternate Rx pin
#define USE_NMEA2000_TEENSYX_FOR_TEENSY_3X // Force NMEA2000_TEENSYX also for Teensy 3.x boards

Arduino DUE:

#define NMEA2000_ARDUINO_DUE_CAN_BUS tNMEA2000_due::CANDevice1 // Use CAN bus 1 instead of 0 for Arduino DUE

Definition in file NMEA2000_CAN.h.

Macro Definition Documentation

◆ MCP_CAN_CLOCK_SET

#define MCP_CAN_CLOCK_SET   MCP_16MHz

The Clock frequency for the MCP CAN is 16MHz.

Definition at line 347 of file NMEA2000_CAN.h.

◆ MCP_CAN_RX_BUFFER_SIZE

#define MCP_CAN_RX_BUFFER_SIZE   1

Definition of the MCP RX Buffer Size Value of 1 is a small buffer size to save memory.

Definition at line 313 of file NMEA2000_CAN.h.

◆ N2k_CAN_INT_PIN

#define N2k_CAN_INT_PIN   0xff

Definition of the CAN Interrupt Pin This defines the number of the CAN Interrupt PIN. Default Value 0xff means not Interrupt PIN in use.

Definition at line 305 of file NMEA2000_CAN.h.

◆ N2k_SPI_CS_PIN

#define N2k_SPI_CS_PIN   53

Definition of the SPI ChipSelectPin for the CAN Transceiver This defines the the I/O Pin uses for the Chip Select Line to the corresponding CAN Transceiver.

Definition at line 325 of file NMEA2000_CAN.h.

◆ USE_MCP_CAN_CLOCK_SET

#define USE_MCP_CAN_CLOCK_SET   16

Definition of the Clock frequency for the MCP CAN.

Definition at line 333 of file NMEA2000_CAN.h.

◆ USE_N2K_ARDUINO_CAN

#define USE_N2K_ARDUINO_CAN   9

Use the Official Arduino CAN Library.

Definition at line 191 of file NMEA2000_CAN.h.

◆ USE_N2K_AVR_CAN

#define USE_N2K_AVR_CAN   4

Use the AVR CAN Library.

Definition at line 157 of file NMEA2000_CAN.h.

◆ USE_N2K_CAN

#define USE_N2K_CAN   USE_N2K_MCP_CAN

Selector for the right board.

Definition at line 225 of file NMEA2000_CAN.h.

◆ USE_N2K_DUE_CAN

#define USE_N2K_DUE_CAN   2

Use the Arduino Due CAN Library.

Definition at line 142 of file NMEA2000_CAN.h.

◆ USE_N2K_ESP32_CAN

#define USE_N2K_ESP32_CAN   7

Use the ESP32 CAN Library.

Definition at line 178 of file NMEA2000_CAN.h.

◆ USE_N2K_MBED_CAN

#define USE_N2K_MBED_CAN   6

Use the MBED CAN Library.

Definition at line 172 of file NMEA2000_CAN.h.

◆ USE_N2K_MCP_CAN

#define USE_N2K_MCP_CAN   1

Use the mcp_can library.

CAN_BUS_shield libraries will be originally found on https://github.com/Seeed-Studio/CAN_BUS_Shield There is improved library, which branch can be found on https://github.com/peppeve/CAN_BUS_Shield.
That works also with Maple mini and 8 MHz clock. Hopefully these improvements will be applied to original library

Definition at line 135 of file NMEA2000_CAN.h.

◆ USE_N2K_SOCKET_CAN

#define USE_N2K_SOCKET_CAN   5

Use the Linux Socket CAN Library.

Definition at line 165 of file NMEA2000_CAN.h.

◆ USE_N2K_TEENSY_CAN

#define USE_N2K_TEENSY_CAN   3

Use the Teensy3.x CAN Library.

Definition at line 150 of file NMEA2000_CAN.h.

◆ USE_N2K_TEENSYX_CAN

#define USE_N2K_TEENSYX_CAN   8

Use the Teensy4.x CAN Library.

Definition at line 185 of file NMEA2000_CAN.h.

Variable Documentation

◆ NMEA2000

Definition at line 350 of file NMEA2000_CAN.h.