DMA and DAC

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

DMA and DAC

Postby fly135 » Thu Oct 18, 2018 3:47 pm

I am seeing a need to send audio data out the ESP32 DAC. I searched this forum for the DMA and DAC but didn't get any relevant hits. Anyone have any input on this task?

The docs say this....
The DAC channels can also be driven with DMA-style written sample data, via the I2S driver when using the “built-in DAC mode”.
And this...
I2S output can also be routed directly to the Digital/Analog Converter output channels (GPIO 25 & GPIO 26) to produce analog output directly, rather than via an external I2S codec.
So is this as simple as setting up I2S to send to the DAC pin and let her rip?

John A

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: DMA and DAC

Postby fly135 » Thu Oct 18, 2018 9:00 pm

Short example configuring I2S to use internal DAC for analog output:
So the internal DAC that they are referring to is the one on GPIO25 or 26?
i2s_set_pin(i2s_num, NULL); //for internal DAC, this will enable both of the internal channels
Should I change the NULL to the pin I want? Does NULL send the signal out both 25 and 26. That seems to be what it's saying.

John A

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: DMA and DAC

Postby chegewara » Fri Oct 19, 2018 2:53 am

Internal DAC output is using both pins 25 and 26.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: DMA and DAC

Postby ESP_Sprite » Fri Oct 19, 2018 2:54 am

Yes, the DAC is the one on pin 25/26. If you want an example on how to use it, feel free to refer to esp-idf/examples/peripherals/i2s_adc_dac/ .

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: DMA and DAC

Postby fly135 » Fri Oct 19, 2018 3:23 pm

So using I2S to write to the DAC uses up both DACs and outputs the same (or R/L) data to both GPIOs? That means if I use GPIO26 that GPIO25 is no longer available? Or are we assuming stereo audio?

This is going to be mono audio. I was hoping that calling "i2s_set_pin(i2s_num, GPIO_NUM_26)" would allow use of only one GPIO with mono audio.

John A

chegewara
Posts: 2207
Joined: Wed Jun 14, 2017 9:00 pm

Re: DMA and DAC

Postby chegewara » Fri Oct 19, 2018 8:13 pm

https://docs.espressif.com/projects/esp ... l#overview
ESP32 has two 8-bit DAC (digital to analog converter) channels, connected to GPIO25 (Channel 1) and GPIO26 (Channel 2).
https://docs.espressif.com/projects/esp ... on-example

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: DMA and DAC

Postby ESP_Sprite » Sat Oct 20, 2018 7:24 am

You should be able to re-purpose one of the DAC GPIOs for something else. For instance, this only uses DAC2:

Code: Select all

        i2s_config_t cfg={
                .mode=I2S_MODE_DAC_BUILT_IN|I2S_MODE_TX|I2S_MODE_MASTER,
                .sample_rate=rate,
                .bits_per_sample=16,
                .channel_format=I2S_CHANNEL_FMT_RIGHT_LEFT,
                .communication_format=I2S_COMM_FORMAT_I2S_MSB,
                .intr_alloc_flags=0,
                .dma_buf_count=4,
                .dma_buf_len=buffsize/4
        };
        i2s_driver_install(0, &cfg, 4, &soundQueue);
        i2s_set_pin(0, NULL);
        i2s_set_dac_mode(I2S_DAC_CHANNEL_LEFT_EN);
        i2s_set_sample_rates(0, cfg.sample_rate);
        //I2S enables *both* DAC channels; we only need DAC2. DAC1 is connected to the select button.
        CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_DAC_XPD_FORCE_M);
        CLEAR_PERI_REG_MASK(RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_XPD_DAC_M);
Not sure if the last two lines are still needed, the I2S driver may have taken care of that by itself now.

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: DMA and DAC

Postby fly135 » Mon Oct 22, 2018 3:09 pm

Thanks for the help guys! :)

User avatar
fly135
Posts: 606
Joined: Wed Jan 03, 2018 8:33 pm
Location: Orlando, FL

Re: DMA and DAC

Postby fly135 » Fri Oct 26, 2018 9:18 pm

Seems like I'm running out of options on this. We can only use PDM mics on I2S 0, but we can only use I2S 0 to write to the DAC. I doubt this is possible but can you DMA read PDM on I2S 0 and DMA write to the DAC on I2S 0 at the same time? My default answer on this is no, but I figured I'd ask just to be sure.

John

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: DMA and DAC

Postby ESP_Sprite » Sun Oct 28, 2018 2:17 am

I'd think the hardware is capable of doing this, but I'm not sure if the driver allows for initializing it in such a way.

Who is online

Users browsing this forum: No registered users and 115 guests