Site Information

 Loading... Please wait...

ESP32 Development Board Controls Dual Isolated CAN Bus HAT

Posted by Wilfried Voss on

I am following up on a series of posts I wrote on the topic of connecting an ESP32 processor to Raspberry Pi HATS. The result of this development is the espBerry. 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 purpose of the espBerry should not be perceived as a Raspberry Pi alternative but as extending the ESP32’s functionality by tapping into the vast offerings of RPi HATs in the market and taking advantage of the multiple and flexible hardware options. For more information, see espberry.com.

But, first, let me reference my previous posts:

In the test setup as shown in above image, I am using an off-the-shelf  ESP32 DevKitC development board in combination with our Dual Isolated CAN Bus HAT.

While the hardware has been successfully tested, there were issues with the MCP2515 driver software. And yes, you can download a myriad of code samples (and their derivatives) from the github website. However, not all of them meet my specific requirements, such as receive ISR (Interrupt Service Routine) or Listen-Only mode. These features are mandatory for any professional CAN Bus development.

Receiver interrupts guarantee that the application will fetch every CAN data frame in the network (if necessary). For instance, SAE J1939 requires that the application can manage short data bursts, such as 20 CAN data frames at highest busload, i.e., no significant pause between frames. Mere pulling of CAN data will fail in such a case.

Listen-only mode is recommended during mere data monitoring mode in order to not interfere with the network. It is also mandatory for automatic CAN baud rate detection.

I went through several cycles of testing various github examples. One of them crashed the program as soon as you connected the INT signals of the CAN controller per attachInterrupt() command. Others promised CAN controller modes, such as sleep, loopback, or listen-only mode but the corresponding functions contained only a return(0) line, indicating "Add your code here."

Nevertheless, I found this  Arduino 2515 CAN Interface library, which was easy to adapt to a dual CAN port application. The documentation is refreshingly thorough, including schematics, and the code is professionally presented. 

All I had to do was creating a second MCP2515 instance and connect the INT0/1 signals using the attachInterrupt() function. I already had developed a code for a CAN data frame ring buffer.

I am still in the process of adding the automatic CAN baud rate detection, and I will publish the code with the release of the espBerry. The full source code will be part of the delivery. If there is interest for the code, please  contact us and refer to this post.


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