EasyManua.ls Logo

Espressif ESP32-S2 - Page 460

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

Table of Contents