Page 1 of 1

I2S driven DMA DAC

Posted: Wed Jun 14, 2023 3:07 pm
by wmattias
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 803 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 803 times
Note: Using Stable 5.0.2 release. Have tried various frequencies and options.

Re: I2S driven DMA DAC

Posted: Thu Jun 15, 2023 1:49 am
by ESP_Sprite
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);