Recent Posts
ESP32: Isolated CAN Bus Repeater and Baud Rate Converter
Posted by
on
With this application, I am adding yet another example to the vast CAN library we developed over the years. The use of the Dual Isolated CAN Bus HAT with the ESP32 opens the door to a number of possible applications. The development of a CAN repeater and/or Baud Rate Converter came to mind first, because the actual code is ridiculously simple.
A CAN repeater is primarily used for signal conditioning and can also serve to extend the physical length of a CAN Bus network. A baud rate converter helps connecting devices with different CAN baud rates to connect them to the same network. The code for both applications is pretty much the same. The repeater application uses the same CAN Bus baud rate for both channels, while the converter uses different transmission speeds.
For my test setup, I used our SAE J1939 ECU Simulator Board to transmit one PGN at 500 kbps. Our espBerry with Dual Isolated CAN Bus HAT acts as the repeater/converter. It converts the 500 kbps to 250 kbps and vice versa. In addition, I connected the PEAK PCAN-USB Pro to the network. It transmits three different CAN message frames at 250 kbps.
The above screen shot shows our JCOM1939 Monitor Software, which is connected to the J1939 ECU Simulator board. The screen shows the received and transmitted CAN message frames. Note the selected baud rate of 500 kbps at the upper right-hand corner.
The PCAN View software in turn shows the received and transmitted CAN messages at 250 kbps.
As I mentioned previously, the code is fairly simple. During setup, we initialize both CAN ports using the chosen baud rates.
In the loop section, we check for received data and forward them to the other port.
Of course, there is further code required for the CAN drivers, and they are included in the downloadable code.
=> Click here to download the Arduino IDE - ESP32 code (.zip file).
A few more things to consider:
- The Dual Isolated CAN Bus HAT operates within a temperature range of o to 50 Celsius.
- The code introduced in this post is free software; you can redistribute it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or (at your option) any later version. The program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. With downloading these programs, you confirm that you have read and agree with these terms and conditions.
espBerry - 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 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.
The HAT is well documented, and there are multiple code samples using the C programming language under the Arduino IDE.