Espressif ESP32-S2 Programming Manual page 460

Table of Contents

Advertisement

Chapter 2. API Reference
Message Flag
TWAI_MSG_FLAG_EXTD
TWAI_MSG_FLAG_RTR
TWAI_MSG_FLAG_SS
TWAI_MSG_FLAG_SELF
TWAI_MSG_FLAG_DLC_NON_COMP
TWAI_MSG_FLAG_NONE
Examples
Configuration & Installation
and start the TWAI driver via the use of the various configuration structures, macro initializers, the
twai_driver_install()
#include
"driver/gpio.h"
#include
"driver/twai.h"
void
app_main()
{
//Initialize configuration structures using macro initializers
twai_general_config_t g_config
NUM_22, TWAI_MODE_NORMAL);
twai_timing_config_t t_config
twai_filter_config_t f_config
//Install TWAI driver
if
(twai_driver_install(&g_config, &t_config, &f_config)
printf("Driver
}
else
{
printf("Failed to install
return;
}
//Start TWAI driver
if
(twai_start()
printf("Driver
}
else
{
printf("Failed to start
return;
}
...
}
The usage of macro initializers is not mandatory and each of the configuration structures can be manually.
Message Transmission
twai_message_t
type and
#include
"driver/twai.h"
...
Espressif Systems
Description
Message is in Extended Frame Format (29bit ID)
Message is a Remote Frame (Remote Transmission Request)
Transmit message using Single Shot Transmission (Message will not be retrans-
mitted upon error or loss of arbitration). Unused for received message.
Transmit message using Self Reception Request (Transmitted message will also
received by the same node). Unused for received message.
Message's Data length code is larger than 8. This will break compliance with
TWAI
Clears all bit fields. Equivalent to a Standard Frame Format (11bit ID) Data
Frame.
The following code snippet demonstrates how to configure, install,
function, and the
twai_start()
=
TWAI_GENERAL_CONFIG_DEFAULT(GPIO_NUM_21, GPIO_
=
TWAI_TIMING_CONFIG_500KBITS();
=
TWAI_FILTER_CONFIG_ACCEPT_ALL();
installed\n");
driver\n");
==
ESP_OK) {
started\n");
driver\n");
The following code snippet demonstrates how to transmit a message via the usage of the
twai_transmit()
Submit Document Feedback
function.
function.
449
==
ESP_OK) {
(continues on next page)
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