### Answers checklist.
- [X] I have read the documentation [ESP-IDF Programmi…ng Guide](https://docs.espressif.com/projects/esp-idf/en/latest/) and the issue is not addressed there.
- [X] I have updated my IDF branch (master or release) to the latest version and checked that the issue is present there.
- [X] I have searched the issue tracker for a similar issue and not found a similar issue.
### IDF version.
v5.0.1-320-ge14c47ee44
### Operating System used.
Linux
### How did you build your project?
Command line with idf.py
### If you are using Windows, please specify command line type.
None
### Development Kit.
TTGO T8
### Power Supply used.
USB
### What is the expected behavior?
I expect to read I2S data from the channel.
### What is the actual behavior?
The I2S data is not received at all.
### Steps to reproduce.
I've updated your "i2c_record" example:
```c
/* I2S Digital Microphone Recording Example */
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_log.h"
#include "esp_err.h"
#include "esp_system.h"
#include "esp_vfs_fat.h"
#include "esp_timer.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/i2s_std.h"
#include "driver/i2c.h"
#include "driver/uart.h"
#include "sdcard.h"
static const char *TAG = "pdm_rec_example";
#define EXAMPLE_SAMPLE_RATE 16000
#define EXAMPLE_BIT_SAMPLE 32
#define I2S_MIC_BUFF_SIZE (4096)
#define GPS_UART_BUFFER_SIZE 2048 /*!< UART ring buffer size */
#define GPS_UART_QUEUE_SIZE 100 /*!< UART queue size to store parsed sentences */
#define GPS_UART_PORT UART_NUM_1 /*!< GPS UART port */
#define GPS_UART_ERR_COUNT_UNTIL_RESET 20 /*!< Restart the GPS task on successive errors */
#define GPS_SDCARD_TIMER_PERIOD_S 1 /*!< GPS log to sdcard timer period */
static i2s_chan_handle_t rx_chan;
static int32_t i2s_raw_buff[I2S_MIC_BUFF_SIZE];
static int16_t i2s_buff[I2S_MIC_BUFF_SIZE];
static esp_err_t gps_init_uart(int rx_pin, int tx_pin) {
static QueueHandle_t xQueueUART; /*!< UART raw data queue */
static const uint8_t baudRateCmd[] = {
0xB5, // sync char 1
0x62, // sync char 2
0x06, // class
0x00, // id
0x14, // length
0x00, //
0x01, // payload
0x00, // payload
0x00, // payload
0x00, // payload
0xD0, // payload
0x08, // payload
0x00, // payload
0x00, // payload
0x00, // payload
0xC2, // payload
0x01, // payload
0x00, // payload
0x07, // payload
0x00, // payload
0x03, // payload
0x00, // payload
0x00, // payload
0x00, // payload
0x00, // payload
0x00, // payload
0xC0, // CK_A
0x7E, // CK_B
};
uart_config_t uart_cfg = {
.baud_rate = 9600,
.data_bits = UART_DATA_8_BITS,
.parity = UART_PARITY_DISABLE,
.stop_bits = UART_STOP_BITS_1,
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
.source_clk = UART_SCLK_DEFAULT,
};
if (rx_pin == 0 || tx_pin == 0) {
return ESP_ERR_INVALID_ARG;
}
BSP_SOFTCHECK(uart_driver_install(GPS_UART_PORT, GPS_UART_BUFFER_SIZE * 2, 0, GPS_UART_QUEUE_SIZE, &xQueueUART, 0));
BSP_SOFTCHECK(uart_param_config(GPS_UART_PORT, &uart_cfg));
BSP_SOFTCHECK(uart_set_pin(GPS_UART_PORT, rx_pin, tx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE));
BSP_SOFTCHECK(uart_enable_pattern_det_baud_intr(GPS_UART_PORT, '\n', 1, 9, 0, 0));
// Reset the pattern queue length to record at most 10 pattern positions.
BSP_SOFTCHECK(uart_pattern_queue_reset(GPS_UART_PORT, GPS_UART_QUEUE_SIZE));
// update the baud rate to 115200
uart_write_bytes(GPS_UART_PORT, (char*)baudRateCmd, sizeof(baudRateCmd));
vTaskDelay(pdMS_TO_TICKS(100));
BSP_SOFTCHECK(uart_set_baudrate(GPS_UART_PORT, 115200));
ESP_LOGI(TAG, "GPS started");
return ESP_OK;
}
void record_raw()
{
int flash_wr_size = 0;
ESP_LOGI(TAG, "Opening file");
uint32_t flash_rec_time = 491520 / 3;
FILE *f = fopen("/sd/record.raw", "w");
if (f == NULL) {
ESP_LOGE(TAG, "Failed to open file for writing");
return;
}
size_t bytes_read;
int cnt = 0;
int64_t dur = 0;
while (flash_wr_size < flash_rec_time) {
const int64_t t_start = esp_timer_get_time();
if (i2s_channel_read(rx_chan, i2s_raw_buff, I2S_MIC_BUFF_SIZE * sizeof(int32_t), &bytes_read, 1000) == ESP_OK) {
dur += esp_timer_get_time() - t_start;
cnt++;
const int samples_read = bytes_read / sizeof(int32_t);
for (int i = 0; i < samples_read; i++)
{
i2s_buff[i] = (i2s_raw_buff[i]) >> 11;
}
fwrite(i2s_buff, sizeof(int16_t), samples_read, f);
flash_wr_size += bytes_read;
} else {
printf("Read Failed!\n");
}
}
ESP_LOGI(TAG, "i2s_read duration: %lld us", dur / cnt);
ESP_LOGI(TAG, "Recording done!");
fclose(f);
ESP_LOGI(TAG, "File written on SDCard");
}
static void init_microphone(void)
{
/* Setp 1: Determine the I2S channel configuration and allocate two channels one by one
* The default configuration can be generated by the helper macro,
* it only requires the I2S controller id and I2S role
* The tx and rx channels here are registered on different I2S controller,
* only ESP32-C3, ESP32-S3 and ESP32-H2 allow to register two separate tx & rx channels on a same controller */
i2s_chan_config_t rx_chan_cfg = {
.id = I2S_NUM_0,
.role = I2S_ROLE_MASTER,
.dma_desc_num = 4,
.dma_frame_num = 1024,
.auto_clear = false,
};
ESP_ERROR_CHECK(i2s_new_channel(&rx_chan_cfg, NULL, &rx_chan));
i2s_std_config_t rx_std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(EXAMPLE_SAMPLE_RATE),
.slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_32BIT, I2S_SLOT_MODE_MONO),
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED, // some codecs may require mclk signal, this example doesn't need it
.bclk = 4,
.ws = 5,
.dout = I2S_GPIO_UNUSED,
.din = 27,
},
};
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_chan, &rx_std_cfg));
/* Step 3: Enable the tx and rx channels before writing or reading data */
ESP_ERROR_CHECK(i2s_channel_enable(rx_chan));
}
void i2c_master_init(i2c_port_t i2c_port, int sda, int scl)
{
if (sda == 0 || scl == 0) {
return;
}
int intr_flag_disable = 0;
/* I2C master doesn't need buffer */
size_t i2c_master_rx_buf_disable = 0;
size_t i2c_master_tx_buf_disable = 0;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = sda,
.scl_io_num = scl,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 400000,
};
ESP_LOGI(TAG, "Initializing I2C%d SDA=%d SCL=%d clk=%lu", i2c_port, sda, scl, conf.master.clk_speed);
ESP_ERROR_CHECK(i2c_param_config(i2c_port, &conf));
ESP_ERROR_CHECK(i2c_driver_install(
i2c_port, conf.mode, i2c_master_rx_buf_disable, i2c_master_tx_buf_disable, intr_flag_disable));
}
void app_main(void)
{
ESP_ERROR_CHECK(gpio_install_isr_service(ESP_INTR_FLAG_IRAM | ESP_INTR_FLAG_LEVEL3));
// Mount the SDCard for recording the audio file
sdcard_mount_mmc();
gps_init_uart(23, 19);
i2c_master_init(1, 26, 25);
init_microphone();
// Start Recording
record_raw();
// Stop I2S driver and destroy
ESP_ERROR_CHECK(i2s_channel_disable(rx_chan));
ESP_ERROR_CHECK(i2s_del_channel(rx_chan));
}
```
If I comment out either
```c
gps_init_uart(23, 19);
```
or
```c
i2c_master_init(1, 26, 25);
```
the app works as intended: I do receive I2S data. But not when both I2C and UART are installed.
I found a number of related issues (https://github.com/espressif/esp-idf/issues/7767, https://github.com/adafruit/circuitpython/issues/6254, https://github.com/espressif/arduino-esp32/issues/7648, https://esp32.com/viewtopic.php?t=2902, https://github.com/espressif/arduino-esp32/issues/4686) but none of them describes any fix.
### Debug Logs.
```plain
I (29) boot: ESP-IDF v5.0.1-320-ge14c47ee44 2nd stage bootloader
I (29) boot: compile time 12:07:52
I (29) boot: chip revision: v3.0
I (34) boot.esp32: SPI Speed : 40MHz
I (38) boot.esp32: SPI Mode : DIO
I (43) boot.esp32: SPI Flash Size : 2MB
I (47) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (56) boot: ## Label Usage Type ST Offset Length
I (64) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (71) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (78) boot: 2 factory factory app 00 00 00010000 00100000
I (86) boot: End of partition table
I (90) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0f9bch ( 63932) map
I (122) esp_image: segment 1: paddr=0001f9e4 vaddr=3ffb0000 size=00634h ( 1588) load
I (123) esp_image: segment 2: paddr=00020020 vaddr=400d0020 size=2ad18h (175384) map
I (191) esp_image: segment 3: paddr=0004ad40 vaddr=3ffb0634 size=01a98h ( 6808) load
I (194) esp_image: segment 4: paddr=0004c7e0 vaddr=40080000 size=0f4ach ( 62636) load
I (230) boot: Loaded app from partition at offset 0x10000
I (230) boot: Disabling RNG early entropy source...
I (242) cpu_start: Pro cpu up.
I (242) cpu_start: Starting app cpu, entry point is 0x40081398
0x40081398: call_start_cpu1 at /home/dizcza/tools/esp-idf/components/esp_system/port/cpu_start.c:142
I (0) cpu_start: App cpu up.
I (258) cpu_start: Pro cpu start user code
I (258) cpu_start: cpu freq: 160000000 Hz
I (258) cpu_start: Application information:
I (263) cpu_start: Project name: i2s_recorder_ex
I (269) cpu_start: App version: 1
I (273) cpu_start: Compile time: Mar 15 2023 12:34:58
I (279) cpu_start: ELF file SHA256: 383826619059703b...
I (285) cpu_start: ESP-IDF: v5.0.1-320-ge14c47ee44
I (291) cpu_start: Min chip rev: v0.0
I (296) cpu_start: Max chip rev: v3.99
I (301) cpu_start: Chip rev: v3.0
I (306) heap_init: Initializing. RAM available for dynamic allocation:
I (313) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (319) heap_init: At 3FFB8AD8 len 00027528 (157 KiB): DRAM
I (325) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (331) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (338) heap_init: At 4008F4AC len 00010B54 (66 KiB): IRAM
I (346) spi_flash: detected chip: generic
I (349) spi_flash: flash io: dio
W (353) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (367) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
I (377) sdcard: Mounting SD MMC...
I (427) sdcard: SD card mounted at /sd
Name: SD32G
Type: SDHC/SDXC
Speed: 40 MHz
Size: 29580MB
CSD: ver=2, sector_size=512, capacity=60579840 read_bl_len=9
SSR: bus_width=1
Free: 29517MB
I (437) uart: queue free spaces: 100
I (537) pdm_rec_example: GPS started
I (537) pdm_rec_example: Initializing I2C1 SDA=26 SCL=25 clk=400000
D (537) i2s_common: rx channel is registered on I2S0 successfully
W (537) i2s_common: dma frame num is out of dma buffer size, limited to 1023
D (547) i2s_common: DMA malloc info: dma_desc_num = 4, dma_desc_buf_size = dma_frame_num * slot_num * data_bit_width = 4092
D (557) i2s_std: Clock division info: [sclk] 160000000 Hz [mdiv] 39 [mclk] 4096000 Hz [bdiv] 4 [bclk] 1024000 Hz
D (567) i2s_std: The rx channel on I2S0 has been initialized to STD mode successfully
D (577) i2s_common: i2s rx channel enabled
I (577) pdm_rec_example: Opening file
Read Failed!
Read Failed!
Read Failed!
Read Failed!
```
### More Information.
The default sdkconfig is used.