hideakitai / ESP32DMASPI

SPI library for ESP32 which use DMA buffer to send/receive transactions
MIT License
170 stars 36 forks source link

Capture I2S channel 1 via SPI Slave DMA #11

Closed JBSchueler closed 2 years ago

JBSchueler commented 2 years ago

Hi , ESP32 has only 2 I2S units but I need one moreas input channel 1 of an I2S stream. This should be doable via an SPI unit by connecting :

I2S Master SPI Slave ESP32 Pin
SCLK CLK 26
LRCLK SPI CS 25
DO MOSI 22

I2S is a 8000Hz/16bit/Stereo. This will result in 2 bytes every 125uS.

I use the example file slave_simple_task.ino

snd_spi.begin(  HSPI, 26, -1, 22, 25);  // default SPI is HSPI

For test I generate via another ESP32 a stereo waveform on I2S. I connect this to the ESP32 test device (see connection table)

What I get is only zeros on my screen. I am aware it can not keep up on terminal with the i2s stream, but that shoul not be a problem I guess... If I initialize the buffer with e.g. 0x55 ('U') than this is printed on the screen, not the expected incomming values. If I remove printing the buffer and replace it with printing the (received) size it only print '1' and sometimes '0'. This makes me confused because it should at least capture 2 bytes I would say.

If the buffer size is set to e.g. 32, why does the function slave.size only returns 0 or 1 byte? What can be the reason why the buffer is not filled wit the received data?

JBSchueler commented 2 years ago

I use this code to generate a 8kHz sinus on I2S. ESP32_I2S_master_simple.zip

This cod is the receiver for SPI. slave_simple_task_test.zip

What I like to try is to capture only 1 channel (left) out of the I2S stream. I am aware that I2S is 1 bit shifted compared to PCM. Losing LSbit by shifting the data is not an issue for me.

So, is it possible to capture 1 channel out of the I2S stream via SPI or not?

JBSchueler commented 2 years ago

T0 is an ouput that is HIGH when slave.wait(spi_slave_rx_buf, BUFFER_SIZE); is busy. The image shows the function returns after CS is HIGH.

image

What I would like is to capture an amount of bytes before this function return.

JBSchueler commented 2 years ago

Another question, related to this topic... Must receiving be multiples of 4 bytes? Reading Restrictions and Known Issues it states the receive in DMA must be multiples of 4 bytes.