esp32s3和inmp441都是正确连接上的,代码也是正确的,但是串口监视器一直给出0没有检测到音频
#include <Arduino.h>
#include <driver/i2s.h>
// 定义I2S引脚
#define I2S_WS 18
#define I2S_SD 16
#define I2S_SCK 17
#define I2S_PORT I2S_NUM_0
#define bufferLen 1024 // 缓冲区大小
int16_t sBuffer[bufferLen]; // 存储音频数据的缓冲区
void setup() {
Serial.begin(115200);
Serial.println("Setup I2S...");
// 初始化I2S
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 48000, // 采样率
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
.intr_alloc_flags = 0,
.dma_buf_count = 16,
.dma_buf_len = bufferLen,
.use_apll = false
};
i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
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_set_pin(I2S_PORT, &pin_config);
i2s_start(I2S_PORT);
}
void loop() {
// 从INMP441读取数据
size_t bytesIn = 0;
esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen * sizeof(int16_t), &bytesIn, portMAX_DELAY);
if (result == ESP_OK && bytesIn > 0) {
// 通过串口输出数据
Serial.print("[");
for (int i = 0; i < bufferLen; i++) {
Serial.print(sBuffer[i]);
if (i < bufferLen - 1) {
Serial.print(", ");
}
}
Serial.println("]");
}
}
