Internal DAC audio output - Please Help - no luck with idf examples or guide

User avatar
cooperbaker
Posts: 10
Joined: Fri Jan 18, 2019 6:39 am

Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby cooperbaker » Mon Jan 27, 2020 10:30 pm

Hi.

I'm trying to get some audio out of the esp32 onboard dacs. I'm using a wrover, and have also tried wroom boards, but nothing I try sends audio through the internal dacs. There is no output at all on any board.

I have tried all examples in esp-idf that demonstrate internal adc/dac for audio. They do not work.
I have tried the internal dac i2s config settings from the idf programming guide but no luck.

Please help. I am baffled. Unfortunately esp-adf is not an option.

A simple code example is included below:

Code: Select all

#include "driver/i2s.h"
#include "esp_err.h"

void app_main( void )
{
    // configure i2s for internal dac
    static const i2s_config_t i2s_config =
    {
        .mode                   = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN,
        .sample_rate            = 48000,
        .bits_per_sample        = 16,
        .channel_format         = I2S_CHANNEL_FMT_RIGHT_LEFT,
        .communication_format   = I2S_COMM_FORMAT_I2S_MSB,
        .intr_alloc_flags       = ESP_INTR_FLAG_LEVEL1,
        .dma_buf_count          = 8,
        .dma_buf_len            = 64,
        .use_apll               = true
    };

    // install i2s driver
    ESP_ERROR_CHECK( i2s_driver_install( I2S_NUM_0, &i2s_config, 0, NULL ) );

    // set pins for internal dac - enable both channels
    ESP_ERROR_CHECK( i2s_set_pin( I2S_NUM_0, NULL ) );

    // enable dac outputs
    ESP_ERROR_CHECK( i2s_set_dac_mode( I2S_DAC_CHANNEL_BOTH_EN ) );

    // I2S log results:
    //-----------------
    // I (325) I2S: DMA Malloc info, datalen=blocksize=256, dma_buf_count=8
    // I (345) I2S: APLL: Req RATE: 48000, real rate: 23999.980, BITS: 16, CLKM: 1, BCK_M: 8, MCLK: 6143995.000, SCLK: 767999.375000, diva: 1, divb: 0



    // memory for i2s write:
    //----------------------
    // 64 samples = 128 bytes at 16bit
    // 8 buffers  = 1024 bytes (  128 x 8 )
    // 2 channels = 2048 bytes ( 1024 x 2 )
    int outBytes  = 2048;

    // allocate output buffer memory
    uint8_t* outBuf = ( uint8_t* )calloc( outBytes, sizeof( uint8_t ) );

    // fill output buffer with a ramp
    for( int i = 0 ; i < outBytes ; i++ )
    {
        outBuf[ i ] = ( ( float )i / outBytes ) * 255;
    }

    // i2c bytes written variable
    size_t bytesOut;

    // output the buffer
    while( true )
    {
        ESP_ERROR_CHECK( i2s_write( I2S_NUM_0, outBuf, outBytes, &bytesOut, portMAX_DELAY ) );
        // this results in silence; nothing on either pin 25 or 26; nothing on the scope.
        // ESP_ERROR_CHECK reports nothing
    }
}



ericwhite
Posts: 4
Joined: Sat Feb 01, 2020 5:56 pm

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby ericwhite » Sat Feb 01, 2020 11:39 pm

I seem to be having the same problem. I only started with ESP32 this month and I got the latest esp-idf from GitHub.

Board: Adafruit HUZZAH32 – ESP32 Feather Board
ESP-IDF: "latest" v3.3.1

I've been able to make many other things work from the examples including producing a sine wave from the DAC with dac_output_voltage. However, using I2S to DAC is not working. In fact everything I've tried has worked except I2S_MODE_DAC_BUILT_IN.

With the IDF example i2s_adc_dac, I'm able to see that the ADC is reading samples to I2S with the I2S_MODE_ADC_BUILT_IN setting. But I get no voltage change out from the DAC via the I2S_MODE_DAC_BUILT_IN setting.

@cooperbaker I wonder if you would try writing to your DAC without I2S to verify your DAC is working and that we have the same results? I think there is an example "wave_gen" that I used.

I see there are people on forums that were using I2S to DAC with I2S_MODE_DAC_BUILT_IN setting in 2019. I don't want to jump to a conclusion that it somehow broke in IDF recently, but perhaps this is the case.

User avatar
cooperbaker
Posts: 10
Joined: Fri Jan 18, 2019 6:39 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby cooperbaker » Mon Feb 03, 2020 4:19 pm

@cooperbaker I wonder if you would try writing to your DAC without I2S to verify your DAC is working and that we have the same results? I think there is an example "wave_gen" that I used.

Yes. The DACs on the boards I have are indeed working without i2s. I can write values at will and they appear as expected on the scope...

ericwhite
Posts: 4
Joined: Sat Feb 01, 2020 5:56 pm

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby ericwhite » Tue Feb 18, 2020 12:34 pm

Ok, thanks. What version of ESP-IDF were you using?

I have tried ESP-IDF: "latest" v3.3.1

I made an attempt to downgrade to an older version but that somehow caused some issues and didn't compile on OSX. I'm sure it can be downgraded, but it got so tangled that I ran out of time.

User avatar
cooperbaker
Posts: 10
Joined: Fri Jan 18, 2019 6:39 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby cooperbaker » Tue Feb 18, 2020 11:56 pm

ericwhite wrote:
Tue Feb 18, 2020 12:34 pm
Ok, thanks. What version of ESP-IDF were you using?

I pulled the latest 4.x version.

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby ESP_houwenxiang » Sun Feb 23, 2020 12:05 pm

Hi,
The I2S DAC in the master branch is currently not working. We have refactored the driver and have not merged into the master branch. It can work on release 3.3.
wookooho

ESP_houwenxiang
Posts: 118
Joined: Tue Jun 26, 2018 3:09 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby ESP_houwenxiang » Wed Apr 15, 2020 2:56 am

Hi, please try the master branch.
wookooho

ducalex
Posts: 1
Joined: Wed Jan 27, 2021 7:05 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby ducalex » Wed Jan 27, 2021 6:01 pm

I think the fix never made its way to 4.1 and 4.2 because it's back to not working with the exact same symptoms. Is this an oversight or am I seeing a different bug?

Thanks

User avatar
cooperbaker
Posts: 10
Joined: Fri Jan 18, 2019 6:39 am

Re: Internal DAC audio output - Please Help - no luck with idf examples or guide

Postby cooperbaker » Fri Jan 29, 2021 8:03 pm

FWIW, it works with esp32 arduino...

Who is online

Users browsing this forum: No registered users and 318 guests