I2S to Internal DAC is Broken

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

I2S to Internal DAC is Broken

Postby cooperbaker » Tue Feb 18, 2020 7:31 am

Esp-idf internal dac audio examples produce no audio.

The output signal is "silence" hovering at about +80mV

Another user reports the same behavior in this post.

Included below is a separate bare-bones example that should produce audio clicks.

Please prove me wrong.

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 ) );

    // make spikes
    outBuf[ 0 ] = 255;
    outBuf[ 1 ] = 255;
    outBuf[ 2 ] = 255;
    outBuf[ 3 ] = 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: I2S to Internal DAC is Broken

Postby ericwhite » Wed Feb 19, 2020 1:51 am

Yep, I'm having the same issue.

Thanks for creating this complete example to reproduce the problem.

One thing I noticed in your code is that use_apll is set true. However, I keep reading that it won't take effect unless one also sets fixed_mclk. I don't believe it's the source of the problem, but maybe looking into it helps with something.

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

Re: I2S to Internal DAC is Broken

Postby cooperbaker » Fri Feb 21, 2020 9:03 pm

One thing I noticed in your code is that use_apll is set true.

Yes, good eye. Unfortunately it changes nothing. I tried all permutations of apll/mclk true/false and never saw a signal from the dac.

dlizotte
Posts: 1
Joined: Sat Feb 22, 2020 4:03 am

Re: I2S to Internal DAC is Broken

Postby dlizotte » Sat Feb 22, 2020 4:06 am

Thanks for posting this; I am having the exact same problem. Suggest opening an issue on github?

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

Re: I2S to Internal DAC is Broken

Postby ESP_houwenxiang » Sun Feb 23, 2020 12:06 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 (will be OK soon). It can work on release 3.3.

thanks !!
wookooho

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

Re: I2S to Internal DAC is Broken

Postby cooperbaker » Sun Mar 01, 2020 1:46 am

ESP_houwenxiang wrote:
Sun Feb 23, 2020 12:06 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 (will be OK soon). It can work on release 3.3.

thanks !!

Ok, thanks. Glad I'm not going crazy...

Any idea how soon it will be working again?

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

Re: I2S to Internal DAC is Broken

Postby ericwhite » Sun Mar 01, 2020 12:54 pm

Thanks @ESP_houwenxiang. Just knowing that helps a lot with my planning.

And to help everyone else, I can confirm that I did indeed get DMA to DAC working with version 3.3.1 IDF. Actually the example i2s_adc_dac completely works with 3.3.1.

heinzv
Posts: 7
Joined: Fri Sep 20, 2019 7:22 pm

Re: I2S to Internal DAC is Broken

Postby heinzv » Wed Mar 04, 2020 5:06 pm

will the 3.3.x API also been available for Arduino Studio and when can we expect it?
I also have this issue and I'm working with Arduino Studio.

boborjan
Posts: 9
Joined: Thu Sep 19, 2019 5:46 pm

Re: I2S to Internal DAC is Broken

Postby boborjan » Fri May 22, 2020 5:06 pm

Could you tell then which git tag or commit we shall use? Or is it already solved since?

Thx,
Viktor

kbreining
Posts: 3
Joined: Thu May 21, 2020 1:16 pm

Re: I2S to Internal DAC is Broken

Postby kbreining » Mon Nov 23, 2020 6:57 pm

Hi,
I used the released 4.1 and it still didn't work.
Then I downloaded the master - now it works!

However: as the DAC can only output positive values, the negative values are mirrored around the 3.3V/2.
I tried to set the register SENS.sar_dac_ctrl2.dac_invX to 2 (invert MSB) to move the signal by VDD/2, but this didn't work.
I tried to set the register SENS.sar_dac_ctrl2.dac_dcX to 0x7f to achieve the same, but this also didn't work.

So I added in the A2DP-SINK demo code in write_ringbuf() the lines
for (int i = 0; i < size; i++)
((uint8_t *)data) += 0x7f;

Now it works. This solution is a botch, but it's what I got to run. Seems there has to be done more investigation in the ESP_IDF framework...
Regards
Klaus

Who is online

Users browsing this forum: ccrause and 227 guests