We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我能读得到i2c的id,但是没法实现录音功能
//控制 ES7243E 音频编解码器的 ADC (Analog-to-Digital Converter) 功能的使能或禁用 void es7243e_adc_enable(bool enable) { if (enable) { es7243e_write_byte(0xF9, 0x00); es7243e_write_byte(0x04, 0x01); es7243e_write_byte(0x17, 0x01); es7243e_write_byte(0x20, 0x10); es7243e_write_byte(0x21, 0x10); es7243e_write_byte(0x00, 0x80); es7243e_write_byte(0x01, 0x3A); es7243e_write_byte(0x16, 0x3F); es7243e_write_byte(0x16, 0x00); } else { es7243e_write_byte(0x04, 0x02); es7243e_write_byte(0x04, 0x01); es7243e_write_byte(0xF7, 0x30); es7243e_write_byte(0xF9, 0x01); es7243e_write_byte(0x16, 0xFF); es7243e_write_byte(0x17, 0x00); es7243e_write_byte(0x01, 0x38); es7243e_write_byte(0x20, 0x00); es7243e_write_byte(0x21, 0x00); es7243e_write_byte(0x00, 0x00); es7243e_write_byte(0x00, 0x1E); es7243e_write_byte(0x01, 0x30); es7243e_write_byte(0x01, 0x00); } } void es7243e_init(void) { i2c_bus_init();//i2c初始化
es7243e_write_byte(0x01, 0x3A); es7243e_write_byte(0x00, 0x80); es7243e_write_byte(0xF9, 0x00); es7243e_write_byte(0x04, 0x02); es7243e_write_byte(0x04, 0x01); es7243e_write_byte(0xF9, 0x01); es7243e_write_byte(0x00, 0x1E); es7243e_write_byte(0x01, 0x00); es7243e_write_byte(0x02, 0x00); es7243e_write_byte(0x03, 0x20); es7243e_write_byte(0x04, 0x01); es7243e_write_byte(0x0D, 0x00); es7243e_write_byte(0x05, 0x00); es7243e_write_byte(0x06, 0x03); // SCLK=MCLK/4 es7243e_write_byte(0x07, 0x00); // LRCK=MCLK/256 es7243e_write_byte(0x08, 0xFF); // LRCK=MCLK/256 es7243e_write_byte(0x09, 0xCA); es7243e_write_byte(0x0A, 0x85); es7243e_write_byte(0x0B, 0x00); es7243e_write_byte(0x0E, 0xBF); es7243e_write_byte(0x0F, 0x80); es7243e_write_byte(0x14, 0x0C); es7243e_write_byte(0x15, 0x0C); es7243e_write_byte(0x17, 0x02); es7243e_write_byte(0x18, 0x26); es7243e_write_byte(0x19, 0x77); es7243e_write_byte(0x1A, 0xF4); es7243e_write_byte(0x1B, 0x66); es7243e_write_byte(0x1C, 0x44); es7243e_write_byte(0x1E, 0x00); es7243e_write_byte(0x1F, 0x0C); es7243e_write_byte(0x20, 0x1A); //PGA gain +30dB es7243e_write_byte(0x21, 0x1A); //PGA gain +30dB es7243e_write_byte(0x00, 0x80); //Slave Mode es7243e_write_byte(0x01, 0x3A); es7243e_write_byte(0x16, 0x3F); es7243e_write_byte(0x16, 0x00); es7243e_adc_enable(false);
} void i2s_driver_init(void) { // gpio_set_direction(ES7243_I2S_MCLK,GPIO_MODE_OUTPUT); // gpio_set_level(ES7243_I2S_MCLK,1); i2s_chan_config_t cfg = I2S_CHANNEL_DEFAULT_CONFIG(ES7243_I2S_NUM,I2S_ROLE_MASTER); //cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer ESP_ERROR_CHECK(i2s_new_channel(&cfg,NULL,&rx_handle)); i2s_std_config_t std_cfg = { .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(ES7243_I2S_FRE), .slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO), .gpio_cfg = { .mclk = ES7243_I2S_MCLK, .bclk = ES7243_I2S_BCLK, .ws = ES7243_I2S_WS, .dout = ES7243_I2S_DOUT, .din = ES7243_I2S_DIN, .invert_flags = { .mclk_inv = false, .bclk_inv = false, .ws_inv = false, }, }, }; std_cfg.clk_cfg.mclk_multiple = 384; ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle,&std_cfg)); ESP_ERROR_CHECK(i2s_channel_enable(rx_handle)); // i2s_tdm_config_t i2s_tdm_rx_cfg ={ // .clk_cfg = { // .clk_src = I2S_CLK_SRC_DEFAULT, // .sample_rate_hz = 48000, // .mclk_multiple = 256 // }, // .gpio_cfg = { // .mclk = ES7243_I2S_MCLK, // .bclk = ES7243_I2S_BCLK, // .ws = ES7243_I2S_WS, // .dout = -1, // ES7210 only has ADC capability // .din = ES7243_I2S_DIN // }, // .slot_cfg = I2S_TDM_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, EXAMPLE_I2S_TDM_SLOT_MASK), // }; // ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle, &i2s_tdm_rx_cfg)); // ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
}
void MEMS_READ_Task(void) { size_t r_bytes = 0; //ESP_ERROR_CHECK(i2s_channel_enable(rx_handle)); while(1) { int8_t sBuffer =(int8_t)malloc(2400 * sizeof(int8_t)); if (sBuffer == NULL) { printf("Failed to allocate memory for sBuffer\n"); return; } esp_err_t result = i2s_channel_read(rx_handle, sBuffer, 2400, &r_bytes, portMAX_DELAY) ; if (result == ESP_OK) { int samples_read = r_bytes / 8; if (samples_read > 0) { int mean = 0; for (int i = 0; i < samples_read; ++i) { mean += (sBuffer[i]); } mean /= samples_read; printf("%d\n",mean); } } else { printf("Read Task: i2s read failed\n"); } vTaskDelay(pdMS_TO_TICKS(500)); free(sBuffer); } ESP_ERROR_CHECK(i2s_channel_disable(rx_handle));
} 以上是我重点代码,请问下,这个无法录音,在代码方面有问题吗?
The text was updated successfully, but these errors were encountered:
可以dump下es7243e的寄存器,对比看和设定是否一致,如果一致在看下线上的信号是否OK
Sorry, something went wrong.
No branches or pull requests
我能读得到i2c的id,但是没法实现录音功能
//控制 ES7243E 音频编解码器的 ADC (Analog-to-Digital Converter) 功能的使能或禁用
void es7243e_adc_enable(bool enable)
{
if (enable) {
es7243e_write_byte(0xF9, 0x00);
es7243e_write_byte(0x04, 0x01);
es7243e_write_byte(0x17, 0x01);
es7243e_write_byte(0x20, 0x10);
es7243e_write_byte(0x21, 0x10);
es7243e_write_byte(0x00, 0x80);
es7243e_write_byte(0x01, 0x3A);
es7243e_write_byte(0x16, 0x3F);
es7243e_write_byte(0x16, 0x00);
} else {
es7243e_write_byte(0x04, 0x02);
es7243e_write_byte(0x04, 0x01);
es7243e_write_byte(0xF7, 0x30);
es7243e_write_byte(0xF9, 0x01);
es7243e_write_byte(0x16, 0xFF);
es7243e_write_byte(0x17, 0x00);
es7243e_write_byte(0x01, 0x38);
es7243e_write_byte(0x20, 0x00);
es7243e_write_byte(0x21, 0x00);
es7243e_write_byte(0x00, 0x00);
es7243e_write_byte(0x00, 0x1E);
es7243e_write_byte(0x01, 0x30);
es7243e_write_byte(0x01, 0x00);
}
}
void es7243e_init(void)
{
i2c_bus_init();//i2c初始化
}
void i2s_driver_init(void)
{
// gpio_set_direction(ES7243_I2S_MCLK,GPIO_MODE_OUTPUT);
// gpio_set_level(ES7243_I2S_MCLK,1);
i2s_chan_config_t cfg = I2S_CHANNEL_DEFAULT_CONFIG(ES7243_I2S_NUM,I2S_ROLE_MASTER);
//cfg.auto_clear = true; // Auto clear the legacy data in the DMA buffer
ESP_ERROR_CHECK(i2s_new_channel(&cfg,NULL,&rx_handle));
i2s_std_config_t std_cfg = {
.clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(ES7243_I2S_FRE),
.slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
.gpio_cfg = {
.mclk = ES7243_I2S_MCLK,
.bclk = ES7243_I2S_BCLK,
.ws = ES7243_I2S_WS,
.dout = ES7243_I2S_DOUT,
.din = ES7243_I2S_DIN,
.invert_flags = {
.mclk_inv = false,
.bclk_inv = false,
.ws_inv = false,
},
},
};
std_cfg.clk_cfg.mclk_multiple = 384;
ESP_ERROR_CHECK(i2s_channel_init_std_mode(rx_handle,&std_cfg));
ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
// i2s_tdm_config_t i2s_tdm_rx_cfg ={
// .clk_cfg = {
// .clk_src = I2S_CLK_SRC_DEFAULT,
// .sample_rate_hz = 48000,
// .mclk_multiple = 256
// },
// .gpio_cfg = {
// .mclk = ES7243_I2S_MCLK,
// .bclk = ES7243_I2S_BCLK,
// .ws = ES7243_I2S_WS,
// .dout = -1, // ES7210 only has ADC capability
// .din = ES7243_I2S_DIN
// },
// .slot_cfg = I2S_TDM_PHILIPS_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO, EXAMPLE_I2S_TDM_SLOT_MASK),
// };
// ESP_ERROR_CHECK(i2s_channel_init_tdm_mode(rx_handle, &i2s_tdm_rx_cfg));
// ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
}
void MEMS_READ_Task(void)
{
size_t r_bytes = 0;
//ESP_ERROR_CHECK(i2s_channel_enable(rx_handle));
while(1)
{
int8_t sBuffer =(int8_t)malloc(2400 * sizeof(int8_t));
if (sBuffer == NULL) {
printf("Failed to allocate memory for sBuffer\n");
return;
}
esp_err_t result = i2s_channel_read(rx_handle, sBuffer, 2400, &r_bytes, portMAX_DELAY) ;
if (result == ESP_OK)
{
int samples_read = r_bytes / 8;
if (samples_read > 0)
{
int mean = 0;
for (int i = 0; i < samples_read; ++i) {
mean += (sBuffer[i]);
}
mean /= samples_read;
printf("%d\n",mean);
}
}
else {
printf("Read Task: i2s read failed\n");
}
vTaskDelay(pdMS_TO_TICKS(500));
free(sBuffer);
}
ESP_ERROR_CHECK(i2s_channel_disable(rx_handle));
}
以上是我重点代码,请问下,这个无法录音,在代码方面有问题吗?
The text was updated successfully, but these errors were encountered: