EasyManuals Logo

Espressif ESP32-S2 User Manual

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
Page #309 background imageLoading...
Page #309 background image
Chapter 2. API Reference
(continued from previous page)
.ws_io_num = 5,
.data_out_num = 18,
.data_in_num = I2S_PIN_NO_CHANGE
};
i2s_set_pin(i2s_num, &pin_config);
Running I2S Communication To perform a transmission:
Prepare the data for sending
Call the function i2s_write() and pass the data buffer address and data length to it
The function will write the data to the DMA Tx buffer, and then the data will be transmitted automatically.
i2s_write(I2S_NUM, samples_data, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &i2s_bytes_
,write, 100);
To retrieve received data, use the function i2s_read(). It will retrieve the data from the DMA Rx buffer, once
the data is received by the I2S controller.
i2s_read(I2S_NUM, data_recv, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &i2s_bytes_read,
,100);
You can temporarily stop the I2S driver by calling the function i2s_stop(), which will disable the I2S Tx/Rx
units until the function i2s_start() is called. If the function :cpp:func`i2s_driver_install` is used, the driver will
start up automatically eliminating the need to call i2s_start().
Deleting the Driver If the established communication is no longer required, the driver can be removed to free
allocated resources by calling i2s_driver_uninstall().
Application Example
A code example for the I2S driver can be found in the directory peripherals/i2s.
In addition, there is a short configuration examples for the I2S driver.
I2S configuration Example for general usage.
#include "driver/i2s.h"
static const int i2s_num = 0; // i2s port number
i2s_config_t i2s_config = {
.mode = I2S_MODE_MASTER | I2S_MODE_TX,
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S
.tx_desc_auto_clear = false,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 // Interrupt level 1, default 0
};
static const i2s_pin_config_t pin_config = {
.bck_io_num = 4,
(continues on next page)
Espressif Systems 298
Submit Document Feedback
Release v4.4

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

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

Espressif ESP32-S2 Specifications

General IconGeneral
BrandEspressif
ModelESP32-S2
CategorySingle board computers
LanguageEnglish