Recent Posts
ESP32: CAN Bus Programming with MCP2515 and MCP2517FD
Posted by
onFor 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:
- ESP32 Development Board with NMEA 2000 & NMEA 0183 HAT...
- 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:
- ESP32 Triple CAN Bus Application Through Adding Two MCP2515 Ports - Copperhill (copperhilltech.com)
- ESP32 Sketch: espBerry with Dual MCP2515 CAN Bus HAT - Copperhill (copperhilltech.com)
- ESP32 Application: Galvanically Isolated CAN Bus Repeater and Baud Rate Converter - Copperhill (copperhilltech.com)
- Arduino IDE Boards Manager - Do NOT Install ESP32 by Espressif Systems Version 3.00-alpha1 - Copperhill (copperhilltech.com)
- Dual-Channel Linear Actuator Control Module with ESP32 Processor - Copperhill (copperhilltech.com)
- ESP32, ESP32-S2 - Serial Port, Native USB Access using Arduino IDE - Copperhill (copperhilltech.com)
- espBerry Project: ESP32 with NMEA 2000 & NMEA 0183 HAT - Copperhill (copperhilltech.com)
- ESP32 with Dual Isolated CAN Port Controls Thomson Electrac Linear Actuator - Copperhill (copperhilltech.com)
- Know OBD2 Before You Start That Development Project - Copperhill (copperhilltech.com)
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 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.