No Sound Output from ES8374 Using ESP32 with I2S
Posted: Wed May 28, 2025 12:59 pm
Hello all,
I'm working on a project where I developed my own board using the ES8374 audio codec with an ESP32-WROOM-32E. I’ve read the official datasheet thoroughly and configured the registers step-by-step based on the required clocking and output path. I am trying to get just any sound from ES8374, but no success.
I verified that:
- I2C works correctly. (I have I2C_read registers and they were same as the ones I wrote)
- I2S lines (BCLK, LRCK) have expected signals. Using osciloscope, I verified that BCLK is square wave with 512kHz and LRCK is 16kHz
Despite all this, I’m not getting any sound, not even with a basic square wave tone.
My setup details are as follows.
-I2C: SDA=21, SCL=17
-I2S: BCLK=26, LRCK=25, DOUT=27 (DIN of ES8374)
-No MCLK used. PLL is used
-Sample rate: 16 kHz
-Bits/sample: 16-bit stereo
-Output: Only DAC to SPK, mic/ADC path not used
- I set CE pin of ES8374 to LOW to set address to 0x10
- I am using 0.5W 8 ohm Speaker. Vspeaker is 5V and VDD for analog and digital part is 3V3.
- I am using SPKP and SPKN pins for speaker.
Did I miss critical register that makes speaker off, or DAC mute or are there any known issues with ES8374 and ESP32? Thank you all for your help in advance.
Regards,
I'm working on a project where I developed my own board using the ES8374 audio codec with an ESP32-WROOM-32E. I’ve read the official datasheet thoroughly and configured the registers step-by-step based on the required clocking and output path. I am trying to get just any sound from ES8374, but no success.
I verified that:
- I2C works correctly. (I have I2C_read registers and they were same as the ones I wrote)
- I2S lines (BCLK, LRCK) have expected signals. Using osciloscope, I verified that BCLK is square wave with 512kHz and LRCK is 16kHz
Despite all this, I’m not getting any sound, not even with a basic square wave tone.
My setup details are as follows.
-I2C: SDA=21, SCL=17
-I2S: BCLK=26, LRCK=25, DOUT=27 (DIN of ES8374)
-No MCLK used. PLL is used
-Sample rate: 16 kHz
-Bits/sample: 16-bit stereo
-Output: Only DAC to SPK, mic/ADC path not used
- I set CE pin of ES8374 to LOW to set address to 0x10
- I am using 0.5W 8 ohm Speaker. Vspeaker is 5V and VDD for analog and digital part is 3V3.
- I am using SPKP and SPKN pins for speaker.
Code: Select all
#include <Wire.h>
#include "driver/i2s.h"
// === Pin Definitions ===
#define I2C_SDA 21
#define I2C_SCL 17
#define I2S_BCLK 26
#define I2S_LRCK 25
#define I2S_DOUT 27 // ESP32 -> ES8374 DIN
#define CE_PIN 16
#define ES8374_ADDR 0x10
int16_t squareWave[64];
void generateSquareWave() {
for (int i = 0; i < 64; i += 2) {
squareWave[i] = 8000;
squareWave[i + 1] = -8000;
}
}
void es8374_write(uint8_t reg, uint8_t val) {
Wire.beginTransmission(ES8374_ADDR);
Wire.write(reg);
Wire.write(val);
Wire.endTransmission();
}
void initES8374() {
es8374_write(0x00, 0x1F);
delay(10);
es8374_write(0x00, 0x80);
delay(10);
es8374_write(0x01, 0x33); //0x30
es8374_write(0x02, 0x08);
es8374_write(0x03, 0x20);
//es8374_write(0x04, 0x0C);
es8374_write(0x06, 0x03);
es8374_write(0x07, 0x00);
es8374_write(0x08, 0x21);
es8374_write(0x08, 0x21);
es8374_write(0x09, 0x03); // PLL analog enable, reset ON
delay(10);
es8374_write(0x09, 0x43); // PLL analog enable, reset OFF , dither off, VCO divide by 2
es8374_write(0x0A, 0x49); //3.3V, VCO gain 1, charge pump 4
es8374_write(0x0B, 0x48);
es8374_write(0x0C, 0x00);
es8374_write(0x0D, 0x00);
es8374_write(0x0E, 0x00);
es8374_write(0x0F, 0x00);
es8374_write(0x11, 0x0C); // 0b00001100
//0x12 and 0x13 are for startup delay, not used
es8374_write(0x14, 0x12);
es8374_write(0x15, 0x40);
es8374_write(0x17, 0x10);
es8374_write(0x18, 0x12);
es8374_write(0x1A, 0x00); // mono off
es8374_write(0x1B, 0x00); // lout off
es8374_write(0x1C, 0x88);
es8374_write(0x1D, 0x0B);
es8374_write(0x1E, 0xA7); // last 4 bit is volume, enable Class D
es8374_write(0x1F, 0x0C);
es8374_write(0x20, 0x08);
es8374_write(0x21, 0xC0); // neglect
es8374_write(0x22, 0x00); // neglect
es8374_write(0x36, 0x04);//DAC mute off
es8374_write(0x37, 0x00);
es8374_write(0x38, 0x00);
es8374_write(0x39, 0x00);
}
void setup() {
Serial.begin(115200);
pinMode(CE_PIN, OUTPUT);
digitalWrite(CE_PIN, LOW);
delay(200);
Wire.begin(I2C_SDA, I2C_SCL);
delay(100);
initES8374();
generateSquareWave();
// === I2S Configuration ===
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX),
.sample_rate = 16000,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // stereo
.communication_format = I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = 0,
.dma_buf_count = 8,
.dma_buf_len = 64,
.use_apll = false,
.tx_desc_auto_clear = true,
.fixed_mclk = 0
};
i2s_pin_config_t pin_config = {
.bck_io_num = I2S_BCLK,
.ws_io_num = I2S_LRCK,
.data_out_num = I2S_DOUT,
};
// Start I2S driver
esp_err_t err = i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
if (err != ESP_OK) {
Serial.printf("❌ i2s_driver_install failed: %d\n", err);
while (true)
;
}
err = i2s_set_pin(I2S_NUM_0, &pin_config);
if (err != ESP_OK) {
Serial.printf("❌ i2s_set_pin failed: %d\n", err);
while (true)
;
}
}
void loop() {
int16_t test_buf[64];
static bool toggle = false;
for (int i = 0; i < 64; i += 2) {
test_buf[i] = toggle ? 10000 : -10000;
test_buf[i + 1] = toggle ? -10000 : 10000;
}
toggle = !toggle;
size_t written;
i2s_write(I2S_NUM_0, test_buf, sizeof(test_buf), &written, portMAX_DELAY);
}
Regards,