Read from I2S without blocking call

Lateralus
Posts: 5
Joined: Fri Mar 22, 2019 8:51 am

Read from I2S without blocking call

Postby Lateralus » Fri Mar 22, 2019 9:04 am

There are various examples how to read from an I2S microphone. eg: https://github.com/maspetsberger/esp32-i2s-mems

However, they all are using i2s_read() https://docs.espressif.com/projects/esp ... TickType_t which works perfectly fine but always blocks until the specified byte size has been read.
This is ok if you want to read a block of samples just for testing purpose, but for a real device I would expect to kick of the reading and would expect to get a call to an ISR everytime a block of samples has been transferred by the DMA.

Any idea how to achieve this?
What we have right now is a DMA that moves data from i2s peripheral to memory, but it blocks my operation in the main-loop.
I would expect the DMA not to blook my main loop.

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

Re: Read from I2S without blocking call

Postby ESP_Sprite » Mon Mar 25, 2019 3:58 am

You'd normally use a dedicated thread for reading the I2S peripheral, which then does whatever needs doing with the output data. You'd run other responsibilities in other tasks.

Lateralus
Posts: 5
Joined: Fri Mar 22, 2019 8:51 am

Re: Read from I2S without blocking call

Postby Lateralus » Mon Mar 25, 2019 1:44 pm

Assuming i2s_read() is on thread A and the output via http is on thread B.
Both threads do not run at the same time, but only consecutively.
So you still und up with thread B not running because it needs to wait for the blocking call of i2s_read() in thread A to complete.

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

Re: Read from I2S without blocking call

Postby ESP_Sprite » Wed Mar 27, 2019 2:28 am

Well, first of all you can run the two threads in parallel, as you have two cores. Moreover, thread B can use some kind of signalling to indicate that it does not yet have any data buffered, allowing thread A to return immediately.

Lateralus
Posts: 5
Joined: Fri Mar 22, 2019 8:51 am

Re: Read from I2S without blocking call

Postby Lateralus » Sun Mar 31, 2019 10:16 am

Thank you very much, I was not aware I can choose the core my task is running at.
This solves all my questions :D

Who is online

Users browsing this forum: No registered users and 104 guests