The CAN bus on the ESP32-S3 is implemented through its on-chip TWAI (Two-Wire Automotive Interface) controller. It is compatible with CAN 2.0, supporting 11-bit standard frames and 29-bit extended frames. It handles arbitration, error detection, acceptance filtering, and transmit/receive buffering, but does not include the physical layer. To connect to a real CAN bus, an external CAN transceiver is required. In industrial environments, isolation, TVS/ESD protection, and properly selected termination resistors are also typically necessary. One important limitation to note is that TWAI does not support CAN FD. If your network uses CAN FD or requires multiple CAN channels, consider adding an external SPI CAN controller or choosing a different solution.
This article systematically covers the complete set of knowledge required to use the ESP32-S3 as a CAN bus node, following the sequence: “Capability Limitations → System Architecture → Transceivers and Isolation → Wiring and Termination → Bit Timing and Baud Rates → Software Drivers → Error Handling → Wi-Fi/Bluetooth Coexistence → Typical Applications → Debugging and Troubleshooting → Deployment Checklist.”
1. CAN Capability Limitations of the ESP32-S3
| Item | ESP32-S3 TWAI | Description |
|---|---|---|
| Protocol | CAN 2.0A/B (ISO 11898-1 Classical CAN frames) | Supports 11-bit standard IDs and 29-bit extended IDs |
| CAN FD | Not supported | Cannot transmit or receive FD frames; do not connect it to a network carrying FD frames |
| Number of controllers | 1 channel | Additional channels require external controllers |
| Physical layer | Not included; an external transceiver is required | 3.3V logic levels |
| Pins | TX/RX can be flexibly assigned through the GPIO matrix | Avoid strapping pins and pins occupied by Flash/PSRAM |
| Operating modes | Normal, No-Ack, and Listen-Only | Listen-Only mode does not affect the bus and is suitable for monitoring and analysis |
| Acceptance filtering | Supports single-filter and dual-filter modes (code and mask) | Reduces CPU overhead caused by irrelevant frames |
| Error management | Transmit/receive error counters, error warning, error-passive, and bus-off states | Supports recovery procedures after entering the bus-off state |
| Baud rate range | Common Classical CAN rates, such as 125k/250k/500k/1M | The exact configurable range and timing parameters should be verified against the official documentation |
In short, the ESP32-S3 is well suited for use as a Classical CAN node. If your requirements include CAN FD, multiple CAN channels, or strict hard real-time performance, evaluate external controllers or a different main controller in advance. For guidance on selecting a main controller, refer to ESP8266 vs. ESP32 vs. 8051 Microcontrollers vs. STM32: Comparison and Selection Guide.
2. System Architecture: What Makes Up an ESP32-S3 CAN Node?
From top to bottom, a typical node consists of the following components:
- Application layer: Business logic and protocol stacks, such as custom protocols, CANopen, and J1939. These typically need to be implemented independently or through third-party libraries.
- Driver layer: The ESP-IDF TWAI driver, responsible for initialization, transmission, reception, filtering, alerts, and recovery.
- TWAI controller (on-chip): Handles bit timing, arbitration, CRC, error counting, and buffering.
- CAN transceiver (external): Converts TX/RX logic signals into differential signals (CANH/CANL) and monitors the bus state.
- Isolation and protection (recommended): Digital isolators or integrated isolated transceivers, TVS/ESD protection, and common-mode chokes.
- Bus and cabling: Twisted-pair cable, termination resistors, and connectors.
Insufficient design at any layer may result in a system that “works on the bench but becomes unstable in the field.”
3. How to Select a CAN Transceiver and Isolation Solution
3.1 Why Is a Transceiver Required?
TWAI outputs 3.3V single-ended logic signals, whereas the CAN bus uses differential signaling. During the dominant state (logic 0), a differential voltage develops between CANH and CANL. During the recessive state (logic 1), the two lines return to similar voltage levels. The transceiver converts between these two signal types and provides bus-side drive and protection capabilities.
3.2 Key Selection Criteria
| Selection Criterion | Key Considerations |
|---|---|
| Supply voltage | Prefer transceivers powered by 3.3V or equipped with a logic-level reference pin (VIO) to prevent direct connection of 5V logic signals to ESP32-S3 GPIOs |
| Data rate | Must support your target data rate (Classical CAN typically operates at up to 1 Mbps) |
| Bus protection | Check the voltage tolerance and ESD protection capabilities of the bus pins |
| Standby and wake-up | Consider standby modes when operating on battery power or when low power consumption is required |
| Isolation | An isolated solution is recommended for industrial environments |
| Package and cost | Balance these factors against the overall BOM and available space |
Common 3.3V transceiver options include the SN65HVD23x series. Many 5V transceivers are also available, such as the TJA105x series, with some models featuring a VIO pin for compatibility with 3.3V logic. Always refer to the manufacturer’s datasheet for the specific model and verify its data rate, voltage requirements, and protection ratings.
3.3 Isolation Options
| Solution | Description | Suitable Applications |
|---|---|---|
| Non-isolated transceiver | Low cost and simple design | Desktop development and short-distance applications with a shared ground and very low noise |
| Digital isolator + standard transceiver | Flexible, allowing independent selection of the isolator and isolated power supply | Custom designs requiring trade-offs between cost and performance |
| Integrated isolated CAN transceiver | Combines isolation and transceiver functions in one device, simplifying the design, as seen in common industry product families | Industrial products prioritizing design efficiency and consistency |
Why is isolation necessary in industrial environments?
Industrial sites may involve ground potential differences, inductive load switching, motor and variable-frequency drive noise, and cable faults. Isolation helps prevent these issues from affecting the controller through ground connections or common-mode paths. An isolation solution also requires an isolated power supply, such as an isolated DC-DC converter or an integrated solution. Pay attention to parameters such as isolation withstand voltage and common-mode transient immunity (CMTI), and select sufficient design margins for the operating environment.
4. Wiring and Termination: The Most Common Source of Field Issues
4.1 Termination Resistors
Classical CAN uses a linear bus topology with termination at both ends and no additional termination in the middle. A resistor of approximately 120Ω should be connected between CANH and CANL at each of the two farthest ends of the bus. A common self-check method is to power off the system and measure the resistance between CANH and CANL with a multimeter. When both end terminators are connected, the measured resistance should be approximately 60Ω (two 120Ω resistors in parallel).
| Measurement | Possible Cause |
|---|---|
| Approximately 120Ω | Only one end has a termination resistor |
| Approximately 40Ω | Too many termination resistors may be connected, for example, if a node has a built-in terminator |
| Very low resistance or close to 0Ω | A short circuit may be present |
| Very high resistance | Termination resistors may be missing, or the wiring may be disconnected |
Reminder: Many development boards or modules include built-in termination resistors, which may be enabled or disabled using jumpers or solder pads. Always verify that termination has not been unintentionally enabled on intermediate nodes.
4.2 Topology and Stubs
- Prefer a linear bus topology and keep stubs as short as possible.
- Avoid arbitrary star topologies or long branches, as they can easily cause signal reflections.
- When the number of nodes increases or the data rate is high, stub length becomes more critical.
4.3 Cables and Shielding
- Use impedance-matched shielded twisted-pair cable, preferably dedicated CAN cable with a characteristic impedance of approximately 120Ω.
- Determine the grounding method for the shield according to the isolation design and system grounding scheme to avoid ground loops.
- Connector pinouts can follow common industry conventions, such as the typical CAN_L/CAN_H/GND pin assignments on DB9 connectors or M12 connectors commonly used in industrial applications. Refer to the applicable standard or device manual for the exact pinout.
4.4 Data Rate and Cable Length: A Common Rule-of-Thumb Reference
Cable length and data rate depend on cable quality, the number of nodes, stub length, and the noise environment. The following table provides approximate reference values only; actual performance must be verified through testing.
| Bit Rate | Typical Maximum Bus Length (Rule-of-Thumb Value) |
|---|---|
| 1 Mbps | Approximately 40 m |
| 500 kbps | Approximately 100 m |
| 250 kbps | Approximately 250 m |
| 125 kbps | Approximately 500 m |
As cable length increases, signal round-trip propagation delay becomes more significant. The data rate must be reduced accordingly, with sufficient margin for the sampling point.

5. Bit Timing and Data Rates: Understanding “Why You Cannot Choose a Baud Rate Arbitrarily”
A CAN bit time consists of the synchronization segment, propagation segment, phase segment 1, and phase segment 2. The sampling point is located after phase segment 1. A common practice is to set the sampling point at approximately 75%–87.5% of the bit time and ensure that all nodes on the network use the same data rate and similar sampling points.
- The higher the data rate, the shorter the bit time, making the network more sensitive to cable delay, clock accuracy, and noise.
- Bit timing configurations must match across all nodes; otherwise, numerous error frames may occur.
- ESP-IDF provides predefined timing macros for common data rates and also allows custom prescalers and time segments to accommodate specialized networks.
5.1 How Long Does It Take to Transmit One Frame? (The Correct Estimation Method)
A Classical CAN standard frame carrying 8 bytes of data contains approximately 110 bits without bit stuffing, or around 135 bits when bit stuffing and the interframe space are taken into account. Therefore, the approximate frame transmission times are:
| Data Rate | Transmission Time for an 8-Byte Standard Frame (Approx.) |
|---|---|
| 1 Mbps | Approximately 110–135 µs |
| 500 kbps | Approximately 220–270 µs |
| 250 kbps | Approximately 440–540 µs |
| 125 kbps | Approximately 0.9–1.1 ms |
These are estimated ranges. Actual transmission time depends on the data content (bit stuffing) and frame type.
5.2 Bus Load
When planning periodic messages, calculate the bus utilization rate:
Bus utilization ≈ Total bit time occupied by all frames per unit of time ÷ Total bus bandwidth
In engineering practice, sufficient margin should be reserved for burst traffic and retransmissions. It is not recommended to keep the bus operating close to full utilization over extended periods. The appropriate utilization limit should be determined according to the application’s real-time requirements.
6. Software Development: Using the TWAI Driver in ESP-IDF
6.1 Basic Workflow
- Configuration: Select TX/RX pins, operating mode, bit timing, and acceptance filtering.
- Install and start the driver.
- Transmission: Construct a message containing the ID, data length, data, and flags, then transmit it.
- Reception: Block while waiting for incoming messages in a dedicated task and process them when received.
- Alerts and error handling: Subscribe to alerts, monitor error states, and initiate recovery when necessary.
- Stop and uninstall the driver, if required.
6.2 Example (Classic driver/twai.h API, for Understanding the Workflow Only)
#include "driver/twai.h"
#define CAN_TX_GPIO GPIO_NUM_4 // Example pin; modify according to the actual hardware
#define CAN_RX_GPIO GPIO_NUM_5
void can_init(void)
{
twai_general_config_t g = TWAI_GENERAL_CONFIG_DEFAULT(
CAN_TX_GPIO, CAN_RX_GPIO, TWAI_MODE_NORMAL);
twai_timing_config_t t = TWAI_TIMING_CONFIG_500KBITS();
twai_filter_config_t f = TWAI_FILTER_CONFIG_ACCEPT_ALL();
ESP_ERROR_CHECK(twai_driver_install(&g, &t, &f));
ESP_ERROR_CHECK(twai_start());
}
void can_send_example(void)
{
twai_message_t msg = {
.identifier = 0x123,
.data_length_code = 2,
.data = {0x01, 0x02},
};
twai_transmit(&msg, pdMS_TO_TICKS(100));
}
void can_rx_task(void *arg)
{
twai_message_t rx;
for (;;) {
if (twai_receive(&rx, pdMS_TO_TICKS(1000)) == ESP_OK) {
// Perform only lightweight processing here:
// enqueue the data for processing by an application task
}
}
}Important Notes:
- The pins in this example are for demonstration only. Avoid strapping pins and pins occupied by Flash/PSRAM, and select pins according to the actual board-level design.
- Avoid time-consuming operations in the receive task, such as extensive logging or network requests. Instead, enqueue received data for processing by another task to prevent the receive queue from overflowing.
- The TWAI API may change between ESP-IDF versions. For newer versions, always refer to the official documentation.
6.3 How to Choose the Operating Mode
| Mode | Purpose |
|---|---|
| Normal mode | Standard transmission and reception; participates in arbitration and acknowledgment |
| No-Ack mode | Commonly used for single-node self-testing by looping TX back to RX without requiring acknowledgment from another node |
| Listen-Only mode | Receives only; does not transmit or acknowledge frames. Suitable for bus monitoring and analysis without interfering with an existing network |
6.4 Acceptance Filtering
Acceptance filters use an “acceptance code + mask” to configure the hardware to receive only the IDs of interest, reducing the frequency of CPU interruptions caused by irrelevant frames. When the network carries many frames but the node only needs a small subset of IDs, properly configured filters can significantly reduce CPU load and queue pressure. For bus monitoring, the “accept all” configuration can be used.
7. Error Handling and Reliability: Don’t Let a Node “Fail Silently”
7.1 CAN Node Error States
CAN nodes manage their own operation through the transmit error counter (TEC) and receive error counter (REC):
| State | General Meaning |
|---|---|
| Error Active | Normal state; the node can transmit active error frames |
| Error Warning | A warning indicating that the error counter has reached a relatively high level. ESP32 TWAI issues a warning when the counter reaches 96 |
| Error Passive | The error counter exceeds 127; transmission is restricted, and the node can only send passive error flags |
| Bus-Off | The transmit error counter exceeds 255; the node disconnects from the bus and stops transmitting and receiving |
7.2 Application-Layer Recommendations
- Subscribe to alerts and maintain logs: Log and count events such as error warnings, error-passive states, bus-off conditions, and receive queue overflows.
- Recovery after bus-off: The driver provides a recovery interface, but avoid unlimited retries. Apply a backoff strategy and report the node’s status.
- Heartbeat and timeout monitoring: Critical nodes should periodically transmit heartbeat frames. Receivers should detect timeouts and enter a safe state. This is an effective way to detect “silent failures.”
- Data validity: Add counters or checks to critical application-layer signals to identify stale data.
- Watchdog: Use a watchdog to ensure that the system can recover to a known state if a task becomes unresponsive.
7.3 Safety Functions Such as Emergency Stops
Do not treat general-purpose CAN communication as the sole channel for safety functions. Safety-related functions such as emergency stops and safety interlocks should use solutions that comply with the applicable safety standards, such as hardwired safety circuits or certified safety buses. CAN is better suited for status monitoring and coordination. Designs involving functional safety must be evaluated according to the standards applicable to the relevant industry.
8. Wi-Fi/Bluetooth Coexistence: Real-Time Considerations When Using the ESP32-S3 as a Gateway
The ESP32-S3 has the advantage of supporting both Wi-Fi and Bluetooth, making it well suited for “CAN ↔ network” gateways. However, this also means that wireless protocol stacks and application tasks run concurrently within the system.
- Assign a higher priority to the CAN receive task. If necessary, pin it to a specific core and separate it from network tasks.
- Perform only minimal processing in the receive task. Enqueue the data and let lower-priority tasks handle time-consuming operations such as MQTT, HTTP, and data storage.
- Set an appropriate RX queue depth and evaluate burst traffic under worst-case conditions.
- For closed-loop control requiring deterministic timing, avoid placing the entire workload on a single chip that is also running wireless protocol stacks. Consider placing real-time control on a dedicated controller while using the ESP32-S3 for network connectivity. For the dual-chip architecture approach, refer to ESP8266 vs. ESP32 vs. 8051 Microcontrollers vs. STM32: Comparison and Selection Guide.
9. Expansion Options: What If You Need Multiple CAN Channels or CAN FD?
| Requirement | Common Approach |
|---|---|
| Multiple Classical CAN channels | Add external SPI CAN controllers, such as the commonly used MCP2515, and communicate with the ESP32-S3 via SPI |
| CAN FD | Add an SPI controller that supports CAN FD or select an MCU with built-in CAN FD peripherals |
| Stronger real-time determinism | Use an industrial MCU with CAN/CAN FD peripherals for real-time control, while the ESP32-S3 handles network connectivity |
Adding an external SPI CAN controller increases SPI communication latency and software complexity. Throughput and interrupt handling must be evaluated during the design phase.

10. Typical Applications
| Application Scenario | Description |
|---|---|
| Industrial equipment data gateway | Collect CAN data from equipment and upload it to MQTT brokers or cloud platforms via Wi-Fi/Ethernet |
| CAN ↔ RS485/Modbus protocol conversion | Enable communication between devices using different bus protocols |
| Communication with variable-frequency drives, servos, sensors, and other nodes | Exchange data using higher-layer protocols such as CANopen or custom protocols |
| Agricultural machinery and construction equipment monitoring | Read vehicle or equipment data using application-layer protocols such as J1939. The protocol stack must be implemented independently or through third-party libraries |
| Battery management systems (BMS) and energy equipment communication | Read data such as cell voltages and temperatures |
| Vehicle diagnostics and data logging | Monitor the bus in Listen-Only mode and record and analyze data |
| Local web dashboard | Provide a simple web interface on the ESP32-S3 to display CAN data in real time |
11. Debugging and Common Troubleshooting Issues
| Symptom | Possible Causes | Troubleshooting Steps |
|---|---|---|
| No data received at all | Inconsistent data rates, abnormal transceiver power supply, or incorrect TX/RX pin connections | Verify the data rate first, then check the power supply and pin connections. Use an oscilloscope to inspect the differential waveform |
| Transmission fails when only one node is connected | No other node is available to provide an acknowledgment (ACK) | Use No-Ack mode for single-node testing or connect a second node |
| Error counters continue to increase | Missing or excessive termination resistors, excessively long stubs, excessively high data rate, or high noise levels | Measure bus resistance with the power off, shorten stubs, and reduce the data rate |
| Occasional frame loss or latency jitter | Receive task blocked, insufficient queue depth, or preemption by wireless tasks | Increase the receive task priority, enlarge the queue, and optimize task allocation |
| Node enters the bus-off state | Severe errors or wiring faults | Inspect the wiring and termination, review error logs, and design the recovery strategy carefully |
| Unstable operation in the field despite normal bench testing | Lack of isolation, ground potential differences, or EMC issues | Add isolation and protection components, and optimize shielding and grounding |
Common tools: CAN analyzers (USB-CAN adapters), oscilloscopes (to observe differential voltage levels and waveform quality), and multimeters (to measure termination resistance). When analyzing an existing network, Listen-Only mode can be used to avoid interfering with the bus.
12. Hardware Design and PCB Layout Considerations
- Place the transceiver close to the connector to minimize trace length on the bus side.
- Route CANH and CANL as a matched differential pair, keeping the traces symmetrical and as equal in length as possible. Keep them away from switching power supplies and high-dv/dt areas.
- Add TVS/ESD protection devices and common-mode chokes, depending on EMC requirements. Split termination may be used when necessary to improve common-mode noise performance.
- For isolated designs, ensure that there is no copper pour beneath the isolation barrier and that no traces cross the isolation boundary. Reserve sufficient space for the isolated power supply.
- Provide optional solder pads or jumpers for termination resistors, allowing flexible configuration for nodes at different positions on the bus.
- Reserve test points and debugging interfaces, such as TX/RX and enable/standby pins.
Product development and commercialization also involve costs associated with EMC and wireless certification. Refer to A Complete Breakdown of ESP32 Product Development Costs to plan your budget in advance.
13. Pre-Deployment Checklist
- All nodes use consistent data rates and sampling point configurations.
- A termination resistor of approximately 120Ω is installed at each end of the bus. With the power off, the measured bus resistance is approximately 60Ω.
- Stubs are kept as short as possible, and the topology follows a linear bus structure.
- Shielded twisted-pair cable is used, and the shielding and grounding scheme has been evaluated.
- Industrial nodes use an isolation solution, with isolation withstand voltage and CMTI margins verified.
- TVS/ESD protection and necessary common-mode suppression measures are implemented.
- Receive task priorities and queue depths have been validated through stress testing.
- Heartbeat monitoring, timeout detection, and error logging have been implemented.
- Long-duration testing has been completed in the actual operating environment, including areas with interference sources such as variable-frequency drives and motors.
- The firmware supports version rollback or protection against OTA update failures.
- Safety-related functions do not rely solely on general-purpose CAN communication.
Conclusion
The value of using the ESP32-S3 as a CAN node lies in its integration of Classical CAN, Wi-Fi, and Bluetooth in a single chip, making it well suited for industrial equipment data gateways and connected control units. However, achieving stable operation in real-world environments depends less on the TWAI controller itself and more on transceiver and isolation selection, termination and wiring, bit timing and data rates, error handling and heartbeat mechanisms, and resource allocation between wireless and application tasks. Only by systematically addressing each of these aspects using a checklist can you move from “working on the development board” to “reliable operation in the field.”
If you are planning an industrial gateway, CAN communication module, or controller based on the ESP32-S3 and need end-to-end support, from schematic design and isolation planning to PCB and EMC reviews, prototype development, and mass production, feel free to contact the engineering team at Leadsintec. We can start by reviewing your design and identifying potential risks.














