Chapter 2. API Reference
}
//Block indefinitely until an alert occurs
uint32_t
alerts_triggered;
twai_read_alerts(&alerts_triggered, portMAX_DELAY);
Stop and Uninstall
The following code demonstrates how to stop and uninstall the TWAI driver via the use of the
twai_stop()
and
twai_driver_uninstall()
#include
"driver/twai.h"
...
//Stop the TWAI driver
if
(twai_stop()
==
ESP_OK) {
printf("Driver
stopped\n");
}
else
{
printf("Failed to stop
return;
}
//Uninstall the TWAI driver
if
(twai_driver_uninstall()
printf("Driver
uninstalled\n");
}
else
{
printf("Failed to uninstall
return;
}
Multiple ID Filter Configuration
that two or more IDs will be accepted for a single filter. For a particular filter to accept multiple IDs, the conflicting
bit positions amongst the IDs must be set in the acceptance mask. The acceptance code can be set to any one of the
IDs.
The following example shows how the calculate the acceptance mask given multiple IDs:
ID1
=
11'b101 1010 0000
ID2
=
11'b101 1010 0001
ID3
=
11'b101 1010 0100
ID4
=
11'b101 1010 1000
//Acceptance Mask
MASK
=
11'b000 0000 1101
Application Examples
Network Example: The TWAI Network example demonstrates communication between
two ESP32-S2s using the TWAI driver API. One TWAI node acts as a network master that initiates and ceases
the transfer of a data from another node acting as a network slave. The example can be found via
als/twai/twai_network.
Alert and Recovery Example: This example demonstrates how to use the TWAI driver's alert and bus-off re-
covery API. The example purposely introduces errors on the bus to put the TWAI controller into the Bus-Off state.
An alert is used to detect the Bus-Off state and trigger the bus recovery process. The example can be found via
peripherals/twai/twai_alert_and_recovery.
Self Test Example: This example uses the No Acknowledge Mode and Self Reception Request to cause the TWAI
controller to send and simultaneously receive a series of messages. This example can be used to verify if the connec-
tions between the TWAI controller and the external transceiver are working correctly. The example can be found via
peripherals/twai/twai_self_test.
Espressif Systems
functions.
driver\n");
==
ESP_OK) {
driver\n");
The acceptance mask in
twai_filter_config_t
451
Submit Document Feedback
(continued from previous page)
can be configured such
peripher-
Release v4.4
Need help?
Do you have a question about the ESP32-S2 and is the answer not in the manual?
Questions and answers