Any way to disable I2S MCLK output on T3x and T4x?

Status
Not open for further replies.
Hi,

I've been working for the past months on adapter PCBs that convert Teensy 3x and 4x to the Pi Zero form-factor, offering an alternative to a Raspberry Pi for those projects that really do not need an OS running in the background.
Teensy2Zero_T3x_MFGTopSilk3.jpg Teensy2Zero_T4x_MFGTopSilk3.jpg

I'm close to done with the design and routing now, but there's a few things on the pinout that I am double checking with some Adafruit perma-proto boards I soldered up.
DSC09687_small.jpg

Testing has been going fairly well (here's a clip of an SPI LCD test: https://twitter.com/ZodiusInfuser/status/1268547125455073280?s=20), however, when I attempt to use I2S in conjunction, the SPI no longer works.

I've narrowed the problem down to MOSI and MCLK sharing the same pin on the 3.x. Now I can get around this by switching MOSI to its alternate pin so the function's no longer conflict, but that's just shifting the problem to another pin that could still cause issues with some Pi HAT combinations. So instead of that, is there a function I could call, or register parameter I could change to disable the MCLK outputs outright on all T3x and T4x boards? The Pi GPIO header does not have MCLK exposed, so it is an unneeded clock signal for any I2S audio HATs. Sadly I cannot just leave the pin disconnected, as I'm two pins short of a full mapping on the smaller Teensy boards if underside pins aren't soldered to (an option I want to keep open to people).

If it is not possible to disable MCLK then I will adjust my routing to use the alternate MOSI pin, but thought I would put the question out there.

Thanks in advance
 
Sorry, I don't do anything with I2S, so I have no idea what would work or not work with I2S if MCLK is not outputting on that pin.

But is is sort of last configure wins... What I mean is if you later do a SPI.begin() after the I2S begin, the pin will probably be configured for SPI... Note: Pins are different between T3.x and T4.x.
As you can deduce from the Audio board page talking about IO pins: https://www.pjrc.com/store/teensy3_audio.html
 
Thanks very much for that tip! I was calling SPI.begin() in a class constructor that I happened to place before all the audio objects. Swapping it around to have Audio first, or placing SPI.begin() in setup(), lets MOSI take over from MCLK as you thought. Similarly for just setting the pin to output and driving it high or low.

I will have a think about changing MOSI on the T3x to the alt pin though, so that MCLK is on a less important Pi GPIO pin.

Note: Pins are different between T3.x and T4.x.
Yea, this is why I've had to design versions of the adapter for 3x and 4x. Too much is different between them to make a single adapter board for both generations without a whole load of solder jumpers. Yours and other community member's pinout spreadsheets have proved extremely useful in figuring things out!
 
Hi,

I've been working for the past months on adapter PCBs that convert Teensy 3x and 4x to the Pi Zero form-factor, offering an alternative to a Raspberry Pi for those projects that really do not need an OS running in the background.

I'm close to done with the design and routing now, but there's a few things on the pinout that I am double checking with some Adafruit perma-proto boards I soldered up.

Testing has been going fairly well (here's a clip of an SPI LCD test: https://twitter.com/ZodiusInfuser/status/1268547125455073280?s=20), however, when I attempt to use I2S in conjunction, the SPI no longer works.

I've narrowed the problem down to MOSI and MCLK sharing the same pin on the 3.x. Now I can get around this by switching MOSI to its alternate pin so the function's no longer conflict, but that's just shifting the problem to another pin that could still cause issues with some Pi HAT combinations. So instead of that, is there a function I could call, or register parameter I could change to disable the MCLK outputs outright on all T3x and T4x boards? The Pi GPIO header does not have MCLK exposed, so it is an unneeded clock signal for any I2S audio HATs. Sadly I cannot just leave the pin disconnected, as I'm two pins short of a full mapping on the smaller Teensy boards if underside pins aren't soldered to (an option I want to keep open to people).

If it is not possible to disable MCLK then I will adjust my routing to use the alternate MOSI pin, but thought I would put the question out there.

Thanks in advance

Well in Teensy 4.x, you do have the option of using I2S2 instead of I2S1. The MCLK2 pin is 33 (back of the Teensy 4.1, underneath on the Teensy 4.0). So it doesn't interfere with the other standard 24 pins. The pins are:
  • Pin 2 -- OUT2
  • Pin 3 -- LRCLK2
  • Pin 4 -- BCLK2
  • Pin 5 -- IN2
  • Pin 33 -- MCLK2

Note, the audio shield only uses I2S1, but if you are developing your own processing, you should be able to use I2S2.

Paul has updated the Audio Gui to include I2S2: https://www.pjrc.com/teensy/gui/.

On the Teensy 3.x, you have no option to use the 2 alternate SPI pins (pin 7, alternate for MOSI0, pin 14, alternate for SCK0). If you limit yourself to the Teensy 3.6/3.5, you could use the second SPI bus:
  • Pin 0 -- MOSI1 (alternate pin 21/A7)
  • Pin 1 -- MISO1 (alternate pin 5)
  • Pin 32 -- SCK1 (alternate pin 20/A6)
  • Pin 31 -- preferred CS pin

Note, in using the 2nd SPI bus on the Teensy 3.5/3.6, you lose some of the optimizations some LCDs have on certain pins for Teensy 3.x because there is only one favored CS pin (31), and you need 2 to do the optimization (one for CS, one for D/C). But at least it should be usable.

The Teensy 3.1/3.2 does not have a second SPI port, but it does support pins 7/14 as alternates for MOSI0/SCK0.

The Teensy LC does have a second SPI port, but since it doesn't support I2S, or the audio library in general, it may be less of an issue. The pins are somewhat different for the 2nd SPI bus.

Assuming you are connecting the I2C bus in addition to the I2S bus to the Pi, you likely will need two pull-up resistors on the I2C pins. It may make sense to have a solder jumper to disable these resistors. Typically for 3.3v systems, you would want 2.2K resistors.
 
Last edited:
Thanks for the info! It's given me much to think about over the past few days.

The option of switching to alternate I2S and SPIs certainly appealed, but would have caused too much re-routing of the boards at this stage. Instead I've switched the MOSI0 output on the T3x adapter (already had SCK switched but forgot about MOSI), and changed the pin mapping. Also swapped pins on the T4x adapter to avoid MCLK being on one of the Pi's few designated PWM pins (so thankful most T4 pins are PWM capable!).

Ended up doing a bit of pin round-robin too, so that MCLK is output on the same GPIO pin on both adapters. I didn't necessarily need to do this, but seemed wise to have them share the same "problem pin". Not that it's a major problem. As KurtE mentioned, MCLK can be "overridden" by another pin operation, but even when I do that right at the start of setup() with a digitalWriteFast(), on a Teensy 4 it still manages to output a clock for 5uS according to my logic analyser.

Assuming you are connecting the I2C bus in addition to the I2S bus to the Pi, you likely will need two pull-up resistors on the I2C pins. It may make sense to have a solder jumper to disable these resistors. Typically for 3.3v systems, you would want 2.2K resistors.
Already got pull-ups accounted for, as that was the one oversight I made on my first version of the adapter I made a year ago.

Glad you mentioned value though! I was going to use 4.7k as I thought I'd read somewhere that the Pi used that value (and it worked in my testing), but checking the latest schematics they actually use 1.8k. Should I copy that, stick with 4.7k or go with your 2.2k suggestion?

A solder jumper to disable them's not a bad idea, but those pins are only I2C on the Pi GPIO so no HATs will be using alternate functions, and I don't actually have the space to fit one in now anyway.
 
Status
Not open for further replies.
Back
Top