Blog
Recent Posts
ESP32 Processor: Adding CAN/CAN-FD Controllers per SPI Port
Posted by
onThis post is an excerpt from our application note Controller Area Network (CAN) Development with ESP32.
The internal CAN controller SJA1000 does not support CAN-FD and is not CAN-FD tolerant. To use CAN-FD with the ESP32, you need to employ CAN-FD breakout boards that are accessible per the ESP32’s SPI ports.
Note: The SPI ports are not limited to CAN-FD controllers; they also support Classical CAN controllers, such as the Microchip MCP2515. The Microchip MCP2515 is a very popular chip, and its software support is superior to that of the ESP32’s SJA 1000, thus allowing a wider range of applications.
SPI stands for Serial Peripheral Interface, a serial full-duplex and synchronous interface. The synchronous interface requires a clock signal to transfer and receive data. The clock signal is synchronized between one central control ("master") and multiple peripheral devices ("slaves"). Unlike UART communication, which is asynchronous, the clock signal controls when data will be sent and when it should be ready to read.
Only a master device can control the clock and provide a clock signal to all slave devices. Data cannot be transferred without a clock signal. Both master and slave can exchange data with each other. No address decoding is required.
The ESP32 has four SPI buses, but only two are available: HSPI and VSPI (Default). They are being selected per software, and I will explain the specifics in the SPI programming chapter.
Again, in SPI communication, there is always one controller (also known as a master) that controls other peripheral devices (also known as slaves).
While you can configure the ESP32 as either a master or a slave, we will use it as a master for all our CAN-FD applications.
The above image shows the connection between two SPI devices that use four signals:
- SCK/SCLK Clock Signal
- MISO Master In Slave Out
- MOSI Master Out Slave In
- CS/SS Chip Select
Many ESP32 boards come with default SPI pins pre-assigned. The pin mapping for most boards is as follows:
Keep in mind that the default SPI pins may vary depending on the board you are using. Therefore, it is important to check the pinout for your specific board. In some cases, certain boards do not have pre-assigned SPI pins, so you will need to set them in the code. Generally, if not specified, the board will use the VSPI pins when initiating an SPI communication with the default settings.
If you are unsure about your board’s default SPI pins, you can execute a code as described in Finding your ESP32 Board Default SPI Pins.
I would like to address the Chip Select (CS) signal in more detail because it enables the ESP32 to communicate with up to three SPI devices. This means that you can connect up to three CAN/CAN-FD controllers per SPI port (HSPI, VSPI). While the default settings are GPIO5/GPIO15 on most systems, you can assign additional CS output signals to any GPIO. The CS signal initiates access to the selected CAN controller.
Another important signal is the interrupt (INT) input signal. Each CAN controller provides an interrupt output signal when a CAN data frame is received, which triggers an Interrupt Service Routine (ISR) on the processor. This allows for the timely processing of CAN data frames. Each INT signal can be assigned to any GPIO per code.
It is possible to poll all CAN controllers without using ISRs because the ESP32 is fast enough for the task. However, interrupt-driven data processing is more reliable, especially when your application requires a lot of code.
ESP32 WiFi, Bluetooth Classic, BLE, CAN Bus Module
This board has an onboard ESP32 WROOM-32 WiFi, Bluetooth Classic, BLE Module, and a CAN Bus port with a transceiver. Also onboard are an RGB LED and IO pins on a 0.1" pad.
Programming is accomplished through the popular Arduino IDE connected to the USB-to-Serial converter with a USB-C connector, automatic bootloader, and reset. The ESP32 is a low-cost, low-power system-on-chip microcontroller with integrated Wi-Fi and dual-mode Bluetooth. It employs a Tensilica Xtensa LX6 microprocessor in dual-core and single-core variations.
It includes built-in antenna switches, RF baluns, a power amplifier, a low-noise receive amplifier, filters, and power management modules. More Information...
ESP32: CAN Bus Programming with MCP2515 and MCP2517FD
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 [...]
ESP32 Triple CAN Bus Application Through Adding Two MCP2515 Ports
The first question that may arise when talking about accessing the MCP2515 CAN Bus controller per ESP32 may be, "Why would you need an MCP2515 controller when the ESP32 comes with an internal CAN port?" Yes, I found this question in one of the online forums while researching this particular topic. The answer is easy: [...]
Four Channel CAN Bus to USB Gateway Using The Arduino Due
In the past, I frequently received inquiries regarding the availability of a four-channel CAN Bus gateway. Such devices exist in the marketplace; however, they are usually costly, and they don't support easy customization or programming. While we at Copperhill Technologies have the ability to create such a gateway, this is primarily a matter of market [...]
MCP2515 CAN Bus Monitor Demo Board Kit Forms A Simple Two-Node CAN Bus Network
The MCP2515 is a low pin count stand-alone CAN Bus controller which interfaces to a microcontroller via a standard Serial Peripheral Interface (SPI). The MCP2515 is a second-generation stand-alone CAN Bus controller. It is pin and function compatible with the MCP2510 and also includes upgraded features like faster throughput, data byte filtering, and support for time-triggered protocols.The feature [...]
SAE J1939 Programming with Arduino - The CAN Bus Interface
This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. While the code as introduced in the previous chapter was well designed and thus is highly efficient, I inserted yet another software layer between the CAN Bus interface and the ARD1939 protocol stack.I wrote the ARD1939 source code in plain C [...]
SAE J1939 Programming with Arduino - MCP2515 Function Calls
This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. There are further functions, among others, for message filtering and settings masks, and they are worth being checked out for more sophisticated functions, but they are not necessary for simple CAN communication tasks.The implementation of the MPC2515 library is fairly easy: Open Arduino, [...]
SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino - The MCP2515 Library
This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. Microchip Technology’s MCP2515 is a stand-alone Controller Area Network (CAN Bus) controller that implements the CAN 2.0B specification. It is capable of transmitting and receiving both standard (11-bit) and extended (29-bit) data and remote frames. The MCP2515 has two acceptance masks and six acceptance filters [...]
SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino - Microchip MCP2515 CAN Bus Controller
This post is part of a series about SAE J1939 ECU Programming & Vehicle Bus Simulation with Arduino. Microchip Technology’s MCP2515 is a stand-alone Controller Area Network (CAN Bus) controller that implements the CAN specification, version 2.0B. It is capable of transmitting and receiving both standard and extended data and remote frames. The MCP2515 has two acceptance masks and six [...]
CAN Bus Prototyping With Arduino Uno - The MCP2515 Library
This post is part of a series about Controller Area Network (CAN Bus) Prototyping With the Arduino Uno.As with any serial networking controller, the essential functions are: InitializationRead DataWrite DataCheck StatusIn case of the MCP2515 library, these functions are represented by: Initialization: CAN0.beginRead Data: CAN0.readMsgBuf incl. CAN0.checkReceive, CAN0.getCanIdWrite Data: CAN0.sendMsgBufCheck Status: CAN0.checkErrorFunction CallsFunction: CAN0.beginPurpose: Initializes the CAN controller and [...]