Chapter 2. API Reference
(continued from previous page)
.ws_io_num = 5,
.data_out_num = 18,
.data_in_num = I2S_PIN_NO_CHANGE
};
i2s_driver_install(i2s_num, &i2s_config, 0, NULL); //install and start i2s driver
i2s_set_pin(i2s_num, &pin_config);
...
/* You can reset parameters by calling 'i2s_set_clk'
*
* The low 16 bits are the valid data bits in one chan and the high 16 bits are
* the total bits in one chan. If high 16 bits is smaller than low 16 bits, it will
* be set to a same value as low 16 bits.
*/
uint32_t bits_cfg = (I2S_BITS_PER_CHAN_32BIT << 16) | I2S_BITS_PER_SAMPLE_16BIT;
i2s_set_clk(i2s_num, 22050, bits_cfg, I2S_CHANNEL_STEREO);
...
i2s_driver_uninstall(i2s_num); //stop & destroy i2s driver
API Reference
Header File
• components/driver/include/driver/i2s.h
Functions
esp_err_t i2s_set_pin(i2s_port_t i2s_num, const i2s_pin_config_t *pin)
Set I2S pin number.
Inside the pin configuration structure, set I2S_PIN_NO_CHANGE for any pin where the current configuration
should not be changed.
Note The I2S peripheral output signals can be connected to multiple GPIO pads. However, the I2S peripheral
input signal can only be connected to one GPIO pad.
Parameters
• i2s_num: I2S port number
• pin: I2S Pin structure, or NULL to set 2-channel 8-bit internal DAC pin configuration (GPIO25
& GPIO26)
Note if *pin is set as NULL, this function will initialize both of the built-in DAC channels by default. if
you don’t want this to happen and you want to initialize only one of the DAC channels, you can call
i2s_set_dac_mode instead.
Return
• ESP_OK Success
• ESP_ERR_INVALID_ARG Parameter error
• ESP_FAIL IO error
esp_err_t i2s_driver_install(i2s_port_t i2s_num, const i2s_config_t *i2s_config, int queue_size,
void *i2s_queue)
Install and start I2S driver.
This function must be called before any I2S driver read/write operations.
Parameters
• i2s_num: I2S port number
• i2s_config: I2S configurations - see i2s_config_t struct
• queue_size: I2S event queue size/depth.
• i2s_queue: I2S event queue handle, if set NULL, driver will not use an event queue.
Espressif Systems 299
Submit Document Feedback
Release v4.4