# Peripherals

[中文]

## Two-Wire Automotive Interface (TWAI)

TWAI provides a brand-new driver interface that supports a wider range of convenient features. Please refer to the programming guide: Two-Wire Automotive Interface (TWAI).

Compared to the legacy driver, the new driver offers several major improvements:

- Event-driven architecture, supporting registration of multiple callback functions

- Runtime configuration changes for bitrate and filter settings

- More intuitive and user-friendly APIs for bitrate and filter configuration

- Support for ESP32-C5 and its FD (Flexible Datarate) capabilities

- Support using multiple TWAI controllers simultaneously

The new driver is located in the esp_driver_twai component. To use it, simply add the component dependency. The relevant header files are esp_driver_twai/include/esp_twai.h and esp_driver_twai/include/esp_twai_onchip.h.

Deprecated/Removed | Replacement | Notes
--- | --- | ---
twai_read_alerts | None | Use `on_state_change` and `on_error` callbacks to receive status and error notifications.
twai_receive | twai_node_receive_from_isr | Can only be called inside the on_rx_done callback.
twai_clear_transmit_queue | None | Not supported at the moment.
twai_clear_receive_queue | None | The new driver uses event-driven receive; blocking receive APIs are not currently provided.

Although we recommend using the new TWAI driver APIs, the legacy driver is still available. To use the legacy driver, include the header file `driver/twai.h`. When using the legacy driver, please note the following:

- The new and legacy drivers are not compatible and must not be used together. Mixing them will trigger warnings during startup, and may even cause crashes and system reboots. To suppress this compatibility check, you may enable the configuration option CONFIG_TWAI_SKIP_LEGACY_CONFLICT_CHECK.

- The legacy driver will no longer receive new features, such as TWAI FD (Flexible Data-rate) support.

## SPI Flash Driver

- New argument `flags` is added to `esp_flash_os_functions_t::start`. Caller and implementer should handle this argument properly.

Was this page helpful?

- Thank you! We received your feedback.
- If you have any comments, fill in Espressif Documentation Feedback Form.

- We value your feedback.
- Let us know how we can improve this page by filling in Espressif Documentation Feedback Form.