CAN Transceiver
Puts an MCU's CAN controller on a shared bus
Component type:
CanTransceiver
The CAN Transceiver connects one microcontroller’s CAN controller (called TWAI on Espressif chips) to a shared CAN bus. It behaves like an ideal TJA1050 or SN65HVD230: use one per node, and join all of them on one bus line.
| Pin | Direction | Connect to |
|---|---|---|
TXD | Input | The MCU’s CAN TX pin |
RXD | Output | The MCU’s CAN RX pin |
BUS | Bus line | The BUS pin of every other transceiver |
A real transceiver has two bus wires, CANH and CANL. The simulator folds them
into one logical line, the BUS pin, so a two-wire bus is a single wire here.
The part has no power pins and no configuration. There are no termination resistors to add.
Behaviour
Section titled “Behaviour”TXDlow drives the bus dominant.TXDhigh or unwired leaves it recessive.- The bus is wired-AND: if any node drives dominant, the bus is dominant. This is what lets CAN arbitration and ACK work.
RXDfollows the bus, including the node’s own transmissions, as on real hardware.
Wiring example
Section titled “Wiring example”Two nodes: a Seeed XIAO ESP32-C3 and an ESP32-P4 board, each with its own transceiver.
| From | To |
|---|---|
XIAO ESP32-C3 D2 (GPIO4, TWAI TX) | Transceiver A TXD |
Transceiver A RXD | XIAO ESP32-C3 D3 (GPIO5, TWAI RX) |
ESP32-P4 GPIO22 (TWAI TX) | Transceiver B TXD |
Transceiver B RXD | ESP32-P4 GPIO23 (TWAI RX) |
Transceiver A BUS | Transceiver B BUS |
XIAO ESP32-C3 ESP32-P4 board D2 (GPIO4) ──► TXD ┐ ┌ TXD ◄── GPIO22 D3 (GPIO5) ◄── RXD ┘ A BUS ─────── BUS B └ RXD ──► GPIO23Both chips route TWAI through the GPIO matrix, so any free GPIO works. GPIO4
and GPIO5 are the defaults in ESP-IDF v5.5’s twai_network example. Add more
nodes by giving each one a transceiver and wiring its BUS pin to the same net.
With ESP-IDF’s driver/twai.h, the C3 side looks like this (use GPIO_NUM_22
and GPIO_NUM_23 on the P4):
twai_general_config_t g = TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_4, GPIO_NUM_5, 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());Things to know
Section titled “Things to know”- A frame needs a second node to be acknowledged. A node alone on the bus, or with only listen-only nodes, gets ACK errors and keeps retransmitting while its transmit error counter rises. This is standard CAN behaviour. Put at least two nodes in normal mode on the bus.
- Every node must use the same bit rate. A node at a different rate sees error frames and disturbs the others.
- Never wire two MCUs’ TX pins straight together. Each node gets its own transceiver.
Limitations
Section titled “Limitations”- CANH and CANL are one logical line, so differential faults (a shorted or open CANH or CANL wire) cannot be modelled.
- No propagation delay, slope control, standby pin or supply behaviour is modelled.