Site Information

 Loading... Please wait...

Controller Area Network (CAN) Development with the ESP32

Controller Area Network (CAN) Development with ESP32 - Classical CAN & CAN FD

Note: The following represents an application note in the making. We will add further posts over time until finished.

Controller Area Network (CAN) Development with ESP32

Classical CAN & CAN FD

by Wilfried Voss
Copperhill Technologies

The ESP32 processor, including the various development kits, is perfect for Controller Area Network (CAN) and Internet of Things (IoT) prototyping applications. It provides multiple on-chip resources, including a CAN controller, WIFI, Bluetooth, BLE, UART, SPI, and more.

The onboard CAN controller supports Classical CAN (CC). The wireless functionality is great for the Internet of Things (IoT) or gateway applications. The SPI ports allow additional external hardware, such as up to six CAN controllers (CC or CAN FD) or SD card support for CAN data recording. For the implementation of higher-layer protocols (HLP), such as CANopen, SAE J1939, and NMEA 2000, as well as for gateway applications, the ESP32 offers multiple serial interfaces (UART, USB), interrupt-driven digital inputs for real-time support, and onboard timers. Furthermore, there are digital and analog IOs. 

However, in the following, I will focus on basic Classical CAN and CAN FD implementations regarding hardware and software. While the hardware design is straightforward, developing the corresponding software presented a challenge. The internet offers a myriad of code examples, some of them good, some of them not. So, I filtered the good ones while adding more background information and technical details.

I use the popular Arduino IDE for software development and tests to have common ground with most ESP32 programmers.

All these aspects will be discussed in more detail in the following chapters. Wherever necessary, I will point to references with insights that go beyond the scope of this document.

From the Author

For many years, the Arduino Due has been my favorite solution for rapid prototyping. It provides excellent performance, and programming with the Arduino IDE is fun (despite lacking inline debugging for too long). Add to this the vast code resources you find online, and you are all set to create your favorite applications.

However, Arduino hardware is not necessarily the best choice for industrial and automotive applications with Controller Area Networks (CAN) under real-world environmental conditions, such as vibration and temperature. In contrast, the ESP32 processor and its various development kits operate in an extended temperature range, and in most cases, you can copy Arduino code without modification (using the Arduino IDE). Furthermore, besides the vastly greater memory resources and execution speed, the ESP32 offers on-chip features, such as a CAN controller. Add to this WIFI, Bluetooth, and BLE (Bluetooth Low Energy), which are crucial for IoT (Internet of Things).

The following writing reflects my experience working on Controller Area Network (CAN) applications with the ESP32 processor, and I will share hardware and software aspects for those interested. This document comes with sufficient information to start your application development.

However, I would like to emphasize one crucial aspect: Please understand that I cannot provide help for your specific application beyond this document.

Over the years, I have dealt with many newcomers to the CAN Bus technology, some motivated by great product ideas. Others were thrown into a project because they were embedded system programmers. What they all had in common was that they were grateful to have found me, and they all wanted to pick my brain or that I solve the problems they encountered.

The drawback is that while I happily share my knowledge, remote troubleshooting per phone call or multiple emails is cumbersome (to put it diplomatically) and can be incredibly time-consuming. My answer was always consistent and sometimes frustrating for the engineer eager to get his hands on an embedded application: I understand your predicament. We have all been there. However, you are responsible for your application. You need to grasp your development's full scope, including a solid understanding of the technology involved. Sound engineering requires research, time, and patience, with no shortcuts.

And yes, I understand the frustration of exploring new projects. I chose the ESP32 processor due to its compatibility with the Arduino system and vast resources. Yet, there were too many occasions when I wanted to speak with the publishers of various examples due to a lack of documentation and poorly written code. However, I decided that my time was better spent working around these shortcomings by improving documentation and code or continuing my search for better examples. The result is this document.

I always consider these aspects when I write and share as much knowledge as possible. However, it makes no sense to repeat published information, so I provide various hyperlinks in this document to enable further research on details not covered here.

I believe the information in this application note and working through the various online resources will help you gain the necessary expertise to tackle the most complex CAN Bus applications.

ESP32 WiFi, Bluetooth Classic, BLE, CAN Bus Module

ESP32 WiFi, Bluetooth Classic, BLE, CAN Bus Module

This board comes with an onboard ESP32 WROOM-32 WiFi, Bluetooth Classic, BLE Module, and a CAN Bus port with a transceiver. Also, onboard is an RGB LED, IO pins on a 0.1" pad.

Programming is accomplished through the popular Arduino IDE connected to the USB-to-Serial converter with USB-C connector, automatic bootloader and reset.

The ESP32 is a series of low-cost, low-power system-on-chip microcontrollers with integrated Wi-Fi and dual-mode Bluetooth. The ESP32 series employs a Tensilica Xtensa LX6 microprocessor in both dual-core and single-core variations and includes built-in antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules. More Information...

Additional ESP32 & CAN Bus Resources on this Website

espBerry - ESP32 Development Board with Dual Isolated CAN Bus HATespBerry - ESP32 Development Board with Dual Isolated CAN Bus HAT

The espBerry DevBoard combines the ESP32-DevKitC development board with any Raspberry Pi HAT by connecting to the onboard RPi-compatible 40-pin GPIO header. The espBerry is the perfect solution for Internet of Things (IoT) applications, especially those requiring wireless capabilities. All open-source code samples take advantage of the popular Arduino IDE with its excellent programming capabilities.

The Dual Channel CAN Bus expansion HAT, designed for the Raspberry Pi, supports the full CAN2.0 Standard, and it features multi onboard protection circuits, high anti-interference capability, and reliable operation. As a result, it suits applications such as automotive devices or industrial automation. More Information...

Table of Contents


Controller Area Network

Classical CAN


CAN FD Compatibility Issues

The ESP32 Processor

Internal SJA 1000 CAN Controller

Adding a CAN Bus Transceiver

Adding CAN Interfaces per SPI Port

The Integrated Development Environment (IDE)

The Arduino IDE

Visual Studio Code

The Test Hardware

The ESP32-WROOM-32 Development Kit

ESP32 Development Kits with Onboard CAN Controller

Other ESP32 Development Kits

CAN Analyzing & Monitoring Device

Controller Area Network (CAN) Applications

Classical CAN Implementation

Internal SJA1000 CAN Controller

External MCP2515 CAN Controller

CAN FD Implementation

Hardware Design

Software Development

Application Library

CAN Bus Troubleshooting

Most Problems Are Related to Wiring Problems

A Word to OBD-II Enthusiasts

Additional Helpful Features

Automatic CAN Baud Rate Detection and Silent Mode

Interrupt Timer Implementation

Gateway and IoT Functionality

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


All trademarks or registered trademarks are the property of their respective owners.


The information provided in this document is provided "as is" without warranty of any kind. Copperhill Technologies Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Copperhill Technologies Corporation be liable for any damages whatsoever, including direct, indirect, incidental, consequential, loss of business profits, or special damages, even if Copperhill Technologies Corporation or its suppliers have been advised of the possibility of such damages.