Espressif ESP32-S2 Programming Manual page 465

Table of Contents

Advertisement

Chapter 2. API Reference
Functions
esp_err_t
twai_driver_install(const
Install TWAI driver.
This function installs the TWAI driver using three configuration structures. The required memory is allocated
and the TWAI driver is placed in the stopped state after running this function.
Note Macro initializers are available for the configuration structures (see documentation)
Note To reinstall the TWAI driver, call twai_driver_uninstall() first
Return
• ESP_OK: Successfully installed TWAI driver
• ESP_ERR_INVALID_ARG: Arguments are invalid
• ESP_ERR_NO_MEM: Insufficient memory
• ESP_ERR_INVALID_STATE: Driver is already installed
Parameters
• [in] g_config: General configuration structure
• [in] t_config: Timing configuration structure
• [in] f_config: Filter configuration structure
esp_err_t
twai_driver_uninstall(void)
Uninstall the TWAI driver.
This function uninstalls the TWAI driver, freeing the memory utilized by the driver. This function can only be
called when the driver is in the stopped state or the bus-off state.
Warning The application must ensure that no tasks are blocked on TX/RX queues or alerts when this function
is called.
Return
• ESP_OK: Successfully uninstalled TWAI driver
• ESP_ERR_INVALID_STATE: Driver is not in stopped/bus-off state, or is not installed
esp_err_t
twai_start(void)
Start the TWAI driver.
This function starts the TWAI driver, putting the TWAI driver into the running state. This allows the TWAI
driver to participate in TWAI bus activities such as transmitting/receiving messages. The TX and RX queue
are reset in this function, clearing any messages that are unread or pending transmission. This function can
only be called when the TWAI driver is in the stopped state.
Return
• ESP_OK: TWAI driver is now running
• ESP_ERR_INVALID_STATE: Driver is not in stopped state, or is not installed
esp_err_t
twai_stop(void)
Stop the TWAI driver.
This function stops the TWAI driver, preventing any further message from being transmitted or received until
twai_start() is called. Any messages in the TX queue are cleared. Any messages in the RX queue should be
read by the application after this function is called. This function can only be called when the TWAI driver is
in the running state.
Warning A message currently being transmitted/received on the TWAI bus will be ceased immediately. This
may lead to other TWAI nodes interpreting the unfinished message as an error.
Return
• ESP_OK: TWAI driver is now Stopped
• ESP_ERR_INVALID_STATE: Driver is not in running state, or is not installed
esp_err_t
twai_transmit(const
Transmit a TWAI message.
This function queues a TWAI message for transmission. Transmission will start immediately if no other mes-
sages are queued for transmission. If the TX queue is full, this function will block until more space becomes
available or until it times out. If the TX queue is disabled (TX queue length = 0 in configuration), this function
Espressif Systems
twai_general_config_t
twai_timing_config_t
*t_config,
*f_config)
twai_message_t
*message, TickType_t ticks_to_wait)
454
Submit Document Feedback
*g_config,
const
const
twai_filter_config_t
Release v4.4

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S2 and is the answer not in the manual?

Table of Contents

Save PDF