
专业版
esp32s3单声道喇叭麦克风测试板
2.2k
0
0
14
简介
模块板载MSM261S4030H0R数字麦克风,MAX98357AEWL+T数字功放,复用I2S的BCLK和WS信号,仅需四根线,为项目添加喇叭麦克风功能。
简介:模块板载MSM261S4030H0R数字麦克风,MAX98357AEWL+T数字功放,复用I2S的BCLK和WS信号,仅需四根线,为项目添加喇叭麦克风功能。开源协议
:GPL 3.0
(未经作者授权,禁止转载)创建时间:2024-04-20 07:06:03更新时间:2024-04-28 03:52:26
描述
模块板载MSM261S4030H0R数字麦克风,MAX98357AEWL+T数字功放,两者使用一组I2S的BCLK和WS信号,仅需四根线,为项目添加喇叭麦克风功能。
测试代码
IDF5.2
ESP32-S3 N16R8
注意在menuconfig里启用psram
#include <stdint.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2s_std.h"
#include "driver/gpio.h"
#include "esp_check.h"
#define EXAMPLE_STD_BCLK_IO1 GPIO_NUM_17 // I2S bit clock io number I2S_BCLK
#define EXAMPLE_STD_WS_IO1 GPIO_NUM_15 // I2S word select io number I2S_LRC WS
#define EXAMPLE_STD_DOUT_IO1 GPIO_NUM_18 // I2S data out io number I2S_DOUT SPK
#define EXAMPLE_STD_DIN_IO1 GPIO_NUM_16 // I2S data in io number I2S_DIN MIC
#define SAMPLE_RATE 48000
i2s_chan_handle_t tx_handle;
i2s_chan_handle_t rx_handle;
EXT_RAM_BSS_ATTR uint8_t buffer[1024 * 200 * 3];
static void i2s_example_task(void *args) {
size_t n;
while (1) {
for (int i = 0; i < 200; ++i) {
if (i2s_channel_read(rx_handle, buffer + i * 1024 * 3, 1024 * 3, &n, 1000) == ESP_OK) {
printf("Read Task: %d\n", n);
}
}
for (int i = 0; i < 200; ++i) {
if (i2s_channel_write(tx_handle, buffer + i * 1024* 3, 1024 * 3, &n, 1000) == ESP_OK) {
printf("Write Task: %d\n", n);
}
}
}
ESP_ERROR_CHECK(i2s_channel_disable(tx_handle));
ESP_ERROR_CHECK(i2s_channel_disable(rx_handle));
vTaskDelete(NULL);
}
static void i2s_example_init_std_simplex(void) {
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(I2S_NUM_AUTO, I2S_ROLE_MASTER);
ESP_ERROR_CHECK(i2s_new_channel(&chan_cfg, &tx_handle, &rx_handle));
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(SAMPLE_RATE),
.slot_cfg = {\
.data_bit_width = I2S_DATA_BIT_WIDTH_24BIT, \
.slot_bit_width = I2S_SLOT_BIT_WIDTH_32BIT, \
.slot_mode = I2S_SLOT_MODE_MONO, \
.slot_mask = I2S_STD_SLOT_LEFT, \
.ws_width = I2S_DATA_BIT_WIDTH_32BIT, \
.ws_pol = false, \
.bit_shift = true, \
.left_align = true, \
.big_endian = false, \
.bit_order_lsb = false \
},
.gpio_cfg = {
.mclk = I2S_GPIO_UNUSED, // some codecs may require mclk signal, this example doesn't need it
.bclk = EXAMPLE_STD_BCLK_IO1,
.ws = EXAMPLE_STD_WS_IO1,
.dout = EXAMPLE_STD_DOUT_IO1,
.din = EXAMPLE_STD_DIN_IO1,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false,
},
},
};
ESP_ERROR_CHECK(i2s_channel_init_std_mode(tx_handle, &std_cfg));
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle, &std_cfg));
}
void app_main(void) {
i2s_example_init_std_simplex();
ESP_ERROR_CHECK(i2s_channel_enable(tx_handle));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
xTaskCreate(i2s_example_task, "i2s_example_task", 4096, NULL, 5, NULL);
}
设计图

BOM


添加到专辑
0
0
分享
侵权投诉
评论