21 Two-wire Automotive Interface (TWAI)
Single Channel and Non-Return-to-Zero: The bus consists of a single channel to carry bits, thus communication
is half-duplex. Synchronization is also derived from this channel, thus extra channels (e.g., clock or enable) are
not required. The bit stream of a TWAI message is encoded using the Non-Return-to-Zero (NRZ) method.
Bit Values: The single channel can either be in a Dominant or Recessive state, representing a logical 0 and
a logical 1 respectively. A node transmitting a Dominant state will always override a another node transmitting
a Recessive state. The physical implementation on the bus is left to the application level to decide (e.g.,
differential wiring).
Bit-Stuffing: Certain fields of TWAI messages are bit-stuffed. A Transmitter that transmits five consecutive bits
of the same value should automatically insert a complementary bit. Likewise, a Receiver that receives five
consecutive bits should treat the next bit as a stuff bit. Bit stuffing is applied to the following fields: SOF,
Arbitration Field, Control Field, Data Field, and CRC Sequence (see Section
Multi-cast: All nodes receive the same bits as they are connected to the same bus. Data is consistent across
all nodes unless there is a bus error (See Section 21.3.3).
Multi-master: Any node can initiate a transmission. If a transmission is already ongoing, a node will wait until
the current transmission is over before beginning its own transmission.
Message-Priorities and Arbitration: If two or more nodes simultaneously initiate a transmission, the TWAI pro-
tocol ensures that one node will win arbitration of the bus. The Arbitration Field of the message transmitted by
each node is used to determine which node will win arbitration.
Error Detection and Signaling: Each node will actively monitor the bus for errors, and signal the detection errors
by transmitting an Error Frame.
Fault Confinement: Each node will maintain a set of error counts that are incremented/decremented according
to a set of rules. When the error counts surpass a certain threshold, a node will automatically eliminate itself
from the network by switching itself off.
Configurable Bit Rate: The bit rate for a single TWAI bus is configurable. However, all nodes within the same
bus must operate at the same bit rate.
Transmitters and Receivers: At any point in time, a TWAI node can either be a Transmitter or a Receiver.
• A node originating a message is a Transmitter. The node remains a Transmitter until the bus is idle or until
the node loses arbitration. Note that multiple nodes can be Transmitter if they have yet to lose arbitration.
• All nodes that are not Transmitters are Receivers.
21.3.2 TWAI Messages
TWAI nodes use messages to transmit data, and signal errors to other nodes. Messages are split into various
frame types, and some frame types will have different frame formats. The TWAI protocol has of the following
frame types:
• Data Frames
• Remote Frames
• Error Frames
• Overload Frames
• Interframe Space
Espressif Systems
546
Submit Documentation Feedback
21.3.2
for more details).
ESP32 TRM (Version 5.2)
Need help?
Do you have a question about the ESP32 and is the answer not in the manual?