Skip to content

Commit 898861b

Browse files
authored
ES8311 Init Fix
ES8311 Init Fix - works all the time now, instead of 50% working perfectly and 50% being garbage.
2 parents daa8103 + 598e9aa commit 898861b

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

usermods/audioreactive/audio_source.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,12 @@ class ES8311Source : public I2SSource {
679679
//
680680
// Currently only tested with the ESP32-P4 boards with the onboard mic.
681681
// Datasheet with I2C commands: https://dl.xkwy2018.com/downloads/RK3588/01_Official%20Release/04_Product%20Line%20Branch_NVR/02_Key%20Device%20Specifications/ES8311%20DS.pdf
682+
// If making changes, make sure to completely power off the board - sometimes settings are kept until the board is powered off!
682683
//
683684
_es8311I2cBegin();
684685
_es8311I2cWrite(0x00, 0b00011111); // RESET, default value
685686
_es8311I2cWrite(0x45, 0b00000000); // GP, default value
686-
_es8311I2cWrite(0x01, 0b00111010); // CLOCK MANAGER was 0b00110000 trying 0b00111010 (MCLK enable?)
687+
_es8311I2cWrite(0x01, 0b00111010); // CLOCK MANAGER (MCLK enable?)
687688

688689
_es8311I2cWrite(0x02, 0b00000000); // 22050hz calculated
689690
_es8311I2cWrite(0x05, 0b00000000); // 22050hz calculated
@@ -693,23 +694,23 @@ class ES8311Source : public I2SSource {
693694
_es8311I2cWrite(0x08, 0b11111111); // 22050hz calculated
694695
_es8311I2cWrite(0x06, 0b11100011); // 22050hz calculated
695696

696-
_es8311I2cWrite(0x16, 0b00100100); // ADC was 0b00000011 trying 0b00100100 was good
697+
_es8311I2cWrite(0x16, 0b00100100); // ADC synchronize filter counter with "standard" LRCK and ADC RAM clear when lrck/adc_mclk active
697698
_es8311I2cWrite(0x0B, 0b00000000); // SYSTEM at default
698-
_es8311I2cWrite(0x0C, 0b00100000); // SYSTEM was 0b00001111 trying 0b00100000
699-
_es8311I2cWrite(0x10, 0b00010011); // SYSTEM was 0b00011111 trying 0b00010011
700-
_es8311I2cWrite(0x11, 0b01111100); // SYSTEM was 0b01111111 trying 0b01111100
701-
_es8311I2cWrite(0x00, 0b11000000); // *** RESET (again - seems important?)
702-
_es8311I2cWrite(0x01, 0b00111010); // *** CLOCK MANAGER was 0b00111111 trying 0b00111010 (again?? seems important)
703-
_es8311I2cWrite(0x14, 0b00010000); // *** SYSTEM was 0b00011010 trying 0b00010000 (PGA gain)
704-
_es8311I2cWrite(0x0A, 0b00001000); // *** SDP OUT, was 0b00001100 trying 0b00001000 (I2S 32-bit)
705-
_es8311I2cWrite(0x0E, 0b00000010); // *** SYSTEM was 0b00000010 trying 0b00000010
706-
_es8311I2cWrite(0x0F, 0b01000100); // SYSTEM was 0b01000100
707-
_es8311I2cWrite(0x15, 0b00010000); // ADC soft ramp (disabled 0000xxxx)
708-
_es8311I2cWrite(0x1B, 0b00000101); // ADC soft-mute was 0b00000101
709-
_es8311I2cWrite(0x1C, 0b01100101); // ADC EQ and offset freeze at 0b01100101 (bad at 0b00101100)
710-
_es8311I2cWrite(0x17, 0b10111111); // ADC volume was 0b11111111 trying ADC volume 0b10111111 = 0db (maxgain)
711-
_es8311I2cWrite(0x18, 0b10000001); // ADC ALC enabled and AutoMute disabled.
712-
// _es8311I2cWrite(0x19, 0b11110100); // ADC ALC max and min - not sure how best to use this, default seems fine
699+
_es8311I2cWrite(0x0C, 0b00100000); // SYSTEM power up things
700+
_es8311I2cWrite(0x10, 0b00010011); // SYSTEM internal things
701+
_es8311I2cWrite(0x11, 0b01111100); // *** SYSTEM undocumented bits, seems to be important
702+
_es8311I2cWrite(0x01, 0b00111010); // *** CLOCK MANAGER
703+
_es8311I2cWrite(0x14, 0b00010000); // *** SYSTEM PGA gain
704+
_es8311I2cWrite(0x0A, 0b00001000); // *** SDP OUT = I2S 32-bit
705+
_es8311I2cWrite(0x0E, 0b00000010); // *** SYSTEM undocumented bits, seems to be important
706+
_es8311I2cWrite(0x0F, 0b01000100); // SYSTEM enable LPPGA and LPDACVRP in low power mode. No idea.
707+
_es8311I2cWrite(0x15, 0b00010000); // ADC soft ramp
708+
_es8311I2cWrite(0x1B, 0b00000101); // ADC soft-mute enabled
709+
_es8311I2cWrite(0x1C, 0b11100101); // ADC dynamic HPF enabled
710+
_es8311I2cWrite(0x17, 0b10111111); // ADC volume = 0db (max gain)
711+
_es8311I2cWrite(0x18, 0b11001000); // ADC ALC enabled and AutoMute enabled
712+
_es8311I2cWrite(0x19, 0b11110000); // ADC ALC max (-6dB) and min (-30dB)
713+
_es8311I2cWrite(0x00, 0b10000000); // *** RESET (This is very required! Thanks to ESPHome for the hint!)
713714
}
714715

715716
public:

0 commit comments

Comments
 (0)