Need clarification about I2C and the audio shield or other devices as INPUTs

Status
Not open for further replies.

Beavis

Active member
It says at https://www.pjrc.com/teensy/gui/index.html?info=AudioInputI2S that the audio shield uses I2S, but at https://www.pjrc.com/store/teensy3_audio.html the pin usage table for the Audio Adaptor says, "18, 19 (other I2C chips)" I'm assuming this is a typo, but since I've recently noticed that I2S and I2C are distinct (and not just 3 of maybe 1, I, 2, S, 5, or C) I'm forced to ask.

I lost over, "S/PDIF output uses the I2S hardware. This object can not be used together with any of the I2S objects, because it requires the I2S hardware with different internal settings." I've never been able to understand "objects", so here's what gets me: the audio shield is I2S and it has both input and output (objects?), but the digital S/PDIF (I'm assumings is Toslink) is only found in the OUTPUTs. So again, I'm forced to ask, There can't be a S/PDIF input even if it is a I2S chip, because the audio shield (being I2S) has both INs and OUTs ? And is the S/PDIF only for optical, or is there a way I can use coax?

To really make my head spin, I found another device https://www.aliexpress.com/item/Aiy...PDIF-Fiber-Coaxial-USB-Sound/32833080360.html which claims to be I2S, but instead of 4 pins, it only has 3 [DATA, BCK, LRCK] Will this work as an I2S input?

My final goal is to use this board as an input, and then have one Teensy output an optical signal which would be received by optical input on another Teensy and finally have the audio shield drive an analog amplifier.
 
Note, I2S and I2C are completely different things.

I2S is a technology for moving digital audio from one system to another. I2C is a technology to connect multiple small devices that act as slaves to one master device.

On the Teensy 3.2, the following pins are I2S:
  • Pin 9: BCLK
  • Pin 11: MCLK
  • Pin 13: RXD0
  • Pin 15/A1: TXD1
  • Pin 22/A8: TXD0
  • Pin 23/A9: LRCLK
  • Pin 30/A19: RXD1

I don't know much about I2S other than the above. I suspect that TXD1/RXD1 aren't used by the audio shield, only TXD0/RXD0.

The audio shield has some I2C devices that you use to control things within the audio shield. The SGTL5000 is at address 0x0A, and the WM8731 is at address 0x1A. You can hook other I2C devices up to the I2C bus, using pin 18/A4 as SDA0 and pin 19/A5 as SCL0. If you weren't using the audio shield, pins 16 and 17 are alternate SDA0/SCL0.

The 3.2 has a second I2C bus using solder pads 29/30 underneath the Teensy.
 
It says at https://www.pjrc.com/teensy/gui/index.html?info=AudioInputI2S that the audio shield uses I2S, but at https://www.pjrc.com/store/teensy3_audio.html the pin usage table for the Audio Adaptor says, "18, 19 (other I2C chips)" I'm assuming this is a typo

The audio shield uses both I2S and I2C.

I2S is used for the streaming of digital audio data. I2C is used for configuration. This is actually a very common setup for most audio codec chips with configurable parameters, because I2S doesn't provide any way to do configuration of settings, or really anything other than stream audio data.

I've never been able to understand "objects"

These "objects" are the pieces of software from the audio library. The idea behind an "object" is you can easily use it multiple times within a project. For example, there's a 4 channel mixer object. As you can see in part 2-2 of the audio library tutorial, two of these mixers are used to combine sounds separate for the left and right channels. It's the exact same code implementing the mixer, but each processes different data. In object oriented lingo, these are called 2 "instances" of the object. The essence of objects is they are just pieces of software which can be easily reused multiple times, to process different data in each instance.

Most of the audio objects only manipulate data and do not access any hardware. You can create as many instances as you like, limited only by the available memory and CPU power to perform all the work they do. But the input and output objects are responsible for actually moving data to & from the outside world. They use hardware resources to do this, which means you can't use certain combinations because they would conflict when trying to access the same hardware. Ideally, the design tool would "know" about these hardware requirements and warn or prevent conflicting combinations. But today the best we have is documentation to tell you about these hardware dependencies.

I lost over, "S/PDIF output uses the I2S hardware.

It is a very cleaver hack that Frank created, to run the I2S at a faster rate and synthesize the S/PDIF bitstream in software.

the audio shield is I2S and it has both input and output (objects?), but the digital S/PDIF (I'm assumings is Toslink) is only found in the OUTPUTs. So again, I'm forced to ask, There can't be a S/PDIF input even if it is a I2S chip, because the audio shield (being I2S) has both INs and OUTs ?

Yes, the documentation is correct.

Frank's hack to get S/PDIF output is quite an amazing feat. But it does use the I2S hardware. When used in that mode, the input section of the I2S hardware is unused.

And is the S/PDIF only for optical, or is there a way I can use coax?

I believe it's the same signal, so you should only need to use a different circuit. I have not personally tried this, so I can't really comment on exactly what circuit to use. When/if you or anyone else figures it out and confirms a particular circuit works, I'd be happy to update the documentation.

To really make my head spin, I found another device https://www.aliexpress.com/item/Aiy...PDIF-Fiber-Coaxial-USB-Sound/32833080360.html which claims to be I2S, but instead of 4 pins, it only has 3 [DATA, BCK, LRCK]

Many chips require MCLK, even though it's not technically part of the I2S protocol. Strictly speaking, I2S is only 3 signals.

Will this work as an I2S input?

Good question. Like many cheap Aliexpress products, it sorely lacking in technical documentation. It does at least say the signals are 1.8V logic, so at the very least you'll need 1.8V to 3.3V logic level conversion, with low enough propagation delay to work at the I2S speed. The little bidirection level shifters using a mosfet and 2 resistors are absolutely not up to this fairly high speed task!

I2S is not a "plug and play" standard. There are many fine details to consider. The most basic point is whether a device is the I2S master (creates the clocks) or I2S slave (receives the clocks). Until very recently, the audio library used a BCLK to LRCLK ratio of 32. It was changed to a ratio of 64 earlier this year, because many chips seem to require this ratio, even if they only really support 16 bits. The newest generation of MEMS microphones with I2S were the main case people were finding.

Some time ago, there was a thread about using a I2S bluetooth board. It had better documentation, but still not as much or as clear as you might want. It might have used a FTDI chip, but I'm not sure. Anyway, after much fiddling and guesswork, it turned out that particular board couldn't support 44.1 kHz sample rate. Its I2S was limited to much slower speeds, which of course was not prominently mentioned in any of the documentation (remember, all datasheets are sales pitches).

Whether it will work is anyone's guess. Who knows, if you can figure out whether it's I2S master or slave mode and convert the logic levels, maybe it will work. Or maybe you'll run into tough problems.

I know this may be silly, but maybe try asking the seller for advice or more documentation. They probably won't know anything, or might reply with questionable info that's worse than just guessing, but if they do reply at all, I hope you'll share it here. It's always interesting to hear what those Chinese merchants answer about tech questions. ;)


My final goal is to use this board as an input, and then have one Teensy output an optical signal which would be received by optical input on another Teensy and finally have the audio shield drive an analog amplifier.

There definitely isn't any S/PDIF input support. Frank tried to do input also, but it's just not feasible without hardware to recover the clock.

To get this working, at the very least you would need to make a S/PDIF to I2S converter. If you try to connect two different I2S devices, you'll need one to be the master and both of the others must be in slave mode (receiving the master's LRCLK and BCLK). If any require MCLK, you'll need to make sure that is the correct frequency and in phase with BCLK. Once you have all the clocks figured out so both sides share a valid BCLK and LRCLK, then getting data from one to another is just a matter of connecting a TX output or a RX input.
 
Last edited:
Wow thanks SO much, it would have taken me weeks to get anywhere near that much tailored info. Since I 'm doing this project to "shore up" the sound system at my workplace, it needs to be done in a timely manner. This means I have to keep my learnin' kurve low (ie use as much off-the-shelf stuff as I can). If, down the road I do manage to navigate the ali-express route, I will certainly make it back here with all the details of my big adventure.

At this point, I'm still moving forward with the USB digital input as my anchor, and looking into:

TDM which uses the CS42448 Circuit Board:
Where it says, "Order board" that's JUST the board, right? Soldering chips with that size pin spacing is outside of my
skill level, and the price makes them unsuitable to "learn on". Unless... I could buy the board with the "impossible"
soldering already done? Oh well, 6 digital inputs would have been perfect.

ARDUINO-TEENSY v4.4 with WIFI+BLUETOOTH+NRF24L01:
The bluetooth option would work for me as a stereo digital input using one of the three RxTx pairs. But since I don't see
anything promising as an "object", I conclude this makes it a no-go with the TAL? --->Teensy Audio Library<--- :D

How many stereo digital inputs can I get and still be able to use TAL? Do the USB I/Os have to be tied to Windows, or would a "driverless" (meaning UPnP?) dongle style sound card work? Because I'm thinking about using the USB Host Cable For Teensy 3.6 as an improvised input device.

At the very least, I hope I have this straight, that I can use one analog I/O pair from the audio shield and a digital I/O pair via USB, at the same time? I'm really keen on using TAL to tame the unruly sound system because it would be so slick now, and leave lots of room to make changes or upgrades in the future. Plus, I'd gain much Geek Cred. at work! :p
 
Last edited:
Without fine pitch surface mount soldering, the most that's available today is 4 channels (both in and out) by stacking 2 audio shields. See the quad I2S documentation for details, and a link to a nice tutorial Sparkfun wrote.

If you're going to connect analog signals to other grounded equipment, odds are good you'll need ground loop isolators or special attention to power supplies and grounds of everything involved in the system.
 
It is a very cleaver hack that Frank created
Isn't it a bit too early for Halloween references? ;)

you'll need 1.8V to 3.3V logic level conversion, with low enough propagation delay to work at the I2S speed. The little bidirection level shifters using a mosfet and 2 resistors are absolutely not up to this fairly high speed task!
Well, the TXS0104 can do 2Mbaud (open collector, much higher in push-pull); isn't that enough?
 
The data rate is 2.82 Mbit/sec, if using 44100 samples/sec and BCLK/LRCLK ratio of 64.

I generally suggest avoiding bidirectional converters when the signal is unidirectional.
 
If you're going to connect analog signals to other grounded equipment, odds are good you'll need ground loop isolators or special attention to power supplies and grounds of everything involved in the system.

My project's main focus is just that, getting rid of the hum that plagues the sound system. I've found UNDERSTANDING, FINDING, & ELIMINATING GROUND LOOPS by this cat, Bill Whitlock (a Senior Member of IEEE), to be the best resource on the subject. It covers theory like a text book, but in real world situations with familiar equipment. Most importantly, it gives step-by-step troubleshooting using simple DIY tools. But unlike an academic paper, it's quite readable and at only 43 pages covers a lot of ground [excuse the pun :p ] https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwitjsfnk_HWAhUQ4GMKHUpVD8sQFggmMAA&url=http%3A%2F%2Fweb.mit.edu%2Fjhawk%2Ftmp%2Fp%2FEST016_Ground_Loops_handout.pdf&usg=AOvVaw1t7EXLsd-lADIe8NcRuASE


Without fine pitch surface mount soldering, the most that's available today is 4 channels (both in and out) by stacking 2 audio shields.

2 analog channels would be fine, but I really need digital I/O. The Audio System Design Tool for Teensy Audio Library has an "object?" for USB under Input as well as Output. Can Teensy use both of those at the same time using it's microUSB connector? I've never used one, but USB soundcards have both in & out (I am just assuming both at the same time).

I'm really most interested in the Teensy 3.6 with the USB Host Cable. Will this allow me to use 2 USB inputs at the same time?
 
2 analog channels would be fine, but I really need digital I/O. The Audio System Design Tool for Teensy Audio Library has an "object?" for USB under Input as well as Output. Can Teensy use both of those at the same time using it's microUSB connector?

Yes, simultaneous input and output over the USB micro-b (device mode) connector is supported.

However, pay attention to the requirement to also have an non-USB input or output in your system, even if unused, since the USB is not capable of the "update responsibility".

I'm really most interested in the Teensy 3.6 with the USB Host Cable. Will this allow me to use 2 USB inputs at the same time?

No, audio over the USB host port is not yet supported. It only supports USB device mode (communication to your PC or Mac).

The USBHost_t36 library is still in the experimental stage, though quite a lot of progress has recently been made. Even for the devices it does support, the whole thing is not yet considered stable.

But audio (or video) on the USB host port support is a long way off, because USBHost_t36's EHCI layer doesn't yet support isochronous pipes. The iTD and siTD structures and periodic bandwidth planning for isochronous pipes adds quite a lot of complexity, so it's unlikely I'll manage to add isochronous support anytime soon. It's also theoretically possible someone other than me might work in isochronous pipe support and contribute working code. But EHCI is very difficult, so I wouldn't expect this...
 
USBHost_t36 also currently lacks support for frame span traversal nodes in the periodic schedule. Those are needed to schedule split transaction complete tokens beyond the end of a USB frame. Without this ability, the bandwidth planning code can only assign 12 Mbit/sec (and 1.5 Mbit/sec) transactions within the first section of a 1ms frame. Those FSTN structures are needed to cause the ECHI to communicate with the hub's transaction translator in the early part of the next frame, if the slow transfer might go near the end of the current frame. For interrupt transfers which are limited to only 64 bytes at 12 Mbit/sec or only 8 bytes at 1.5 Mbit/sec, this isn't a huge limitation. But for large isochronous transfers, which are allowed to schedule up to 1023 bytes at 12 Mbit/sec, and also interrupt transfers schedule after them, FSTN support becomes much more important. For a taste of how incredibly complicated this gets, try reading pages 92-106 of the EHCI spec.
 
The data rate is 2.82 Mbit/sec, if using 44100 samples/sec and BCLK/LRCLK ratio of 64.

I generally suggest avoiding bidirectional converters when the signal is unidirectional.
Right. I understand the bidirectional ones also may have issues with oscillation, too. I'm also doing 3.3V-to-1.8V translation on another project. I looked around, and decided to try the 74LVC1T45 one-signal converters; they can do up to 75 Mbps.

In this case, I personally would try something like two TI SN74AVC4T245 (one for each direction, four bits per chip; can do at least 100 Mbits/s), for the I2S, and maybe a TXS0102 or something similar for the I2C. I am very wary of back-feeding current when only one side is powered, so I only loot at chips with isolation features (i.e., high-Z outputs when either side is not powered).

For a taste of how incredibly complicated this gets, try reading pages 92-106 of the EHCI spec.
Ouch. First step would be a complete state graph, definitely. (I like to use Graphviz for those, by the way.) Not the way I'd like to start a Sunday, though.

My project's main focus is just that, getting rid of the hum that plagues the sound system.
You can do that without having to go with optical signals (SPDIF/TOSLINK), though.

One easy way is to isolate the USB sound card from the computer, so that it uses the same ground as the rest of the audio equipment. You need to use an USB audio device that is limited to 12Mbit/s (Full speed USB) -- like the micro-USB connector on Teensies --, as High-speed (480Mbit/s) isolators are very expensive.

The easiest affordable USB isolator is, in my opinion, the OLIMEX USB-ISO, also sold by e.g. Farnell. (It specifically mentions it fits USB audio class 1.) It has an isolated DC-DC converter, which uses the host/computer USB power to supply the device with up to 350mA.

If 350mA (total for Teensy and the Audio Shield) is not enough, the Olimex USB-ISO also has an 8-15V barrel power jack, which can be used to provide the device with up to 750mA of current (regulated to 5V). It is important that you then use a wall wart that is galvanically isolated from the wall ground, to avoid a ground loop via wall sockets. All non-horrible switch-mode power supplies do this; they use a small transformer, and feedback is monitored via an optoisolator. In Europe at least, this is required for wall warts for safety reasons.

I also have a cheap Chinese copy off eBay, which only have the DC-DC converter, no additional power input jack. They seem OK (to me, but I'm not an EE); they're basically just implementations off the ADuM3160 datasheet and application notes, but the DC-DC converters seem to be off-brand. I would not try to draw more than about 300mA off of them, but below that, I'd happily use one of those (after inspection).

(Funnily enough, it looks like even the expensive end of the full speed USB isolators basically use the same circuit, based on an ADuM3160 or ADuM4160. I wonder what the magic pixie dust is that warrants a five-fold to fifteen-fold increase in price?)

However, I do not have the Audio Shield, so I haven't tried it with that. Paul, if you have, then adding a suggestion to the Teensy Audio Shield page might be useful; the ground loop hum issues are ubiquitous.
 
Status
Not open for further replies.
Back
Top