Site Information

 Loading... Please wait...

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. 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...