I2S driver for ESP32 is not working [IDFGH-5854]

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Thu Sep 16, 2021 8:56 am

No worries. Thank you.

For external ADC, I am using following EVM from TI.
https://www.ti.com/tool/PCM1808EVM

If you want other information please let me know.

L-KAYA
Posts: 22
Joined: Thu Aug 12, 2021 3:44 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby L-KAYA » Sat Sep 18, 2021 8:02 am

Hi shailesh.korat,
I wrote a test example to reproduce the issue you mentioned.
Platform: ESP32-LyraT-mini_V1.2 with ESP32-WROVER-B
Codec: ES8311
Signal Input: Generate sine wave at 2KHz & 5kHz by a signal generator
Sample rate: 48kHz & 96kHz
Stored data format: raw data

Here is the result:
wave2.png
Test results
wave2.png (82.4 KiB) Viewed 11663 times
The data at the top line is at 48kHz sample rate with 2kHz sine input, middle line is at 96kHz sample rate with 2kHz input, bottom line is at 96kHz with 5kHz input. As you can see, I failed to reproduce this issue, maybe I should try another ADC codec.

For the reference and trouble shooting, this is my test project based on the latest master branch (by the way, the master branch on Github has not updated for several days, it should be synchronized sooner or later)
i2s_record.zip
(13.74 KiB) Downloaded 747 times

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Mon Sep 20, 2021 2:22 am

Thank you very much E-KAYA for sending me this details.

Now, let me try with your code. Instead of SD card, I am using flash memory to store output data of I2S.

Just want to clarify one thing is I am working on following commit id from master branch of ESP-IDF.

220590d599e134d7a5e7f1e683cc4550349ffbf8

Find attachment for more details.

I hope we are both on the same page.

Thanks.
Attachments
idf_commit_id.PNG
idf_commit_id.PNG (44.17 KiB) Viewed 11591 times

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Mon Sep 27, 2021 7:53 am

Dear E-KAYA,

I checked with your given code example. Gave the 5khz sine wave to external ADC, and start sample from ESP32 with 48000 freq.
I used ESP32 instead of ESP32-S3 board.
But still I am getting noise output data.
Please check attachment for your reference.

FYI, current setup ADC + ESP32 is working fine and and getting correct output in IDF v4.3.

Let us know what could be the next step to follow to make this work.
Thanks
Attachments
esp32_48k_data.png
esp32_48k_data.png (140.17 KiB) Viewed 11309 times

L-KAYA
Posts: 22
Joined: Thu Aug 12, 2021 3:44 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby L-KAYA » Mon Sep 27, 2021 9:05 am

Few days ago, a fix commit (a287f34f88e78759cf09d2d9018b49adb70ea6fd) for apll clock is updated to the github, you can have a try with both 'apll on' and 'apll off' condition on the latest master branch. If it still not working, I might need your register dump for debugging.

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Fri Oct 01, 2021 10:22 am

Dear L-KAYA,

Thanks for supporting on this issue.

Finally, Something got works for me. Looks bit confusable but I2S working well now.

Here is few questions:

Sampling Freq : 48000, DMA buf len = 64, DMA buf cont = 8 , Read data using I2S_read = 64 *8, ch = 2, Sample bit= 32bit ---> Not working
Sampling Freq : 48000, DMA buf len = 48, DMA buf cont = 8 , Read data using I2S_read = 48 *8, ch = 2, Sample bit= 32bit ---> Working
Sampling Freq : 48000, DMA buf len = 96, DMA buf cont = 8 , Read data using I2S_read = 96 *8, ch = 2, Sample bit= 32bit ---> Working

Sampling Freq : 96000, DMA buf len = 64, DMA buf cont = 8 , Read data using I2S_read = 64 *8, ch = 2, Sample bit= 32bit ---> Not Working
Sampling Freq : 96000, DMA buf len = 96, DMA buf cont = 8 , Read data using I2S_read = 96 *8, ch = 2, Sample bit= 32bit ---> Working

Sampling Freq : 64000, DMA buf len = 64, DMA buf cont = 8 , Read data using I2S_read = 64 *8, ch = 2, Sample bit= 32bit ---> Working
Sampling Freq : 64000, DMA buf len = 96, DMA buf cont = 8 , Read data using I2S_read = 96 *8, ch = 2, Sample bit= 32bit ---> Not Working

Sampling Freq : 32000, DMA buf len = 32, DMA buf cont = 8 , Read data using I2S_read = 32 *8, ch = 2, Sample bit= 32bit ---> Working
Sampling Freq : 32000, DMA buf len = 64, DMA buf cont = 8 , Read data using I2S_read = 64 *8, ch = 2, Sample bit= 32bit ---> Working

In conclusion, The Samples only not missing when I keep DMA buf len in multiple of sampling freq (1 ms period).

Is this right behavior I2S ?

L-KAYA
Posts: 22
Joined: Thu Aug 12, 2021 3:44 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby L-KAYA » Mon Oct 18, 2021 5:56 am

@shailesh.korat
Sorry for the late reply~
Thank you very much for your significant information! After some experiments, I think I find the reason of data clip (in other word, data lost).
Actually, received data buffer length is not really related to the dma_buf_len, but is related to the sample rate. When the sample rate is high (like 48k/96kHz), the receive interrupt will be more frequently. When the receive data buffer length is small, that means the DMA receive speed will be faster than data processing (in i2s_read), so the message queue in I2S is always full, the interrupt handler have to drop the old data in order to input the new data. Therefore, we need to set a bigger receive buffer. In this case, 'i2s_read' will spend more time on receiving data from DMA instead of processing the data, which can avoid DMA exhaust the message queue.

From my experience, when the sample rate is 48k, the receive buffer length should be greater than 1200, and in 96k, it should be greater than 3200.

Hope these information can help~

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Tue Nov 16, 2021 8:19 am

Dear L-KAYA,

Nice to meet you again.

I am having different problem with I2S now.

By giving fix frequency(5k, 10k,15k etc.) sine wave from signal generator, ESP32S3 able to capture data correctly. I can see sine wave in audacity with fix frequency clearly.
Now instead of giving fix frequency as input, I an giving sweep sine wave from 500 Hz to 15 KHz as input with time period of 1 Sec,
If I do same test by just changing fix freq to sweep freq, Data sample is started to miss.

Find attached data file for your reference. You can clearly see missing data sample.

FYI, I have captured the sweep data by probing I2S using the logic analyzer and there is no any missing sample I have seen.

Looking forward to hearing from you soon.

Thanks.
Attachments
sweep_sine_500Hz_to_5Khz_1.png
sweep_sine_500Hz_to_5Khz_1.png (85.16 KiB) Viewed 10584 times
sweep_sine_500Hz_to_5Khz.png
sweep_sine_500Hz_to_5Khz.png (118.29 KiB) Viewed 10584 times

L-KAYA
Posts: 22
Joined: Thu Aug 12, 2021 3:44 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby L-KAYA » Tue Nov 23, 2021 2:23 am

Dear shailesh.korat,

Nice to hear your feedback! Seems you met another data lost problem, I need some time to test this issue, but recently I wrote a specific example for the data drop issue, you can have a try and hope it can help.

The key is to create at least two receive buffers, if one is under processing, the others can still receive the data from isr. In this way, we can lower the time cost in the `i2s_read` loop and improve the efficiency.
i2s_es8311_record_example.zip
(35.44 KiB) Downloaded 386 times
By the way, may I ask did you change the i2s configurations during sampling? If you called `i2s_set_clk` the buffer might be cleared.

Thanks!

shailesh.korat
Posts: 15
Joined: Thu Jul 12, 2018 11:09 am

Re: I2S driver for ESP32 is not working [IDFGH-5854]

Postby shailesh.korat » Tue Nov 23, 2021 6:32 am

Dear L-KAYA,

Thank you for your reply.

I will try your example and let you know the result soon.

Just wanted to say that, In my application, receive buffer size from i2s_read is fixed 1536 bytes(192 samples * 8 bytes per sample = 1536 bytes) with sampling freq of 48000.

Could you explain me how did you count below overtim_tick period?

Code: Select all

uint32_t overtime_tick = ((EXAMPLE_RECV_BUF_SIZE * 1000 * 8) / (EXAMPLE_SAMPLE_RATE * EXAMPLE_I2S_CHAN_NUM * EXAMPLE_SAMPLE_BIT)) / portTICK_RATE_MS;
Thanks.

Who is online

Users browsing this forum: Bing [Bot], MicroController and 165 guests