ESP32 as I2S input-device

Status
Not open for further replies.
Its exactly the same here.

Example 4 and 6:
No reaction at the plotter.
Screenshot 2021-09-17 135658.jpg

Example 5:
only a few right looking samples.
example5.jpg
 
I forgot to adapt the bit clock divider for example5. But I just fixed that and chances are good that it works now.
Example 4: If the plotter shows something, then at least the isr of SAI2 is called, which is good. It is strange if the plotter shows something even if the clock lines are disconnected.
Example 5: The Teensy is again master with its internal clock. If this example is working, then we know that the hardware is connected correctly.
Example 6: The final goal. SAI2 is in slave mode. Any audio block that is clocked by the internal PLL like SAI1 in master mode or the spdif output could be added. In the example I added the spdif output, but you can replace it with SAI1. But let's first focus on example 4. It should be easier to debug and if it is working, example 6 should also work.
 
Example 4:

Still nothing on the Plotter...
Bild_2021-09-17_151616.jpg

I also dont have an oszilloscope on hand right now.
Do you think it would be good to look at the signals?
if so i will organize one for monday.
 
I should have explained my commit more clearly: It only changed the behavior of example 5, where the Teensy is master. I hope that it works now.
I would like to first get example 5 running (smallest risk of failing), then example 4 and then example 6 (most complex).

Regarding the oszilloscope: I probably messed up the SAI2 configuration, but it would help if you can check the clock lines, so that we can be sure that it is a problem of the configuration and not of the hardware.
 
I just downloaded your latest updates and ran it. Example 5 still runs but the waveform is broken still. Disconnecting the clocks causes the plotter to stop.

I went back and retested 4 and 6... I thought the plotter was counting with the clocks but I may have been wrong. I'm not getting anything out of it now.

Quick question: How many variations of the ESP32 code are there really? Is it just master or slave? I don't see any other differences at first glance.
 
Example 5 still has the same broken waveform on my setup too.

In the current version (examples1-6) all configurations should be the same, except the MODE_Master/SLAVE.

Regarding the oszilloscope
I will make few screenshots of the Interface lines, with all examples1-6 or other/newer on monday.
 
Ok I might found something: At SAI2 the receiver needs to run in sync with the transmitter (at SAI1 its the other way around). I configured the receiver bit clock for 16bit, but it uses the bit clock of the transmitter anyway and my change had no effect. Now I also adapted the transmitter for 16bit samples in master and in slave mode. Can somebody of you please test if the examples work now?
 
I tried example 5 and it still didnt got any data on the plotter.
Also i had to copy everything to the same folder, because it woldn't compile. I think this has something to do with the Arduino ide.
 
I downloaded your latest files and applied them to example 5. I get a broken waveform but it seems like maybe a bit larger of a broken waveform. Disconnecting the clock lines; the clock continues to count. Teensy is in Master, so I guess this makes sense.

I wonder if we should/could have two plotters. One for SAI1 and one for SAI2.

Screenshot 2021-09-17 213107.png

When debugging my ADC3140 module I remember that there was a "shift" that had to take place. I believe I had to put 16 bits in the front of the signal, plus 16 bits of audio at the end. Please don't quote me, I looked at the code and I have it shifting 1 "slot" which I believe was 16 bits. I wonder if this waveform shows that there is silence where it expects audio...
 
I don't know what you planned to test, but you can connect up to 8 channels to the plotter.
Regarding the shifting the bits: The input works for at SAI1 and I just used the same configuration at SAI2. So I don't think that it has something to do with shifting bits.

The strange thing is: I have a working example at which SAI2 runs in slave mode (with TDM8 instead of i2S and 32bit) and we have a working example with SAI1 in slave mode (I2S and 16bit). But the combination SAI2 + I2S +16bit (master or slave) ist that difficult to get working?

I had an idea how I could use my Teensy/ESP32 to test my examples without spending too much effort on changing my hardware. Maybe I'll find some time tomorrow to test that.
 
I just saw that yesterday I reset the bit clock divider back to the value for 32bit samples. I fixed that (again).
Can you please give it a last try. Tomorrow I'll be back home and if my fix is not working, I'll do the next test runs on my hardware without bothering you.
 
Example 5 works now.
There are still inserted zeros, but this should be no problem if the ESP is master.
InkedScreenshot 2021-09-18 122217_LI.jpg

I haven't tested the other examples jet.
I' happy to be bothered, to find a solution so feel free to bother me:D
 

Attachments

  • Bild_2021-09-18_122453.jpg
    Bild_2021-09-18_122453.jpg
    78.3 KB · Views: 51
Nice, we expected of course some distortion. Have you also tried examples 4 and 6 yet? Maybe they already work.
 
Example 5:

I wrote a python-script (available here https://github.com/NoMedia-py/TeensySerialSamplesToCSV) that records samples of the output of your examples and saves it to a csv file which can be opened and plotted with Microsoft Excel or other programms.

I tested a example with an 500Hz sine wave and noticed that sometimes the waveform is cut off:
SpikeOutput1.png
SpikeOutput4.png
SpikeOutput3.png

Could it be that an buffer overflow occurs somewhere?
 
Have you also tried examples 4 and 6 yet?

Example 4 and 6 are working!
I have jet to analyze the waveform, but so far it looked promising.

EDIT:
Example 6 only works with the left channel. Right channel has no data.

Both example still have inserted zeros and are clipping. I can not guarantee that the my python code causes the clipping, but I can say that it dont inserts the zeros.
Example6.png
Example63.png
 
Last edited:
At example 6 only one channel of the input is connected to the plotter. That's the reason for the missing data.

I'll try to reproduce the other problem.
 
I just tested example 4 and 6. They both worked here. Here is the result of example 6:
signal6.jpg
At example 6 you can ignore the 'glitches' within the first few seconds. They occure since the incoming sample rate is not exactly known at the beginning, but they are not audible. At least I never noticed them when I listen over my speakers.
 
That does indeed makes sense. Now i get Right and left channel data.

But how do we get this data to the audio shield now?
I didnt had much hope that it would be that easy to just set outputI2S and connect the audioshield, but i tried it anyways. It didnt work.
 
I have no experience with the audioshield, but you could search or make an example at which a sine wave is generated on the Teensy and send to the audioshield. If that works, you can replace the sine wave generator with the SAI2 input at which the ESP32 is connected.
You probably already know that, but from example 6 code, you only need 5 lines:
Code:
#include "input_i2s2_16bit.h"
#include "async_input.h"

...

AsyncAudioInput<AsyncAudioInputI2S2_16bitslave> i2sSlaveInput;
AudioConnection          patchCord1(i2sSlaveInput, 0, XXX, 0);
AudioConnection          patchCord2(i2sSlaveInput, 1, XXX, 1);
You don't need the spdif-output of the example.
 
The connection between the teensy and the audioshield is no problem thanks to the audiolibrary. I tried exacly that using the OutputI2S instead of the spdif output. The only hope is that i connected the audioshield wrong. If thats not the case, i think both modes are not working correctly together.?
 
I don't see a reason why SAI1 in master mode and SAI2 in slave mode wouldn't work together. I use them together the other way around: SAI2 in master mode and SAI1 in slave mode and it works.
 
Thanks alex6679. I should have time to test this later today.

If the initial test goes well, I'll also be attempting to run SAI1 in TDM mode and SAI2 in standard stereo I2S mode. Do you think that's going to work? Or will SAI2 have to run TDM as well? I heard you may have an example for ESP32 in TDM mode too?
 
Update:
I took a look with the oszilloscope.
SAI1 outputs what you would expect: 2,8 MHz BCLCK, 11MHz MCLK, data in 32 falling BLCK edges in one cycle of LRCLK and the last 16 bit always zeros.

Turns out I somehow killed my audioshield.
 
Last edited:
Status
Not open for further replies.
Back
Top