Site Information

 Loading... Please wait...

Blog

ESP32: CAN Bus Programming with MCP2515 and MCP2517FD

Posted by Wilfried Voss on

espBerry - ESP32 Development Board with Dual Isolated CAN Bus HAT

For good reasons, the ESP32 processor is a prevalent choice for embedded hardware development. Besides considerable memory resources, it provides various hardware features for many applications, most prominently the Internet of Things (IoT). All that comes with more than reasonable price tags, specifically when you use one of the multiple ESP32 development modules. And since we at Copperhill Technologies are primarily involved with CAN Bus, SAE J1939, and NMEA 2000 development, we welcomed the integration of an internal CAN controller. Consequently, we offer a variety of hardware components based on the ESP32 and using the onboard CAN controller, such as our SAE J1939 ECU Simulator with USB Port. Furthermore, we offer the user-programmable ESP 32 WiFi, Bluetooth Classic, BLE, and Controller Area Network (CAN) Module.

So, the question arises: Why use an external MCP2515 CAN Controller? Well, first of all, the ESP32, combined with its two SPI connections, can control up to six CAN controllers. Add the internal controller, and you get seven, even though it requires a different code. Furthermore, while the internal CAN Bus controller is much appreciated, you should be aware of some functionality limitations. These (not necessarily critical) limitations include a restricted set of baud rate settings and the lack of support for CAN FD.

We have used the available MCP2515 resources to create two products:

  1. ESP32 Development Board with NMEA 2000 & NMEA 0183 HAT...
  2. ESP32 Development Board with Dual Isolated CAN Bus HAT...

Both modules come with extensive documentation and plenty of code samples.

We are currently working on combining our espBerry board with our PICAN FD and PICAN FD Duo HATs. Both HATS use the Microchip MCP2517FD controllers. We will post an application note as soon as it is available. If you need further information, please feel free to contact us.

Github.com offers a unified library, all-inclusive of code, which implements a CAN Busdriver for the built-in CAN hardware on an ESP32. It also implements a driver for the MCP2517FD SPI-connected CAN module. The built-in CAN port is CAN0, and the MCP2517FD is CAN1. This library works directly with the EVTV ESP32-Due board. However, with minor modifications, either driver found within this library could be used on other boards.

For further information on ESP32 CAN Bus programming, see our posts:

Connecting any CAN Bus, SAE J1939, or NMEA 2000 application to the internet is easily accomplished using the information in this post. To learn more about a connection to Bluetooth, BLE, or WiFi, we recommend the following literature:


Electronics Projects with the ESP8266 and ESP32: Building Web Pages, Applications, and WiFi Enabled DevicesElectronics Projects with the ESP8266 and ESP32: Building Web Pages, Applications, and WiFi Enabled Devices

Copperhill Technologies highly recommends using this book for your wireless application projects. Yes, many good books and free online resources are available these days, but this is the book we are using. It made our approach to Bluetooth, BLE, and WIFI a breeze. Programming wireless applications without hassles was fun, and we will share them on this web page.

Projects throughout the book utilize the wireless functionality and processing power of the ESP microcontrollers. Projects are built in the Arduino IDE, so you don't need to download other programming software. In addition, mobile apps are now ubiquitous, making the app build projects of the book very relevant, as are the web page design projects.

In Electronics Projects with the ESP8266 and ESP32, you'll see how easy and practical it is to access information over the internet, develop web pages, build mobile apps to remotely control devices with speech recognition, or incorporate Google Maps in a GPS route tracking app.

More Information...

ESP32 Triple CAN Bus Application Through Adding Two MCP2515 Ports

The first question that may arise when talking about accessing the MCP2515 CAN Bus controller per ESP32 may be, "Why would you need an MCP2515 controller when the ESP32 comes with an internal CAN port?" Yes, I found this question in one of the online forums while researching this particular topic. The answer is easy: [...]

Read More »


Four Channel CAN Bus to USB Gateway Using The Arduino Due

In the past, I frequently received inquiries regarding the availability of a four-channel CAN Bus gateway. Such devices exist in the marketplace; however, they are usually costly, and, after all, they don't support easy customization or programming. While we at Copperhill Technologies have the ability to create such a gateway, this is primarily a matter [...]

Read More »


MCP2515 CAN Bus Monitor Demo Board Kit Forms A Simple Two-Node CAN Bus Network

The MCP2515 is a low pin count stand-alone CAN Bus controller which interfaces to a microcontroller via a standard Serial Peripheral Interface (SPI). The MCP2515 is a second-generation stand-alone CAN Bus controller. It is pin and function compatible with the MCP2510 and also includes upgraded features like faster throughput, data byte filtering, and support for time-triggered protocols.The feature [...]

Read More »


SAE J1939 Programming with Arduino - The CAN Bus Interface

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. While the code as introduced in the previous chapter was well designed and thus is highly efficient, I inserted yet another software layer between the CAN Bus interface and the ARD1939 protocol stack.I wrote the ARD1939 source code in plain C [...]

Read More »


SAE J1939 Programming with Arduino - MCP2515 Function Calls

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. There are further functions, among others, for message filtering and settings masks, and they are worth being checked out for more sophisticated functions, but they are not necessary for simple CAN communication tasks.The implementation of the MPC2515 library is fairly easy: Open Arduino, [...]

Read More »


SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino - The MCP2515 Library

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. Microchip Technology’s MCP2515 is a stand-alone Controller Area Network (CAN Bus) controller that implements the CAN 2.0B specification. It is capable of transmitting and receiving both standard (11-bit) and extended (29-bit) data and remote frames. The MCP2515 has two acceptance masks and six acceptance filters [...]

Read More »


SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino - Microchip MCP2515 CAN Bus Controller

This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. Microchip Technology’s MCP2515 is a stand-alone Controller Area Network (CAN Bus) controller that implements the CAN specification, version 2.0B. It is capable of transmitting and receiving both standard and extended data and remote frames. The MCP2515 has two acceptance masks and six [...]

Read More »


CAN Bus Prototyping With Arduino Uno - The MCP2515 Library

This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.As with any serial networking controller, the essential functions are: InitializationRead DataWrite DataCheck StatusIn case of the MCP2515 library, these functions are represented by: Initialization: CAN0.beginRead Data: CAN0.readMsgBuf incl. CAN0.checkReceive, CAN0.getCanIdWrite Data: CAN0.sendMsgBufCheck Status: CAN0.checkErrorFunction CallsFunction:           CAN0.beginPurpose: Initializes the CAN controller and [...]

Read More »


CAN Bus Prototyping With Arduino Uno - Arduino CAN Sketches

This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.The implementation of either one of the introduced CAN Bus Shields and the corresponding CAN Bus sketches went surprisingly smooth when paired with the right library software. I found several source codes for accessing the MCP2515 CAN controller, but most of [...]

Read More »