I have a simple code reading an i2s microphone on an esp32 written with Arduino. The code runs fine when I build with framework=arduino only.
As soon as I build with famework=arduino,esp-idf the i2s output is only zeros.
I have no issues with my code otherwise. Any ideas?
This works:
[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino
build_flags =
-D ESP32
monitor_speed = 115200
I2S output only zeros:
[env:featheresp32]
platform = espressif32
board = featheresp32
framework = arduino, espidf
build_flags =
-D ESP32
monitor_speed = 115200
platform_packages =
framework-arduinoespressif32 @ GitHub - espressif/arduino-esp32: Arduino core for the ESP32
This is the code I am running:
#include <stdio.h>
#include <Arduino.h>
#include “driver/i2s.h”
#include <soc/i2s_reg.h>
#define SAMPLE_RATE 8000
#define MIC_SAMPLES_BUF 250void setup() {
Serial.begin(115200);
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_I2S),
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 20,
.dma_buf_len = MIC_SAMPLES_BUF,
.use_apll = false,
.tx_desc_auto_clear = true,
.fixed_mclk = 0
};const i2s_pin_config_t pin_config = {
.bck_io_num = 27, // BCKL
.ws_io_num = 13, // LRCL
.data_out_num = -1, // not used (only for speakers)
.data_in_num = 12 // DOUT
};i2s_driver_install(I2S_NUM_1, &i2s_config, 0, NULL);
i2s_zero_dma_buffer(I2S_NUM_1);
i2s_set_pin(I2S_NUM_1, &pin_config);
}uint8_t i2sData[MIC_SAMPLES_BUF*4];
size_t bytes_read = 0;void loop()
{
i2s_read(I2S_NUM_1, &i2sData, sizeof(i2sData), &bytes_read, portMAX_DELAY);
int32_t *samples = (int32_t *)i2sData;
Serial.println(String(samples[0]));
}