Understanding I2S for simultaneous read/write in AudioControlSGTL5000

harrolee

Member
Hi!

I want to understand how the Audio Library uses a single I2S bus for simultaneous read/write. I did not think that I2S could provide simultaneous two-way communication.
I think the answer lies in the AudioControlSGTL5000 class but I am not sure where. If I am looking in the wrong place entirely, please let me know!

In playing with the PassThroughStereo.ino example in the Audio Library, I noticed something interesting. If I comment out the code that enables the instance of AudioControlSGTL5000, input from line-in has no trouble passing through line-out. Is that the result of line 584 from control_sgtl5000.cpp?

Thank you!
 
I want to understand how the Audio Library uses a single I2S bus for simultaneous read/write. I did not think that I2S could provide simultaneous two-way communication.


Could it be that you confuse I2S with I2C?

I2C has one line for both directions. But I2S is very different from I2C RE: use, clock & data lines and speed, and I2S is for data only - no communication like register settings etc.

I think the answer lies in the AudioControlSGTL5000 class but I am not sure where.
No, that just SGTL CHip Configuration.

Simultaneous read/write is not a special feature. Sure, most chips do either RX or TX - but that doesn't mean it's uncommon.

For questions RE. settings, the you'll find the best answers by studying the SGTL-5000 datasheet and Teensy processor reference manual.
 
There is also not much to configure with I2S. It is also not a BUS with several participants. There is always a "master" that provides the clocks.
On all Teensys the audio library is configured so that the Teensy is the master. On the LC you should choose the slave mode. Peripheral chips must be "slave" accordingly (and on the LC best master - the SGTL can be configured accordingly by API calls).
This is the most important, other settings concern only the datailed data format.
 
Thank you for your answer! This is going to sound sarcastic, but I mean this genuinely:

Until I read this, I did not know that I2C was used to set register settings: "no communication like register settings etc."
I also didn't grasp that register settings are the primary method for programming chips.
With those details in mind, the SGTL5000 datasheet was converted from an impenetrable abstract document to literally the coolest thing in the world.

I was confused about simultaneous r/w because the MicroPython implementation of I2S does not support simultaneous two-way communication. Seeing that the Teensy Audio Library accomplishes simultaneous two-way communication, I thought that maybe there was some special workaround at play in the Audio Library. Given the datasheet and your answer, now I understand that simultaneous read/write is a feature of the SGTL5000, and apparently many other chips. So if I want to use MicroPython for DSP, I will need to work with their I2S class and write register settings to the SGTL5000 to make it do what I want... luckily, those settings can probably be found in Paul's code :D
 
You can have so much more than just bidirectional stereo. Many simultaneous channels are possible. If you use the design tool, you can create designs with multiple inputs and outputs. It knows which hardware resources each uses, so you will see yellow error triangles if you use 2 or more which conflict.
 
Also, the SGTL5000 is only one of many codecs with an I2S interface - there are many out there, ranging from inexpensive to co$tly.
Thanks to a wide array of sound-enabled consumer products, most are either directly compatible, or require very little to be compatible with the Teensy audio library.

Case in point, although I now have the rather nice Teensy Guitar Audio Shield MKII, my favorite guitar toy is a converted Line 6 TonePort UX1 sporting an internal Teensy 4.0, hooked up directly to the I2S lines thanks to conveniently disposed test points. It has an AK4528 codec hardwired for I2S 24bits 44.1khz, thus it doesn't even need I2C - I had to use a GPIO pin to physically reset the codec at startup, but that's it, no code change to the audio library

Marc
 
Back
Top