Page 1 of 1

ESP32 with INMP441,I2S

Posted: Thu Sep 17, 2020 2:47 am
by Celeste
Using digital microphone INMP441 to collect data, with known sensitivity of -26dbFS, how should we convert the output data into sound pressure value?

code:
#define I2S_PORT I2S_NUM_0
#define I2S_SCK 14
#define I2S_WS 15
#define I2S_SD 32

const int BLOCK_SIZE = 128;

void i2s_install(){

const i2s_config_t i2s_config = {
.mode = i2s_mode_t(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 44100, //采样频率,默认44100Hz
.bits_per_sample = i2s_bits_per_sample_t(32),
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false
};

i2s_driver_install(I2S_PORT,&i2s_config,0,NULL);
}

void i2s_setpin(){
const i2s_pin_config_t pin_config = {
.bck_io_num = I2S_SCK,
.ws_io_num = I2S_WS,
.data_out_num = -1,
.data_in_num = I2S_SD
};

i2s_set_pin(I2S_PORT, &pin_config);
}

void setup() {

Serial.begin(115200);//启动串口
Serial.println("Configuring I2S...");
i2s_install();
i2s_setpin();
i2s_start(I2S_PORT);
Serial.println("I2S driver installed.");

}

void loop() {

uint32_t sample = 0;
int bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY);
if (bytes_read > 0) {

Serial.println(sample);
}

}