INMP441 bit per sample problem

khanhbkisp
Posts: 3
Joined: Fri Oct 27, 2023 2:46 pm

INMP441 bit per sample problem

Postby khanhbkisp » Fri Oct 27, 2023 3:19 pm

Hi everyone. I'm working with INMP441 and ESP32 Dev kit v1 in ESP-IDF 4.4.3. I set i2s 32 bit per sample and then using i2s_read function to read data from DMA and store in an array. I copy exactly what this guy do https://esp32.com/viewtopic.php?t=15185

Code: Untitled.c Select all

// Connections to INMP441 I2S microphone
#define I2S_WS 25
#define I2S_SD 33
#define I2S_SCK 32

// Use I2S Processor 0
#define I2S_PORT I2S_NUM_0

#define bufferCount 8
#define bufferLen 64

int16_t buffer16[bufferLen] = {0};
uint8_t buffer32[bufferLen * 4] = {0};

// Set up I2S Processor configuration
void i2s_install() {
// Set up I2S Processor configuration
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = 4000, // or 44100 if you like
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // Ground the L/R pin on the INMP441.
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = bufferCount,
.dma_buf_len = bufferLen,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0,
};

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

// Set I2S pin configuration
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);
}
The problem is after i2s_read funtion, my array value is zero. Below is how I read:

Code: Untitled.c Select all

while (1)
{
vTaskDelay(1); // Feed for watchdog, if not watchdog timer will be triggered!

i2s_read(I2S_PORT, &buffer32, sizeof(buffer32), &bytesRead, 100);
int samplesRead = bytesRead / 4;

for (uint8_t i = 0; i < samplesRead; i++) {
uint8_t mid = buffer32[i * 4 + 2];
uint8_t msb = buffer32[i * 4 + 3];
uint16_t raw = (((uint32_t)msb) << 8) + ((uint32_t)mid);
memcpy(&buffer16[i], &raw, sizeof(raw)); // Copy so sign bits aren't interfered with somehow.
printf("%d %d %d\n", 3000, -3000, buffer16[i]);
}
}
I changed to 16 bit per sample and it works. But I want 32 bit per sample. My code is totally fine when I use arduino (I'm using arduino 2.0.1).
Please help me to find the solution for this problem.

khanhbkisp
Posts: 3
Joined: Fri Oct 27, 2023 2:46 pm

Re: INMP441 bit per sample problem

Postby khanhbkisp » Mon Nov 06, 2023 3:23 pm

Update: I switched to esp-idf 5.1 and it worked quite well. Maybe idf 4.4.3 has problem with reading 32-bit samples with INMP441 ? :D

Who is online

Users browsing this forum: Baidu [Spider], PerplexityBot and 3 guests