Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: I2S for input and output

  1. #1
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,366

    I2S for input and output

    I don't know the I2S protocol all that well.

    If I wanted to have an I2S input (such as the I2S microphone sold by Adafruit) and an I2S output (such as audio shield or the various I2S devices that decode I2S to analog speakers), do I need to use I2S1 (pins 7, 8, 20, 21, and 23) for say the speakers and I2S2 (pins 2, 3, 4, 5, and 33) for the microphone? Or can I just wire both to the same I2S port? I don't see things like CS or direction pins in the MCLK, LRCLK, BCLK, IN, and OUT pins, but maybe I'm not understanding things.

    On a whim, I bought the I2S microphone along with 2 analog microphone electret condenser microphones while buying some surface mount capacitors/resistors for the FRDM4236 breakout boards. I know I can solder the analog microphones into the audio shield, but I was curious about how to use the I2S microphone with I2S output. At the moment, I don't really have solid plans for it.

  2. #2
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,398
    Michael,
    Assume you wanted same sampling frequency (LRCLK and BCLK)
    you connect LRCLK and BCLK to both devices, you connect MCLK to devices that need MCLK (assuming both devices use the same MCLK/LRCLK ratio)
    The I2S Micros usually do not take MCLK
    you connect IN to I2S-microphone and out to I2S speaker.

    If sampling is different
    you connect RX_LRCLK and RX_BCLK and IN to microphone and TX_LRCLK and TX_BCLK and OUT to speaker. (NOTE: in this case you have to write your own driver)
    OR, you use I2S1 and I2S2 (again need own driver, which, I guess, should not be difficult for you)

    Summary, the I2S system is extremely flexible and you can do a lot of tricks.

  3. #3
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,366
    Ok, thanks.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,806
    I2S is simpler than protocols like SPI & I2C. All the signals are unidirectional. There's no starting and stopping like with normal protocols. The clock just runs continuously and data output pins always transmit a new bit on each rising edge of BCLK and data inputs always read a new bit.

    Normally Teensy runs in I2S master mode, which means it drives the clocks as outputs. Almost all I2S peripheral chips support slave mode. As far as I know, all the I2S microphones work only in slave mode, which is ideal for use with Teensy.

    When Teensy is using I2S master mode, you can connect 2 chips, as long as each data output connects only to a data input.

    Some peripheral chips also can do I2S master mode, which usually requires connecting a crystal to the chip. If you buy a breakout board that has a crystal, that's a strong sign it probably is designed to run in master mode and drive the clock signals. Obviously you wouldn't want to connect 2 masters together, since they would both try to drive BCLK and LRCLK.

    So when Teensy is using I2S slave mode, only one I2S master can be connected. In slave mode, the audio library no longer runs at a speed sync'd to Teensy's clock. The I2S master is in control of the audio timing and the entire audio library runs at its speed. The non-I2S peripherals (currently only supported on Teensy 3.x) need to run sync'd to Teensy's clock. If you try to use those together with I2S slave mode, they will sort-of work, but you can expect small dropouts or other audible problems.

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    2,398
    To add to Paul's comment:
    I have a version where ADC is running as master and Teensy as slave, BUT Teensy provides the MCLK for the ADC (i.e. not using a Xtal).
    So Teensy outputs MCLK but as slave syncs to external master LRCLK and BCKLK.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •