I2S driven DMA DAC

wmattias
Posts: 4
Joined: Wed Jun 14, 2023 2:57 pm

I2S driven DMA DAC

Postby wmattias » Wed Jun 14, 2023 3:07 pm

I’m having some issues with the DAC output when driving it using I2S DMA. Wondering if this is a known issue or if anyone has encountered it before and solved it.


When driving the DAC using I2S DMA, there seems to be some bit error on even/odd LSBs. See picture below.
IMG_2800.jpeg
I2S DMA DAC Output
IMG_2800.jpeg (1.3 MiB) Viewed 797 times

Driving it by repeatedly calling dac_output_voltage with the same waveform data produces a correct output though.
IMG_2799.jpeg
Bit Banging (dac_output_voltage) DAC Output
IMG_2799.jpeg (1.1 MiB) Viewed 797 times
Note: Using Stable 5.0.2 release. Have tried various frequencies and options.

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

Re: I2S driven DMA DAC

Postby ESP_Sprite » Thu Jun 15, 2023 1:49 am

You're probably feeding the data in the wrong way. The DAC takes 16-bit samples packed in 32-bit words, but in mono mode, it'll take the upper 16-bit of a word first, then the lower 16-bit word. The ESP32 is little-endian, though, so you'll need to do some flipping. Pseudo-code to get what you probably want:

Code: Select all

uint16_t buf_to_send[256];
for (int x=0; x<256; x++) {
	//this fills elements in sequence 1,0,3,2,5,4,...
	buf_to_send[x^1]=x;
}
i2s_send(buf_to_send);

Who is online

Users browsing this forum: Baidu [Spider], Majestic-12 [Bot] and 85 guests