- #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 "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/i2s.h"
- #include "driver/gpio.h"
- #include "driver/spi_common.h"
- #include "sdmmc_cmd.h"
- #include "sdkconfig.h"
- #define I2S_NUM (0)
- #define I2S_WS 15
- #define I2S_SD 13
- #define I2S_SCK 2
- #define SAMPLE_RATE (44100)
- #define WAVE_FREQ_HZ (441)
- #define SAMPLE_PER_CYCLE (SAMPLE_RATE/WAVE_FREQ_HZ)
- #define SAMPLE_SIZE (1024)
- void app_main(void)
- {
- i2s_config_t i2s_config = {
- .mode = I2S_MODE_MASTER | I2S_MODE_RX,
- .sample_rate = 44100,
- .bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
- .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
- .communication_format = I2S_COMM_FORMAT_STAND_I2S,
- .use_apll = false,
- .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, // Interrupt level 1, default 0
- .dma_buf_count = 8,
- .dma_buf_len = 1024,
- .tx_desc_auto_clear = true,
- .fixed_mclk = -1
- };
- i2s_pin_config_t pin_config = {
- .bck_io_num = I2S_SCK,
- .ws_io_num = I2S_WS,
- .data_out_num = I2S_PIN_NO_CHANGE,
- .data_in_num = I2S_SD
- };
- i2s_driver_install(I2S_NUM, &i2s_config, 0, NULL);
- i2s_set_pin(I2S_NUM, &pin_config);
- i2s_start(I2S_NUM);
- printf("I2S is ready!\n");
- int16_t *i2s_output = (int16_t *)malloc(sizeof(uint16_t) * SAMPLE_SIZE);
- int bits = 8;
- size_t bytes_read = 0;
- while (1) {
- i2s_read(I2S_NUM, (char *)i2s_output, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &bytes_read, portMAX_DELAY);
- printf("data: %hn\n", i2s_output);
- vTaskDelay(1000 / portTICK_RATE_MS);
- }
- }
Problem about simple I2S data read code for ESP32-S2 and INMP441 microphone
Problem about simple I2S data read code for ESP32-S2 and INMP441 microphone
Hi! I'm trying to write a basic i2s code to take microphone data, and I don't have much ESP or C knowledge. I am using ESP32-S2-MINI1 (devkit) and INMP441. I cannot make it work, so I would be very grateful if you help.
Who is online
Users browsing this forum: No registered users and 209 guests