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
  1. // Connections to INMP441 I2S microphone
  2. #define I2S_WS 25
  3. #define I2S_SD 33
  4. #define I2S_SCK 32
  5.  
  6. // Use I2S Processor 0
  7. #define I2S_PORT I2S_NUM_0
  8.  
  9. #define bufferCount 8
  10. #define bufferLen 64
  11.  
  12. int16_t buffer16[bufferLen] = {0};
  13. uint8_t buffer32[bufferLen * 4] = {0};
  14.  
  15. // Set up I2S Processor configuration
  16. void i2s_install() {
  17.   // Set up I2S Processor configuration
  18.   i2s_config_t i2s_config = {
  19.     .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
  20.     .sample_rate = 4000, // or 44100 if you like
  21.     .bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
  22.     .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT, // Ground the L/R pin on the INMP441.
  23.     .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
  24.     .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
  25.     .dma_buf_count = bufferCount,
  26.     .dma_buf_len = bufferLen,
  27.     .use_apll = false,
  28.     .tx_desc_auto_clear = false,
  29.     .fixed_mclk = 0,
  30.   };
  31.  
  32.   i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
  33. }
  34.  
  35. // Set I2S pin configuration
  36. void i2s_setpin() {
  37.     const i2s_pin_config_t pin_config = {
  38.         .bck_io_num = I2S_SCK,
  39.         .ws_io_num = I2S_WS,
  40.         .data_out_num = -1,
  41.         .data_in_num = I2S_SD
  42.     };
  43.  
  44.     i2s_set_pin(I2S_PORT, &pin_config);
  45. }
The problem is after i2s_read funtion, my array value is zero. Below is how I read:
  1. while (1)
  2.     {
  3.         vTaskDelay(1); // Feed for watchdog, if not watchdog timer will be triggered!
  4.  
  5.         i2s_read(I2S_PORT, &buffer32, sizeof(buffer32), &bytesRead, 100);
  6.         int samplesRead = bytesRead / 4;
  7.  
  8.         for (uint8_t i = 0; i < samplesRead; i++) {
  9.             uint8_t mid = buffer32[i * 4 + 2];
  10.             uint8_t msb = buffer32[i * 4 + 3];
  11.             uint16_t raw = (((uint32_t)msb) << 8) + ((uint32_t)mid);
  12.             memcpy(&buffer16[i], &raw, sizeof(raw)); // Copy so sign bits aren't interfered with somehow.
  13.             printf("%d %d %d\n", 3000, -3000, buffer16[i]);
  14.         }
  15.     }
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: No registered users and 364 guests