ESP32 CAN

The ESP32 has an integrated CAN controller and therefore doesn’t necessarily need an external controller. Some variants (ESP32-C5, ESP32-C6, ESP32-P4) have multiple CAN controllers - see Multiple CAN Controllers below. You only need to specify the RX and TX pins. Any GPIO will work.

# Example configuration entry
canbus:
  - platform: esp32_can
    tx_pin: GPIOXX
    rx_pin: GPIOXX
    can_id: 4
    bit_rate: 50kbps
    on_frame:
      ...

Configuration variables

  • rx_pin (Required, Pin): Receive pin.

  • tx_pin (Required, Pin): Transmit pin.

  • mode (Optional, enum): Operating mode. One of:

    • NORMAL: Normal operation, sends ACK signals. (default)
    • LISTENONLY: Receive data only, no ACK signals sent.
  • rx_queue_len (Optional, int): Length of RX queue.

  • tx_queue_len (Optional, int): Length of TX queue, 0 to disable.

  • tx_enqueue_timeout (Optional, Time): Maximum time to wait when the TX queue is full before dropping the message (by default, this is set to the time it takes to send 10 CAN messages at the given bit rate).

  • All other options from Canbus.

Listen-Only Mode

Listen-only mode configures the ESP32’s TWAI controller to passively monitor CAN bus traffic without participating in the protocol. In this mode:

  • The controller receives all CAN frames but does not send ACK signals
  • Transmission is disabled (attempts will log a warning)

This is particularly useful for:

  • BMS monitoring: Tapping into battery-to-inverter communication (e.g., Pylontech, Deye)
  • CAN bus debugging: Observing traffic without interfering
  • Multi-master scenarios: When the ESP32 should observe but not participate
# Example configuration for passive CAN bus monitoring
canbus:
  - platform: esp32_can
    tx_pin: GPIOXX
    rx_pin: GPIOXX
    bit_rate: 500kbps
    mode: LISTENONLY
    on_frame:
      - can_id: 0x355
        then:
          - lambda: |-
              ESP_LOGI("can", "SOC: %d%%", x[0]);

ℹ️ Note

In listen-only mode, the ESP32 will not send ACK signals. This means other devices on the bus will not receive acknowledgment for their transmissions from the ESP32. This is the desired behavior when monitoring an existing bus where other devices are already handling acknowledgments.

✅ Tip

The tx_pin is still required even in listen-only mode, as the ESP32 TWAI driver requires both pins for initialization. However, no data will be transmitted on this pin when using LISTENONLY mode.

The following table lists the bit rates supported by the component for ESP32 variants:

bit_rateESP32Other variants*
1KBPSx
5KBPSx
10KBPSx
12K5BPSx
16KBPSx
20KBPSx
25KBPSxx
31K25BPS
33KBPS
40KBPS
50KBPSxx
80KBPS
83K3BPS
95KBPS
100KBPSxx
125KBPS (Default)xx
250KBPSxx
500KBPSxx
800KBPSxx
1000KBPSxx

Other variants: ESP32-C3, ESP32-C5, ESP32-C6, ESP32-H2, ESP32-P4, ESP32-S2, ESP32-S3

ℹ️ Note

ESP32-C2 and ESP32-C61 do not have TWAI/CAN hardware and are not supported.

Multiple CAN Controllers

Some ESP32 variants have multiple CAN (TWAI) controllers:

  • ESP32-C5: 2 controllers
  • ESP32-C6: 2 controllers
  • ESP32-P4: 3 controllers

All other supported variants have a single controller. ESP32-C2 and ESP32-C61 do not have CAN hardware.

Wiring options

5V CAN transceivers are cheap and generate compliant levels. If you power your board with 5V this is the preferred option. R501 is important to reduce the 5V logic level down to 3.3V, to avoid damaging the ESP32. You can alternatively use a voltage divider here instead.

Image

If you prefer to only have a 3.3V power supply, special 3.3V CAN transceivers are available.

Image

See Also