SUCCESS!
After some try-and-error, I have a working configuration!
I tested with a little Edge Impulse Studio AI Keyword Spotting App, it is WORKING OK!
The WORKING config shown below…
The following is a FULL CODE sample using the I2S MIC PDM config for use with XIAO ESP32S3 SENSE { After uploading, open the Serial Plotter to see the MIC output }:
#include <driver/i2s.h>
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM ),
.sample_rate = 16000U,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
//.channel_format = I2S_CHANNEL_FMT_ONLY_RIGHT, // Also works
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
//.communication_format = I2S_COMM_FORMAT_PCM, // Also works
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,
.dma_buf_len = 1024,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
};
i2s_pin_config_t i2s_mic_pins = {
.bck_io_num = I2S_PIN_NO_CHANGE,
.ws_io_num = 42,
.data_out_num = I2S_PIN_NO_CHANGE,
.data_in_num = 41
};
void setup() {
Serial.begin(115200);
// start up the I2S peripheral
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &i2s_mic_pins);
}
#define BUFFER_SIZE 512
int16_t raw_samples[BUFFER_SIZE];
void loop() {
// read from the I2S device
size_t bytes_read = 0;
i2s_read(I2S_NUM_0, raw_samples, sizeof(int16_t) * BUFFER_SIZE, &bytes_read, portMAX_DELAY);
int samples_read = bytes_read / sizeof(int16_t);
for (int i = 0; i < samples_read; i++) {
Serial.printf("%ld\n", raw_samples[i]);
}
}
Edge Impulse Studio
Edge Impulse Studio does not yet support ESP32S3 officially, so, the NPU functions of the CHIP cannot be used yet (we need to disable NN [neural net] function calls in code)… but, at least, now I can use the generated (there) code to run on the XIAO ESP32S3 SENSE with minimalist changes/adaptations…
It is nice to be able to run some basic AI-MACHINE LEARNING stuff on the XIAO ESP32S3, even without the full benefit of the NPU functions on the CHIP…
Regards all,
Valter