Core2 for AWS IoT EduKit BSP 1.5.1
Microphone

The Microphone library provides convenience functions to initialize and de-initialize the SPM1423 microphone over I2S with preset parameters. The I2S bus requires that the initialization and use of the peripheral on the bus is assigned to a dedicated core. The reason for this is that I2S and I2C attaches an interrupt to one of 32 interrupt vectors available per core. Attempting to initialize or access the peripheral without affinity to a specific core will most likely cause a hard fault almost immediately or at some point in time. The microphone cannot be accessed at the same time as the speaker since they both share a common pin (GPIO0).

Circuit Block Diagram for the SPM1423 microphone

To enable this hardware feature using KConfig, use the command pio run --environment core2foraws --target menuconfig from within the root of the project directory in your PlatformIO terminal window and go to the menu Component Config --> Core2 for AWS features to set the features you want to enable.

Example

TThe following example creates a FreeRTOS task that's pinned to Core 1, which intializes the SPM1423 microphone, and then reads 1Kb of sound with the microphone using the ESP-IDF i2s_read function, deinitializes the microphone, uses a loop to print each value of the buffer, and prints the number of bytes read using the ESP logger.

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "core2forAWS.h"
static const char *TAG = "EXAMPLE";
static void microphone_task(void *arg){
/* If the speaker was initialized, be sure to call Speaker_Deinit() and
disable first. */
static int8_t i2s_readraw_buf[1024];
size_t bytes_read;
i2s_read(MIC_I2S_NUMBER, (char*)i2s_readraw_buf, 1024, &bytes_read, pdMS_TO_TICKS(100));
for(uint16_t i = 0; i < 1024; i++){
ESP_LOGI(TAG, "At buffer index %d heard: %d", i, i2s_readraw_buf[i]);
}
ESP_LOGI(TAG, "Read total of %u bytes from microphone", bytes_read);
vTaskDelete(NULL);
}
void app_main(void){
/* Usage of the microphone must be pinned to a specific core since I2S ISR
is assigned per core */
xTaskCreatePinnedToCore(microphone_task, "listen", 4096*2, NULL, 4, NULL, 1);
}
void Core2ForAWS_Init(void)
Initializes the power chip with default values, enables battery charging, and initializes all enabled...
Definition: core2forAWS.c:32
Functions to initialize and access Core2 for AWS IoT EduKit hardware features.
#define TAG
Definition: i2c_device.c:10
void Microphone_Init()
Initializes the microphone over I2S.
Definition: microphone.c:10
void Microphone_Deinit()
De-initializes the microphone over I2S.
Definition: microphone.c:37
#define MIC_I2S_NUMBER
Microphone I2S port number.
Definition: microphone.h:12

Preprocessor Macros

Functions