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
}
How does it work? Is the DMA buffer address incremented with each read?
How can I know how many samples have been read?
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?
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.
How does it work? Is the DMA buffer address incremented with each read? YES
How can I know how many samples have been read? We did'n't find a pretty solution. In our case, we use time
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
}