All ESP32 variants integrate a so-called TWAI (Two-Wire Automotive Interface) controller. The TWAI is compatible with the ISO11898-1 protocol and corresponds to a CAN2.0 interface. So the Espressif Controllers also become interesting for all industrial applications where CAN Bus Interface is used for communication.
Features supported by the ESP32 TWAI controller #
- Supports Standard Frame Format (11-bit ID) and Extended Frame Format (29-bit ID)
- Bit rates from 25 Kbit/s to 1 Mbit/s
- Multiple modes of operation
- Listen Only (no influence on bus)
- Self Test (transmissions do not require acknowledgment)
- 64-byte Receive FIFO
- Special transmissions
- Single-shot transmissions (does not automatically re-transmit upon error)
- Self Reception (the TWAI controller transmits and receives messages simultaneously)
- Acceptance Filter (supports single and dual filter modes)
- Error detection and handling
- Error counters
- Configurable Error Warning Limit
- Error Code Capture
- Arbitration Lost Capture
Development Environment #
A description of the Two-Wire Automotive Interface and the driver configuration can be found in the ESP-IDF Programming Guide, the driver component itself and examples are in the ESP-IDF directory on Github.
It should be mentioned that in any case an external CAN transceiver is needed to physically connect the ESP32 to a CAN network.
To help developers get started, Espressif also provides software examples. The TWAI Network Example is a demo application that shows how to use the TWAI driver to program a target (ESP32, etc.) as a TWAI node and let two (or more) nodes communicate over a TWAI network. You can run the TWAI Self Test Example before to check if your CAN transceiver is connected to your ESP32 board correctly.
You have to make sure to use the right GPIOs on your board for TX and RX. You find a description of each board in the Programming Guide. See below links to some popular boards to easily find the description:
- ESP32-DevKitC V4 (for different ESP32 modules)
- ESP32-S2-DevKitC-1 (ESP32-S2-SOLO)
- ESP32-S2-DevKitM-1 (ESP32-S2-MINI)
- ESP32-C3-DevKitM-1 (ESP32-C3-MINI)
To get started with Espressif development environment check out also our other docs regarding Espressif.
Espressif is providing more ressources on their webpages: