Site Information

 Loading... Please wait...

Blog

Building a Classical CAN to CAN FD Gateway with the ESP32-S3

Posted by Wilfried Voss on

Building a Classical CAN to CAN FD Gateway with the ESP32-S3As CAN FD continues to replace Classical CAN in automotive, industrial, agricultural, and heavy equipment applications, many engineers face a familiar dilemma: they have one or more perfectly functional Classical CAN devices that cannot simply be connected to a CAN FD network.

The obvious solution would be to redesign the existing hardware and rewrite the firmware to support CAN FD. In many cases, however, that approach is neither technically nor economically justified.

A protocol gateway provides a much more practical alternative.

Using the ESP32-S3 Board with CAN FD and Classical CAN Ports, developers can build a compact, low-cost gateway that connects legacy Classical CAN equipment to modern CAN FD networks with surprisingly little software effort. The board combines the ESP32-S3's integrated Classical CAN controller with an external MCP2518FD CAN FD controller, giving the microcontroller simultaneous access to two completely independent CAN buses.

Why You Cannot Connect Classical CAN and CAN FD on the Same Bus

One common misconception is that CAN FD is simply a faster version of Classical CAN and that both can coexist on the same physical network.

That is only partially true.

Both protocols use the same arbitration phase, allowing arbitration to occur at the nominal bus speed. However, once a CAN FD frame switches to the higher data rate (Bit Rate Switching - BRS), Classical CAN controllers no longer understand what they are seeing.

A Classical CAN controller interprets the high-speed data phase as a protocol violation and immediately generates error frames. As a result:

  • Classical CAN nodes continuously report errors.

  • CAN FD communication is disrupted.

  • The network becomes unusable.

Therefore, a network containing Classical CAN controllers cannot simply be upgraded by introducing CAN FD traffic. The two technologies must be separated into different physical CAN segments connected through a gateway.

When Does a Gateway Make Sense?

A gateway becomes particularly attractive whenever only a small portion of an existing system requires modernization.

Typical examples include:

  • Adding a new CAN FD sensor to an existing Classical CAN system

  • Connecting legacy ECUs to a modern vehicle backbone

  • Integrating older industrial controllers into new automation systems

  • Agricultural equipment upgrades

  • Marine electronics modernization

  • Laboratory test benches where both technologies must coexist

In many cases, replacing a single legacy ECU would require:

  • New hardware design

  • New firmware development

  • Extensive validation

  • Regulatory re-certification

Developing a gateway often requires only a few hundred lines of software while leaving the existing equipment completely untouched.

Hardware Platform

ESP32S3 Board with CAN FD and Classical CAN PortsThe ESP32-S3 Board with CAN FD and Classical CAN Ports is particularly well suited for this application because it already contains everything needed.

Its dual CAN architecture consists of:

Classical CAN

  • ESP32-S3 integrated TWAI controller

  • Dedicated CAN transceiver

CAN FD

  • Microchip MCP2518FD controller

  • High-speed CAN FD transceiver

  • SPI interface to the ESP32-S3

Additional hardware features include:

  • Dual-core 240 MHz processor

  • 8 MB Flash

  • 8 MB PSRAM

  • Native USB

  • Wi-Fi

  • Bluetooth LE

  • 7–24 V power input

This eliminates the need for external CAN shields or additional processor boards.

The Simplest Gateway

The easiest implementation performs nothing more than frame forwarding.

Whenever a Classical CAN frame is received:

  1. Read the CAN identifier.

  2. Read the DLC.

  3. Copy the data bytes.

  4. Transmit the frame on the CAN FD network as a Classical-format CAN frame.

Likewise, incoming Classical-format frames on the CAN FD network are forwarded to the Classical CAN network.

No protocol translation is required.

This solution is often sufficient because CAN FD controllers are fully backward compatible with Classical CAN frames.

The firmware can therefore remain remarkably small.

Message Filtering

Most gateways quickly evolve beyond simple forwarding.

Typical filtering functions include:

  • Forward only selected identifiers

  • Block unwanted traffic

  • Change priorities

  • Separate diagnostic traffic

  • Create virtual subnetworks

Filtering reduces network load and allows the gateway to isolate legacy devices from unnecessary CAN FD traffic.

Identifier Translation

Two independent networks frequently use different identifier assignments.

The gateway can therefore translate:

  • Standard to extended identifiers

  • Extended to standard identifiers

  • One identifier range into another

  • Proprietary identifiers into standardized ones

This enables otherwise incompatible systems to communicate.

Scaling Data

Some systems transmit raw sensor values while newer equipment expects engineering units.

The gateway can therefore perform calculations such as:

  • Temperature conversion

  • Pressure scaling

  • RPM conversion

  • Unit conversion

  • Offset correction

Instead of modifying every ECU, only the gateway firmware requires updating.

Converting CAN FD Frames into Multiple Classical CAN Frames

One of the greatest advantages of CAN FD is its payload size.

Classical CAN:

  • Maximum 8 data bytes

CAN FD:

  • Up to 64 data bytes

When a CAN FD message contains more than eight bytes, the gateway can split the information into several Classical CAN frames.

For example:

64-byte CAN FD payload

Eight Classical CAN messages with 8-byte payloads each

The receiving Classical CAN node simply processes the individual messages according to a predefined protocol.

Depending on the application, the gateway may add:

  • Sequence numbers

  • Packet counters

  • Checksums

  • Start/end markers

  • Timeout monitoring

This approach is particularly useful when transmitting larger datasets such as calibration tables, measurement blocks, configuration parameters, or firmware update packets.

Combining Multiple Classical CAN Frames into One CAN FD Frame

The reverse operation is equally useful.

Suppose eight Classical CAN nodes periodically transmit related sensor values.

Instead of forwarding eight individual messages, the gateway can aggregate them into one CAN FD frame.

Advantages include:

  • Reduced bus utilization

  • Lower protocol overhead

  • Faster transmission

  • Better synchronization of related data

For example:

Eight 8-byte Classical CAN messages

One 64-byte CAN FD frame

This technique is especially attractive when connecting legacy sensors to modern data loggers or cloud gateways.

Data Buffering

Because CAN FD can transmit data considerably faster than Classical CAN, temporary buffering often becomes necessary.

The gateway may need to:

  • Queue incoming Classical CAN messages

  • Assemble complete CAN FD packets

  • Reconstruct fragmented messages

  • Handle burst traffic

  • Prioritize urgent messages

The ESP32-S3's generous RAM resources simplify these tasks.

Timeouts and Error Handling

A robust gateway should never blindly forward data.

Recommended features include:

  • CAN bus error monitoring

  • Bus-off recovery

  • Missing message detection

  • Timeout supervision

  • Duplicate frame detection

  • Queue overflow handling

  • Error statistics

These diagnostics become invaluable during system commissioning.

Additional Intelligent Gateway Functions

Once the gateway exists, additional functionality becomes almost free from a hardware perspective.

Examples include:

  • Message logging to Flash memory

  • USB CAN analyzer

  • Wi-Fi diagnostics interface

  • Bluetooth configuration

  • Remote firmware updates

  • Web-based configuration pages

  • MQTT cloud connectivity

  • OTA firmware updates

  • Data recording for troubleshooting

The gateway effectively becomes a smart communication node rather than merely a protocol converter.

Real-World Applications

A Classical CAN to CAN FD gateway can be used in many environments:

  • Agricultural equipment modernization

  • Heavy-duty vehicle retrofits

  • Industrial automation

  • Marine electronics

  • Robotics

  • Test benches

  • Manufacturing equipment

  • Laboratory instrumentation

  • Prototype development

  • Vehicle diagnostics

In all these cases, the gateway extends the useful life of existing hardware while enabling access to modern CAN FD networks.

Software Complexity Is Lower Than Expected

Many engineers initially assume that developing a Classical CAN to CAN FD gateway requires a major software effort. In reality, the simplest implementation is little more than:

  • Receive a frame on one CAN interface
  • Copy the CAN identifier
  • Copy the DLC
  • Copy the payload
  • Transmit the frame on the opposite CAN interface

The ESP32-S3 Board with CAN FD and Classical CAN Ports makes the task even easier by including sample source code that already demonstrates simultaneous operation of both the Classical CAN (TWAI) and CAN FD interfaces. This example serves as an excellent starting point for a gateway application, allowing developers to focus on the conversion logic rather than low-level driver implementation. In many cases, the required software consists of only a small amount of application code built on top of the provided example.

From there, additional capabilities can be added incrementally as project requirements evolve:

  • Message filtering
  • Identifier translation
  • Data scaling
  • Frame aggregation
  • Frame fragmentation
  • Diagnostics
  • Logging
  • Wireless configuration and monitoring

This modular approach allows developers to create a functional gateway with minimal programming effort while retaining the flexibility to expand the software into a sophisticated protocol conversion platform as needed.

Conclusion

Migrating from Classical CAN to CAN FD does not necessarily require replacing every existing controller on the network. In many applications, a dedicated gateway provides a far more practical and economical solution.

By keeping the Classical CAN and CAN FD networks physically separated, the gateway eliminates protocol conflicts while enabling seamless communication between legacy and next-generation devices. Depending on application requirements, it can function as a simple frame forwarder, a sophisticated protocol translator, or an intelligent edge processor that filters, aggregates, fragments, logs, and distributes data across multiple networks.

The ESP32-S3 Board with CAN FD and Classical CAN Ports offers an ideal hardware foundation for such projects. With integrated support for both CAN technologies, abundant processing power, native USB, wireless connectivity, and a flexible software environment, it allows developers to build anything from a straightforward protocol bridge to a feature-rich communication gateway—all without redesigning existing CAN hardware.


Developing IoT Projects with ESP32: Unlock the full Potential of ESP32 in IoT development to create production-grade smart devicesDeveloping IoT Projects with ESP32: Unlock the full Potential of ESP32 in IoT development to create production-grade smart devices

From smart sensors and edge computing to cloud integration and TinyML, this comprehensive guide walks you through every stage of modern IoT development using the ESP32 and industry-standard tools, frameworks, and technologies.

Key Features

  • Build complete IoT applications from the ground up with ESP32

  • Connect devices securely to the cloud and visualize real-time data

  • Develop practical projects including an audio player, smart home automation, voice-enabled devices, and TinyML applications

Book Description

The ESP32 has become one of the world's most popular microcontrollers for Internet of Things (IoT) applications, combining Wi-Fi, Bluetooth, impressive processing power, and low energy consumption in an affordable platform. Whether you're developing connected sensors, industrial controllers, or smart home devices, this book provides a complete roadmap for creating reliable, production-ready IoT systems.

Beginning with the fundamentals of IoT architecture and real-world design concepts, you'll build an ESP32-based application step by step. Along the way, you'll learn how to interface with sensors, manage peripherals, and integrate powerful libraries such as LittleFS and LVGL. You'll then connect your projects to Wi-Fi networks, implement industry-standard security features, exchange data with cloud platforms, and create professional dashboards using Grafana.

The book also explores emerging edge AI technologies by introducing TinyML on the ESP32-S3. Using the Edge Impulse platform, you'll learn how to develop, deploy, and run machine-learning models directly on embedded hardware, enabling intelligent devices that process data locally without relying on cloud computing.

With numerous hands-on examples and progressively more advanced projects, you'll steadily build practical skills throughout the book. The journey culminates in a complete Smart Home project that brings together embedded hardware, networking, cloud services, security, visualization, and edge AI into one integrated IoT solution.

If you're ready to move beyond simple ESP32 examples and build secure, scalable, and intelligent connected devices, this book will provide the knowledge and practical experience you need. More information...

CAN Bus vs. CAN FD: When Is It Worth Upgrading? A Practical Guide for Embedded System Developers

For more than three decades, Classical CAN (Controller Area Network) has been the workhorse of industrial automation, automotive electronics, agricultural machinery, marine systems, and countless embedded applications. It has earned a reputation for exceptional reliability, deterministic communication, and outstanding error detection. Yet the demands placed on embedded networks continue to grow. Today's systems generate far more [...]

Read More »


How to Build a CAN Bus Prototype Before Designing Your PCB

Modern embedded systems rarely begin with a custom PCB. In fact, the fastest and often the most successful development projects start on inexpensive development hardware that allows engineers to validate concepts, write firmware, and test communication long before the first schematic is finalized. When developing CAN Bus and SAE J1939 applications, I have found that the [...]

Read More »


Raspberry Pi CAN Bus and LIN Bus Interface: CAN FD Development Made Easy

The Raspberry Pi has evolved far beyond its educational roots. With modern multi-core processors, generous memory, Linux support, and an enormous software ecosystem, it has become one of the most capable embedded computing platforms available today. When combined with a CAN and LIN interface, the Raspberry Pi transforms into an excellent development platform for automotive, industrial [...]

Read More »


Building a Classical CAN to CAN FD Gateway with ESP32-S3: A Powerful Migration Platform for Next-Generation Networks

As CAN FD (Flexible Data-Rate) continues to gain adoption across automotive, industrial, agricultural, and heavy-duty vehicle applications, many developers face a common challenge: How do you connect legacy Classical CAN networks with newer CAN FD systems? One practical solution is a protocol gateway that can receive messages on one network, process or translate them, and transmit [...]

Read More »


Why CAN Bus Is One of the Most Reliable Communication Systems Ever Created

When engineers design communication systems for vehicles, industrial machinery, agricultural equipment, marine electronics, and embedded control systems, reliability is often more important than raw speed. A lost message in a music streaming application may go unnoticed. A lost message containing engine speed, brake status, steering angle, or hydraulic pressure can lead to equipment malfunction, downtime, or [...]

Read More »


LIN Bus Development Made Easy: Integrating Automotive LIN Networks with Any UART-Based Embedded System

Modern automobiles contain dozens of electronic control units (ECUs) that communicate with each other to manage everything from engine performance to seat adjustments. While high-speed networks such as CAN Bus handle critical vehicle functions, many automotive subsystems rely on a simpler and less expensive communication technology: the Local Interconnect Network, better known as LIN Bus. For [...]

Read More »


Mastering CAN Bus: Essential Guide to Understanding and Troubleshooting Vehicle Networks

In today’s world of connected vehicles and industrial automation, understanding the details of networked communication protocols has become a pivotal skill for engineers and technicians alike. The book Mastering CAN Scratch: Understanding & Troubleshooting (ISBN/ASIN B0G24Z25RZ) steps into this space by offering a comprehensive, hands-on guide to the widely used Controller Area Network (CAN) bus [...]

Read More »


Understanding the Role of LIN Bus in Automotive Networking

The Local Interconnect Network (LIN) bus is a serial communication protocol designed to facilitate cost-effective networking of sensors, actuators, and other components within automotive systems. Developed in the late 1990s by a consortium of European automakers, including BMW, Volkswagen Group, Audi, Volvo Cars, and Mercedes-Benz, along with technology partners such as Volcano Automotive Group and [...]

Read More »


LIN To CAN Bus Gateway - Implementing CAN Bus And Lin Bus Master With Arduino-Compatible Teensy Board

This post is a follow-up to a previous entry, LIN To CAN Bus Gateway - Prototyping And Firmware Development With The Arduino-Compatible Teensy Board. The Teensy USB Development Board Teensy is a brand of microcontroller development boards created by PJRC and designed by the co-owner, Paul Stoffregen. As a long-time maker of creative technologies, Paul saw the versatility [...]

Read More »