I2S on ESP32 - How to read all DMA buffer

Hello!

My code has to make a single sample from an external ADC converter.
Sampling starts with an external interrupt and ends with another external interrupt.
The time between the two interrupts is less than the sampling time, guaranteed by using a large enough DMA buffer.

When I use:

while (  pseudo test to end read ) {
  bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY);
  Serial.println(sample);  // only test
}
  1. How does it work? Is the DMA buffer address incremented with each read?
  2. How can I know how many samples have been read?
  3. Using 4 (example) DMA buffers, is the total reading of the 4 buffers sequential, that is, is it enough to read 4 x num bytes from each buffer sequentially?

Thanks a lot!

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/i2s.html

Good luck.

Thanks Idahowalker!

I already had this documentation exhaustively, but it is very unspecific.
After many days, with tests and tests, we found the answers.
I will leave them here. It might help other people.

  1. How does it work? Is the DMA buffer address incremented with each read?
    YES
  2. How can I know how many samples have been read?
    We did'n't find a pretty solution. In our case, we use time
  3. Using 4 (example) DMA buffers, is the total reading of the 4 buffers sequential, that is, is it enough to read 4 x num bytes from each buffer sequentially?
    YES

The code:

  // when stop interrupt occurs
  err = i2s_stop(I2S_NUM_0);    // After stopping, samples are available in DMA buffers
  for ( int i=0; i<num_samples; i++) {
    // bytes_read return number of bytes (16 bits=2,  32 bits=4 )
    bytes_read = i2s_pop_sample(I2S_PORT, (char *)&sample, portMAX_DELAY); // no timeout
  }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.