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

Thread: Using the I2S with Teensy4.0

  1. #1
    Junior Member
    Join Date
    Dec 2019
    Posts
    5

    Using the I2S with Teensy4.0

    Dear Sir or Madam, I recently acquired a Teensy4.0 and would like to operate the MikroElektronika development board MIKROE-506 with it.

    https://www.amazon.de/MikroElektroni...7787843&sr=8-1

    Everything is OK with the connection to the I2C bus.
    Now I want to establish and program the I2S connections.
    Now my question is how is the connection established and which libraries and commands are needed?
    Many thanks. Best regards

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,551
    If you want to use I2S in default CD format (16bit, 44.1kHz), it can be done with the audio library https://www.pjrc.com/teensy/td_libs_Audio.html and its AudioInputI2S and AudioOutputI2S objects. If you need different sample rates or bit depths, you'll have to write your own drivers based on the aforementioned objects.

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Teensy 4.0 does not yet support I2S slave mode, where the external chip creates the BCLK and LRCLK signals. Teensy 4.0 currently only supports I2S master mode. But that MikroE-506 board is designed for master mode. You can't connect two I2S masters together. One side must be master mode (transmitting BCLK & LRCLK) and the other must be slave mode (receiving BCLK & LRCLK).

    You'll need to modify that MikroE 506 board, which involves removing the crystal and adding a resistor to connect MCLK. Details on these threads:

    https://forum.pjrc.com/threads/53854...l=1#post198733

    https://forum.pjrc.com/threads/55334...l=1#post201494

    With those modifications and with the code shown on those threads, the MikroE-506 will listen for BCLK & LRCLK and be able to work with Teensy 4.0.
    Last edited by PaulStoffregen; 12-31-2019 at 03:43 PM.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    I've committed a fix on github to make I2S slave mode work on Teensy 4.0.

    https://github.com/PaulStoffregen/Au...60a96cc4930d09

  5. #5
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Many thanks to everyone for the quick help. Also interesting is a contribution in which a Wolfson WM8731 to 28 DIP adapter is used. This opens up the full use of all functions of the WM8731.

  6. #6
    Senior Member
    Join Date
    May 2016
    Posts
    245
    @Fritz
    A few of us tried using the WM8731 with the T3.6 and found a whole lotta problems with the I2C communication. The link to the thread is I2C problems with Teensy 3.6 and WM8731 codec. Paul ultimately found the main problem was caused by ringing on the MCLK line, but it was not a complete cure and multiple retries on I2C errors was incorporated into the library. I don't know if the problem persists with the T4 - I haven't tried it.

    Also be aware that there is a problem with I2S stereo input, where the left and right channels sometimes get 1 sample out of synch on program upload or power up. It may not be a problem for you but it causes havoc in quadrature signal processing where phase integrity between channels is essential. The problem seems to present in many arm processors (it's not unique to the Teensies) and many (if not all) codecs, including the WM8731.

  7. #7
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    The 1 sample sync issue is on my low priority bug list. When I get to it, this is the thread I'm following for that issue:

    https://forum.pjrc.com/threads/57391...l-exists-on-T4

    To anyone who's interested in that issue, please comment on that thread. If you comment here, I won't see your message when I later look into the 1 sample sync.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Quote Originally Posted by DerekR View Post
    the main problem was caused by ringing on the MCLK line
    MCLK is only used when Teensy I2S runs in master mode. WM8731 can be used either way, but generally the MikroE 506 board is meant to run in master mode (no MCLK) with Teensy's I2S in slave mode. If used that way, this MCLK ringing isn't an issue because MCLK isn't used at all.

  9. #9
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Hello forum,
    there are probably several versions of MikroE-506.
    The new version I'm using has Lin inputs and 11-pin header.
    Click image for larger version. 

Name:	MikroE-506-neue Version.jpg 
Views:	4 
Size:	233.6 KB 
ID:	18651
    I used the Teensy3.6 and provided all Teensy pins with a 3.9 k pull up.
    The connection to the MikroE-506 via 220R resistors.

    The test program with 440Hz sine works.

    greeting
    Fritz

  10. #10
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Hello forum.
    I currently run the MikroE-506 in master mode. The digital interface MOSI and MISO are connected to each other on the MikroE-506. The digitized data is thus sent from the ADC directly to the DAC in I2S mode. So far everything seems fine.
    Because of the signal quality, I would like to continue to stay in master mode with the MikroE-506.
    But now there is a problem, the I2S interface of the Teensy3.6 cannot function as a slave.
    Hence my idea not to use an I2S, but to operate the interface in DSP mode and send the serial data from the ADC to an input port on the Tennsy3.6.
    I suspect an interrupt is not fast enough to read 6 bytes serial every 20 microseconds.
    The reading function would have to be written in machine language.
    Is this possible on the teensy?
    greeting
    Fritz

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Quote Originally Posted by Fritz View Post
    Is this possible on the teensy?
    Yes. I2S slave mode is supported (though master mode is the normal way to use Teensy's I2S port).

    In Arduino, click File > Examples > Audio > HardwareTesting > WM8731MikroSine. Connection info is in the comments on that example.

    You're using Teensy 3.6, where this is fully supported by Teensyduino 1.48. But if you were using Teensy 4.0 (or anyone else with 4.0 finds this message), version 1.49-beta4 or later is needed to make this work on Teensy 4.0.

    Also look for the info in the comments about the crystal frequency. If you use it with the original crystal, it will work, but audio library synthesis and other features will be shifted in frequency since the audio lib expects 44.1 kHz sample rate.

  12. #12
    Junior Member
    Join Date
    Dec 2019
    Posts
    5
    Thanks for the hint.
    My goal is to collect measurement data at 48kHz in 24bit, so I cannot use any other sampling frequency. The measurement data are recordings with a measurement microphone that extends into the sound range below 1 Hz. The second channel is to record measurement data from an acceleration sensor.
    The recorded data 24bit / 48kHz are analyzed with a math program (Scilab).

    The usual recording devices, mobile recorders, end in the range of around 5-7 Hz.
    The analyzes show that the frequency is high at 5-7 Hz, but are cut off by the limitation of the mobile recorder.
    Therefore I want to extend these measurements in the frequency domain but stay at the sampling frequency of 48kHz.

    Sincerely yours
    Fritz

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,206
    Quote Originally Posted by Fritz View Post
    Thanks for the hint.
    My goal is to collect measurement data at 48kHz in 24bit, so I cannot use any other sampling frequency. The measurement data are recordings with a measurement microphone that extends into the sound range below 1 Hz. The second channel is to record measurement data from an acceleration sensor.
    The recorded data 24bit / 48kHz are analyzed with a math program (Scilab).

    The usual recording devices, mobile recorders, end in the range of around 5-7 Hz.
    The analyzes show that the frequency is high at 5-7 Hz, but are cut off by the limitation of the mobile recorder.
    Therefore I want to extend these measurements in the frequency domain but stay at the sampling frequency of 48kHz.

    Sincerely yours
    Fritz
    All doable, but you need to write your own I2S code.

  14. #14
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,319
    Quote Originally Posted by Fritz View Post
    My goal is to collect measurement data at 48kHz in 24bit
    Have you connected an oscilloscope to watch what those lower WM8731 bits actually do, like with the inputs shorted or open circuit but no signal connected?

    If you have only 2 channel scope, connect LRCLK to the external trigger input, so you can watch the data and bit clock, knowing the first MSB starts 1 clock after the trigger point.

    Everyone who actually sees this with their own eyes gains a much more realistic idea of the usefulness of capturing those 8 low bits (even even the bottom couple of the top 16 bits). Some ADCs might give you 18 or even 19 good bits, but the WM8731 is about as far away from that league of performance as you can get.

Posting Permissions

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