Chapter 2. API Reference
will return immediately if another message is undergoing transmission. This function can only be called when
the TWAI driver is in the running state and cannot be called under Listen Only Mode.
Note This function does not guarantee that the transmission is successful. The TX_SUCCESS/TX_FAILED
alert can be enabled to alert the application upon the success/failure of a transmission.
Note The TX_IDLE alert can be used to alert the application when no other messages are awaiting transmis-
sion.
Return
• ESP_OK: Transmission successfully queued/initiated
• ESP_ERR_INVALID_ARG: Arguments are invalid
• ESP_ERR_TIMEOUT: Timed out waiting for space on TX queue
• ESP_FAIL: TX queue is disabled and another message is currently transmitting
• ESP_ERR_INVALID_STATE: TWAI driver is not in running state, or is not installed
• ESP_ERR_NOT_SUPPORTED: Listen Only Mode does not support transmissions
Parameters
• [in] message: Message to transmit
• [in] ticks_to_wait: Number of FreeRTOS ticks to block on the TX queue
esp_err_t twai_receive(twai_message_t
Receive a TWAI message.
This function receives a message from the RX queue. The flags field of the message structure will indicate the
type of message received. This function will block if there are no messages in the RX queue
Warning The flags field of the received message should be checked to determine if the received message
contains any data bytes.
Return
• ESP_OK: Message successfully received from RX queue
• ESP_ERR_TIMEOUT: Timed out waiting for message
• ESP_ERR_INVALID_ARG: Arguments are invalid
• ESP_ERR_INVALID_STATE: TWAI driver is not installed
Parameters
• [out] message: Received message
• [in] ticks_to_wait: Number of FreeRTOS ticks to block on RX queue
esp_err_t
twai_read_alerts(uint32_t *alerts, TickType_t ticks_to_wait)
Read TWAI driver alerts.
This function will read the alerts raised by the TWAI driver. If no alert has been issued when this function is
called, this function will block until an alert occurs or until it timeouts.
Note Multiple alerts can be raised simultaneously. The application should check for all alerts that have been
enabled.
Return
• ESP_OK: Alerts read
• ESP_ERR_TIMEOUT: Timed out waiting for alerts
• ESP_ERR_INVALID_ARG: Arguments are invalid
• ESP_ERR_INVALID_STATE: TWAI driver is not installed
Parameters
• [out] alerts: Bit field of raised alerts (see documentation for alert flags)
• [in] ticks_to_wait: Number of FreeRTOS ticks to block for alert
esp_err_t
twai_reconfigure_alerts(uint32_t alerts_enabled, uint32_t *current_alerts)
Reconfigure which alerts are enabled.
This function reconfigures which alerts are enabled. If there are alerts which have not been read whilst recon-
figuring, this function can read those alerts.
Return
• ESP_OK: Alerts reconfigured
• ESP_ERR_INVALID_STATE: TWAI driver is not installed
Parameters
• [in] alerts_enabled: Bit field of alerts to enable (see documentation for alert flags)
Espressif Systems
*message, TickType_t ticks_to_wait)
455
Submit Document Feedback
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?