Forum Rule: Always post complete source code & details to reproduce any issue!
Page 1 of 3 1 2 3 LastLast
Results 1 to 25 of 72

Thread: Teensy 4.0 I2S Support

Hybrid View

  1. #1
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    227

    Teensy 4.0 I2S Support

    I understand that the T4 is not direct pin compatible with the audio shield as the I2S pins are in different locations. Looking through the massive Beta thread, there was some discussion about an adaptor board not being possible either because the SAI1/SAI2 pins are both split between the regular pins and back side but I may be interpreting that wrong.

    For SAI1... MCLK, BCLK and LRCLK (23, 21, 20) are all on the regular pins but I'm a little confused about the relationships between the IN/OUT pins. For example, can we use pins 8 and 7 (IN1 and OUT1A respectively) to complete the data in and out for the I2S interface?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,553
    I updated the audio shield page recently, with this:

    Update: Teensy 4.0 has its digital audio signals (MCLK, BCLK, LRCLK, TX, RX) in different locations. On Teensy 3.x, these are pins 11, 9, 23, 22, 13. On Teensy 4.0, those signals are pins 23, 21, 20, 7, 8. This audio shield will only work if wires are used to route those 5 signals. It does not work if soldered directly above or below a Teensy 4.0. The MCLK signal also requires a 100 ohm resistor in series. We added this resistor in "Rev C", which is currently shipping, but not yet documented on this page. If you have an older "Rev B" audio shield, you will need to use a 100 ohm resistor in line with MCLK to use it with Teensy 4.0. We are working on a "Rev D" audio shield with the 5 signals routed for Teensy 4.0, for release in early September.
    When I get some time, will add a photo of the required wiring. A photo should be a lot more visible than just this text.

  3. #3
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Quote Originally Posted by PaulStoffregen View Post
    I updated the audio shield page recently, with this:



    When I get some time, will add a photo of the required wiring. A photo should be a lot more visible than just this text.
    Hi Paul

    Reading the post led me to wonder about something else. I'm not too familiar with how the audio library for the Teensy audio shield is constructed, but it seems to expect certain Teensy pins to be used. I was wondering, how feasible would it be to make the audio library generic such that the user/programmer can choose which Teensy (I2S) pins to assign in the code? Is this possible to do (in theory) given the limitation of assigning the use to digital IO pins of the Teensy? In that way the use of the library would be possible for any kind of pin choice or Teensy 3.x or Teensy4?

    Would like to understand this better,

    Thanks
    Erik

  4. #4
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,250
    Quote Originally Posted by Erik-Jan View Post
    Hi Paul

    Reading the post led me to wonder about something else. I'm not too familiar with how the audio library for the Teensy audio shield is constructed, but it seems to expect certain Teensy pins to be used. I was wondering, how feasible would it be to make the audio library generic such that the user/programmer can choose which Teensy (I2S) pins to assign in the code? Is this possible to do (in theory) given the limitation of assigning the use to digital IO pins of the Teensy? In that way the use of the library would be possible for any kind of pin choice or Teensy 3.x or Teensy4?

    Would like to understand this better,

    Thanks
    Erik
    I suspect this is just impossible, unless you resort to bit-banging (i.e. manually turning the pins on/off and not using the hardware supports, which would be sloooooooooooow). You have to understand that these modern chips have things like SPI, I2S, I2C, in hardware, and there are only so many combinations that are supported.

  5. #5
    Junior Member
    Join Date
    Aug 2019
    Posts
    2
    Quote Originally Posted by MichaelMeissner View Post
    I suspect this is just impossible, unless you resort to bit-banging (i.e. manually turning the pins on/off and not using the hardware supports, which would be sloooooooooooow). You have to understand that these modern chips have things like SPI, I2S, I2C, in hardware, and there are only so many combinations that are supported.
    Thanks for the explanation MichaelMeissner

  6. #6
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    227
    Thanks Paul. Very much looking forward to using the Teensy 4.0 with my TGA Pro and this info will help me make an adaptor board. I presume the 100 ohm resistor on MCLK was to help absorb some reflections from the processor's fast edges?

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,553
    Quote Originally Posted by Blackaddr View Post
    I presume the 100 ohm resistor on MCLK was to help absorb some reflections from the processor's fast edges?
    Yup, pretty much. It came up during the beta test and was discussed somewhere in the 4000+ message beta test thread.

    Fortunately it was discovered long enough ago that we were able to make a revision to add the resistor on the audio shield by the time of Teensy 4.0's release.

    Another rev is coming soon which will have the pins re-routed so it works directly on top of Teensy 4.0.

  8. #8
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    227
    Quote Originally Posted by PaulStoffregen View Post
    Yup, pretty much. It came up during the beta test and was discussed somewhere in the 4000+ message beta test thread.

    Fortunately it was discovered long enough ago that we were able to make a revision to add the resistor on the audio shield by the time of Teensy 4.0's release.
    Hey Paul or anyone from the Beta who worked on I2C/I2S, question about this resistor. At first, I couldn't get my T4 working with my WM8731. As we already know, the WM8731 is sensitive to overly fast edges. It appears the T4 is using default I/O output pad settings, it doesn't change based on the function they are assigned to. This was causing me issues as the default configuration had too fast a slew rate and too strong a drive strength for I2S and I2C pins which are of course slow and very slow respectively.

    I was able to get the codec working flawlessly in the end but had to make a few changes:

    #1 In WireIMXRT.cpp there a couple functions with infinite while (1) loops waiting for an event with a note that says // TODO: timeout .... My bus errors were freezing the bus in a busy state and this was hanging the CPU in these infinite loops so I had to add a timeout. This fixed the CPU hanging but of course the bus errors themselves were still a problem.

    #2 So, I was still getting very serious bus errors, even retries weren't enough to make the codec work. By reconfiguring the various output pads appropriately for slow interfaces, 100% of the bus errors went away. Specifically setting the slew rate slow, and the drive strength to minimum for all I2C pins and I2S outputs. Furthermore, The I2C didn't appear have open-drain enabled? so I added that as well. The following fixed all the signal reflections causing problems:
    Code:
    // defaults were all 0x10B0 which is keeper, Medium speed (100 Mhz), drive strength = R0/6 = 150/6 = 25 ohms (the second strongest drive strength available)
    // My changes were:
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_00 = 0xF808; // SCL, pullup at 22K, open drain enable, low speed, drive strength at R0 (150 ohm)
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_01 = 0xF808; // SDA
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_09 = 0x8; // MCLK, low speed, drive strength at R0 (150 ohm).
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_10 = 0x8; // BCLK
    IOMUXC_SW_PAD_CTL_PAD_GPIO_AD_B1_11 = 0x8; // LRCLK
    IOMUXC_SW_PAD_CTL_PAD_GPIO_B1_01 = 0x8; // OUT1A
    Shouldn't the output drivers be configured similarly for low speed interfaces to prevent reflections? The drive strength is controlled by the output series resistor in the pad. Specifically for MCLK, the default is 25 ohm, and you've added a 100 ohm resistor to the board effectively making the drive strength 125 ohm. Wouldn't changing the output driver from R0/6 to R0 have accomplished the same thing (sets drive strength to 150 ohm)?
    Last edited by Blackaddr; 08-20-2019 at 02:47 AM.

  9. #9
    Quote Originally Posted by Blackaddr View Post
    Shouldn't the output drivers be configured similarly for low speed interfaces to prevent reflections?
    The other interfaces aren't as critical as in this case they are all just allowed to settle and then clocked in by MCLK so it is this line that it is essential there are no reflections. STMicroelectronics MCUs have special circuitry to avoid this problem but NXP seem a little different.

    But anyone using ADC or DACs without an MCLK (e.g. PCM5102) it is essential to avoid reflections so you need to get the line matching perfect or there will be jitter in the regenerated clock.

  10. #10
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    227
    Quote Originally Posted by MikeDB View Post
    The other interfaces aren't as critical as in this case they are all just allowed to settle and then clocked in by MCLK so it is this line that it is essential there are no reflections.
    In general this is true. But you also need to consider PCB routing. Tracks with fast edges can couple into adjacent tracks where then run close and parallel. Thus, data lines that run right next to clock lines can have their reflections (caused by fast edges) couple into the clock line where they run parallel.

    Fast edges also emit more EMI which can cause interference in nearby analog circuits. Since we're talking about an audio codec here this is very important. My recommendation is that all digital output drivers be configured for the slowest edges and power that still provides high data integrity, not just for the clock output. This is a common design rule at my current employer where EMI and power are tightly constrained.

  11. #11
    I'm excited to get my new T4, but how do I tell which rev my audio shield is?

  12. #12
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,250
    Quote Originally Posted by ofishal View Post
    I'm excited to get my new T4, but how do I tell which rev my audio shield is?
    There have been 4 audio shields released so far (not counting the new audio shield specifically for the T4):
    • The real original audio shield had a black PCB (I was reminded of this when I looked in the drawer with my old audio shields);
    • Then there was a re-release of the audio shield with a green PCB, but same functionality (as I recall there were electrical issues with the black PCB's so Paul changed to green);
    • In January 2015, revision B of the board was released that has some minor changes -- it has a green PCB, and it says REV B on the silkscreen underneath the board (see https://www.pjrc.com/store/teensy3_audio.html for the details of the changes, but note the picture on that page is still the first revision board);
    • Just recently there was a revision C of the board that has the MCLK resistor added. It has a green PCB and it says REV C on the silkscreen underneath the board. Sparkfun is now carrying this board. I don't know of the other distributors (Adafruit, Digi-key, etc.). Presumably in a few days Paul will get some breathing room to update the page.


    Paul has provided the specifications for the shield that was used during the beta test to rewire the audio board. You can order the PCB from oshpark if desired, though given its size, it is somewhat pricey ($37.10 for 3 boards for USA delivery):

  13. #13
    Quote Originally Posted by ofishal View Post
    I'm excited to get my new T4, but how do I tell which rev my audio shield is? redadair https://www.redadair.com
    All of the time you hit the command in those shared devices ??

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,553
    Rev D is coming soon. Here's the first prototype, on my desk right now...

    Click image for larger version. 

Name:	DSC_0576_web.jpg 
Views:	81 
Size:	165.4 KB 
ID:	17203

    On the very first ones (Rev A), the green and black ones were identical, other than the color.

    The black solder mask never caused any trouble on the audio shield, but it did cause some of the original Teensy 3.0 boards to fail (during testing). We dropped the black color for all boards, even though it was good enough for some. The green solder mask is a much higher quality.

  15. #15
    Senior Member+ MichaelMeissner's Avatar
    Join Date
    Nov 2012
    Location
    Ayer Massachussetts
    Posts
    3,250
    Quote Originally Posted by PaulStoffregen View Post
    Rev D is coming soon. Here's the first prototype, on my desk right now...
    Given the different pinouts between 3.x and 4.0 for I2S, assuming the rev D board is only for Teensy 4.x, it may be helpful to those of us that serially buy boards over time, and toss them back into a bin for later reuse to add to the silk screen on the bottom saying Teensy 4.0, in addition to "Rev D". Though if the Rev D board has solder jumpers that I could easily convert it between a Teensy 3.x and Teensy 4.0 that would be even better.

    BTW I was going through my bin of audio boards when I saw the board with the black PCB which reminded me of the original color.

    Now that we know there is a new audio board coming for the T4, I wonder what we can do about the prop shield? I found the prop shield to be the perfect companion for the T3.2 (and 3.5/3.6 with adjustments). In fact I stopped using the audio board when the prop shield came out. While the sound isn't the best, for props, it is good enough. I'm wondering if it would make sense something small that would use I2S instead of the DAC for mono sound. With the prop shield, the key is that it doesn't increase the size of the Teensy that much while the sound board makes much wider (and it can't fit in the hilt of a lightsaber).

    I realize Paul, you can't share details of unannounced products until they are close to fruition, and you may be already designing one. Or perhaps the sales of the prop shield aren't high enough to warrant a T4 version.

  16. #16
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    9,678
    Quote Originally Posted by PaulStoffregen View Post
    Rev D is coming soon. Here's the first prototype, on my desk right now...

    ...
    Paul - is the Rev D final silkscreen committed? - I should have mentioned this earlier - during the T4 Beta handling the Audio boards I have to work to find which end is the GND/USB end to orient with Teensy. If not too late having a 'GND' end PIN indicator of some sort could help.

  17. #17
    Member
    Join Date
    Jun 2016
    Location
    rural West Virginia
    Posts
    61
    A photo should be a lot more visible than just this text.
    I'm not sure how much it helps but pictures of my test board are in post #115 of the Teensy 4.0 release thread. My board has sockets for the T4.0 and a T3.2 or T3.6. It is also dual footprint for the Teensy audio shield or Paul's CS42448 board. All 6 combinations work even though I forgot the 100 ohm resistor on MCLK and have rev B audio adapters. I will probably add a 51 ohm SMD part at each end of the wire.

    The three clock lines are run as twisted pair with the grey wire being ground as they are almost 4 inches long. The other signals are just flying wires. Each wire has different color tracers to make it easier to fix or change once the wiring reaches the ratsnest / furball stage.

    The picture was taken with only the minimum wiring needed for audio functionality. I will be adding all the synthesizer functionality as time goes on. The SPI lines for the SD card socket are not implemented yet, as I don't need SD functionality at this time.

    Beta 6 or later TD code is needed to get the fixed I2S output file.

  18. #18
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    189
    Can anyone confirm that AudioInputI2S works with the Teensy 4.0?

    It does not work for me. I can play sounds out via AudioOutputI2S but I can't bring audio in using AudioInputI2S.


    My Setup:

    I wired up the Teensy Audio Adapter to a Teensy 4.0 using the pin remapping described by Paul (https://www.pjrc.com/store/teensy3_audio.html). Below is a picture of my wiring diagram that I made for myself.

    Click image for larger version. 

Name:	Teensy4-AudioBoard.jpg 
Views:	109 
Size:	149.4 KB 
ID:	17212

    Below is a picture of it actually wired.

    Click image for larger version. 

Name:	IMG_20190814_110100055.jpg 
Views:	40 
Size:	285.9 KB 
ID:	17213

    Software:

    I'm running Arduino 1.8.9 with Teensyduino 1.4-beta7. I'm running the ToneSweep and the PassThroughStereo examples from the Teensy Audio library.

    Symptoms:

    ToneSweep runs fun. PassThrougStereo, however, produces no audio at the output (yes, I am injecting audio into the system). Most curiously, going back to ToneSweep, if I simply add a line instantiating an AudioInputI2S object, it breaks ToneSweep:

    Code:
    AudioInputI2S      audioInput;  //I added this
    AudioSynthToneSweep myEffect;   //this was here
    AudioOutputI2S      audioOutput;        // audio shield: headphones & line-out
    
    // The tone sweep goes to left and right channels
    AudioConnection c1(myEffect, 0, audioOutput, 0);
    AudioConnection c2(myEffect, 0, audioOutput, 1);
    Note that I don't need to connect audioInput to anything; simply including the line in the sketch prevents the ToneSweep sketch from making any audio. It compiles fine. It simply doesn't output any audio.

    Has anyone confirmed that AudioInputI2S works with Teensy4?

    Chip

  19. #19
    Senior Member
    Join Date
    Dec 2015
    Posts
    124
    Quote Originally Posted by chipaudette View Post
    Can anyone confirm that AudioInputI2S works with the Teensy 4.0?

    It does not work for me. I can play sounds out via AudioOutputI2S but I can't bring audio in using AudioInputI2S.


    My Setup:


    I wired up the Teensy Audio Adapter to a Teensy 4.0 using the pin remapping described by Paul (https://www.pjrc.com/store/teensy3_audio.html). Below is a picture of my wiring diagram that I made for myself.

    Click image for larger version. 

Name:	Teensy4-AudioBoard.jpg 
Views:	109 
Size:	149.4 KB 
ID:	17212

    Below is a picture of it actually wired.

    Click image for larger version. 

Name:	IMG_20190814_110100055.jpg 
Views:	40 
Size:	285.9 KB 
ID:	17213

    Software:

    I'm running Arduino 1.8.9 with Teensyduino 1.4-beta7. I'm running the ToneSweep and the PassThroughStereo examples from the Teensy Audio library.

    Symptoms:

    ToneSweep runs fun. PassThrougStereo, however, produces no audio at the output (yes, I am injecting audio into the system). Most curiously, going back to ToneSweep, if I simply add a line instantiating an AudioInputI2S object, it breaks ToneSweep:

    Code:
    AudioInputI2S      audioInput;  //I added this
    AudioSynthToneSweep myEffect;   //this was here
    AudioOutputI2S      audioOutput;        // audio shield: headphones & line-out
    
    // The tone sweep goes to left and right channels
    AudioConnection c1(myEffect, 0, audioOutput, 0);
    AudioConnection c2(myEffect, 0, audioOutput, 1);
    Note that I don't need to connect audioInput to anything; simply including the line in the sketch prevents the ToneSweep sketch from making any audio. It compiles fine. It simply doesn't output any audio.

    Has anyone confirmed that AudioInputI2S works with Teensy4?

    Chip
    see: https://forum.pjrc.com/threads/57341...l=1#post213469

  20. #20
    Senior Member
    Join Date
    May 2016
    Posts
    218
    @DD4WH - Have you had a chance yet to look whether the T4 has cured the "twin peaks" bug that has driven me (and possibly you) crazy over the past couple of years with quadrature I2S inputs on the T3.6?
    I'm just wiring mine up to test.

    For those who don't know what I'm talking about, this bug cause the two I2S input channels to be out of synch by a single sample randomly on program reload or power-up, and when present will remain until the next upload or power-up. It is disastrous for quadrature signal processing because it completely destroys the phase relationship between the two channels. I'm pinning a lot of hope on the possibility that it's gone away on the the T4

  21. #21
    Paul just committed a fix for that a few hours ago, you will probably need to pull the absolutely latest to get it.

    https://github.com/PaulStoffregen/Au...fd086b37474443

  22. #22
    Senior Member
    Join Date
    Oct 2015
    Location
    Vermont, USA
    Posts
    189
    Quote Originally Posted by wcalvert View Post
    Paul just committed a fix for that a few hours ago, you will probably need to pull the absolutely latest to get it.

    https://github.com/PaulStoffregen/Au...fd086b37474443
    It works! Yay!

    Thanks so much,

    Chip

  23. #23
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,553
    Install 1.47 (not beta). It has the simultaneous I2S fix.

    https://www.pjrc.com/teensy/td_download.html

  24. #24
    Junior Member
    Join Date
    Aug 2019
    Posts
    9
    zelda and guitar sketches sounding great via my PCM5102 module! listing some DAC schematics/options would make folks happy when they realize t4 has no audio pins or usb midi yet & doesnt work with their audio shields. has anyone tried SPDIF?

  25. #25
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Location
    Central Europe
    Posts
    445
    Quote Originally Posted by reaganr View Post
    zelda and guitar sketches sounding great via my PCM5102 module!
    Could you post your sketch for using the PCM5102 with the Teensy 4.0? Or did you just use an example sketch? If yes, would be nice to know which one you used.

    Thanks a lot!

    Regards, Frank DD4WH

Posting Permissions

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