0

3.3V STEMMA Controller level shifting design
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

3.3V STEMMA Controller level shifting design

by bobjunga on Thu May 06, 2021 11:03 am

I am making a board that will have a STEMMA connector acting as a controller to support adding sensors. It will only have 3.3V onboard. After reading the tech spec page, watching the videos, and looking at some existing board layouts I have a few questions.

1) Power Topology. Are "sensors" always powered via the STEMMA connector and do "controllers" always provide Vcc on the STEMMA connector? Can two "controllers" use STEMMA to communicate? Does it work in practice to connect two STEMMA components if each is supplying Vcc on pin 2 if they are both providing the same nominal voltage? I would think that the voltage regulators would fight over the precise level resulting in a large current one way or another. Alternatively, do some STEMMA components leave pin 2 unconnected so that they neither supply nor consume power over the STEMMA connector? If not, it seems that my 3.3V controller board could assume that it will never see 5V data lines since it is providing only 3.3V on pin 2, yet the tech spec page clearly states "...both sides (I2C controller and I2C device) must be OK with 3-5V logic level and must implement I2C level shifting to the desired final voltage of the controller/device". So what are the scenarios where a 3.3V controller will see 5V data lines?

2) Bus Loading Do both controller and devices always implement pullups? I would think that controllers should implement pullups but devices that are powered by the STEMMA connector would assume that the data lines are already pulled up by the controller. The advice on the tech spec page is to use the level shifter with 4 resistors -- pullups on both sides of the FETs. If I were creating a STEMMA device (aka slave, aka sensor), I would be tempted to leave out the 2 resistors on the output side knowing that they would never be floating because my device needs to be connected to a STEMMA controller for power and the controller providing power would also be pulling up the data lines. Is this not a good assumption?

3) Polarization Its difficult to confirm the polarization of the JST connectors. The board layout shot on the tech spec page shows the layout one way (for PH connetors) but the layout in https://github.com/adafruit/Adafruit-QT-Py-RP2040-PCB uses the opposite (for SH connectors). Are the JST PH and JST SH connectors polarized in the opposite direction or could the picture in the tech spec page be reversed? (I assume the actual PCB layout is tested and correct). The official datasheets do not make it clear to me whether the polarization tabs are up or down on PH and SH connectors and the identification of "circuit 1" on the PH connector appears to be the opposite of that shown in the tech spec page PCB picture so without have the connectors in hand I can not be certain. My board is using through hole PH connectors so another variable is that maybe the SMT and TH parts are polarized differently. the datasheet drawings are not definitive. Only 90deg (horizontal) PH TH parts are in stock at the moment so I have to get it right because I won't be able to fit the 90deg backwarks to flip the polarization if its wrong.

Adafruit-QT-Py-RP2040-PCB Example:
That https://github.com/adafruit/Adafruit-QT-Py-RP2040-PCB board seems to not have any level shifting circuit nor does it pull up the data lines. The MCU pins connect directly to the STEMMA pins 3 and 4. Is that because the RP2040 pins are 5V tolerant and provide internal pullups or does that board assume that it will never see 5V data lines since its supplying only 3.3V on pin 2? My board uses a ATMega328p which does not have 5V tolerant pins. I am not sure if this QTPy board indicates to me that it is reasonable to not be 5V tolerant or not but I think that maybe it does.

Level Shifting for Controllers
The tech spec pages says "...both sides (I2C controller and I2C device) must be OK with 3-5V logic level and must implement I2C level shifting to the desired final voltage of the controller/device", but its not clear how the 4 resistor, 2 FET level shifter could be used on the controller side which would typically be providing power on pin 2. I assume that Vcc in that level shifting circuit is connected to the STEMMA pin 2 and that works for a device receiving either 3.3V or 5V Vcc on pin 2. But a controller needs to provide either 3.3V or 5v on pin 2 so there is no indeterminate Vcc available to the controller to pull the FET drain pins up to. Maybe a controller could just leave off the 2 pullups on the output side of the FETs, assuming the the connected device would pull up the data lines to what ever its Vcc is, but I wonder if it is a problem to leave the drain pins of the FETs floating in the case that nothing is connected to the STEMMA. Is that level shifting circuit only used for sensors/slaves or am I missing something about either the supported power typologies or how Vcc in that circuit is supposed to be connected?

A Potential 5V tolerant Design
It seems that to be safe, my board should make the data lines 5V tolerant even though it is providing 3.3V on pin 2. I am thinking that on each of the data lines I would put a 3.3V zener diode to gnd and a 1K resistor in series and 10K pullup resistor to 3.3V as shown in this schematic. I am thinking in the undriven state with a 5V device connected, the device would loose (5-3.3)/1000 (1.7mA) through the connection which is not ideal but not terrible either. When the device drives the line low, the 10K pullup and 1K series resistors would make a voltage divider that would result in my controller seeing about 0.3V which should be low enough to read as a low. I am not sure of the best value for the series resistor to trade off between the wasted current and the low level being low enough to be clearly read as low. Is there a better way to make the data lines 5V tolerant? Or should I just assume that its unlikely to ever see 5V data lines since I am only providing 3.3v to the sensors/devices attached to my board? If it really is unlikely that my board will ever see 5V data lines, it seems a shame to risk not having the data lines pulled all the way down (which affects 3.3V sensors too).

Potential5VTolerant3.3V_STEMMA_circuit.png
Potential5VTolerant3.3V_STEMMA_circuit.png (13.12 KiB) Viewed 86 times



--BobG

bobjunga
 
Posts: 2
Joined: Thu May 06, 2021 7:44 am

Re: 3.3V STEMMA Controller level shifting design

by adafruit_support_mike on Sun May 09, 2021 11:25 pm

bobjunga wrote:Are "sensors" always powered via the STEMMA connector and do "controllers" always provide Vcc on the STEMMA connector?

Not necessarily.

STEMMA is a connector/wiring protocol for I2C and power, with level shifting. There are no rules about who supplies the power.

bobjunga wrote:Can two "controllers" use STEMMA to communicate?

In theory yes, but in practice it's difficult. Both devices would have to operate as controllers and peripherals, and would have to know when to switch roles. I2C isn't a peer-to-peer protocol.

bobjunga wrote:Does it work in practice to connect two STEMMA components if each is supplying Vcc on pin 2 if they are both providing the same nominal voltage?

No. You never want to put two power sources in parallel unless they're specifically designed to work that way.

All power sources can be approximated by a perfect voltage source (has the same voltage no matter how much current flows through it) in series with a resistor. The resistor models the fact that all real power sources lose some voltage as the current increases, and we call it the power source's 'internal resistance'. A good power source has low internal resistance so its voltage remains reasonably stable as the current changes.

If two power sources are in parallel and they have different voltages, it's equivalent to a pair of low-value resistors in series between two different voltages. Current will flow from the higher voltage to the lower one, and if the resistances are low, you'll get a lot of current from even a small difference in voltage.

Some power sources are designed to adjust their output voltage so they can work together. Ideally they'll have connections to make sure they all deliver about the same amount of current to the load. Simple power sources behave exactly the opposite way, so the default assumption is that putting them in parallel Will Be Bad.

bobjunga wrote:Alternatively, do some STEMMA components leave pin 2 unconnected so that they neither supply nor consume power over the STEMMA connector?

You could, but then you'd have to guarantee the board gets its own power. It's more common to make the power connection to the STEMMA connector then leave that wire out the cable if you want to isolate power.

bobjunga wrote:So what are the scenarios where a 3.3V controller will see 5V data lines?

That would be any connection to a 5V I2C device with built-in pull-ups but no level shifting.

bobjunga wrote:Do both controller and devices always implement pullups?

They're an essential part of the level-shifting circuit, so yes.

bobjunga wrote: I would think that controllers should implement pullups but devices that are powered by the STEMMA connector would assume that the data lines are already pulled up by the controller.

That isn't a safe assumption.

Some microcontrollers (like the ESP8266 and ESP32) don't have I2C pull-ups. There are also situations where you create a new I2C interface using pins that weren't allocated for that purpose when the microcontroller board was designed. Having external pull-ups on general-purpose IO pins creates more problems than it solves.

There are also signal propagation issues. Electrical signals move through wire the same way sound waves move through air, and are subject to all the same issues, like echoing (in cables it's called 'ringing'). Resistors at both ends of a wire absorb energy that would otherwise reflect back the way they came.

bobjunga wrote:I would be tempted to leave out the 2 resistors on the output side knowing that they would never be floating because my device needs to be connected to a STEMMA controller for power and the controller providing power would also be pulling up the data lines.

It sounds like you want to use the connector but not the protocol. That's fine, but if you don't need general STEMMA support, you can just ignore the protocol's details.

bobjunga wrote:Its difficult to confirm the polarization of the JST connectors.

All multi-conductor cables have an inherent polarity issue:

Code: Select all | TOGGLE FULL SIZE
    A  B  C  D          D  C  B  A
    |  |  |  |          |  |  |  |
    |  |  |  +----------+  |  |  |
    |  |  +----------------+  |  |
    |  +----------------------+  |
    +----------------------------+
If you want to keep the wires flat and parallel, you need input and output polarities for the connectors. If you want all the connectors to be wired the same way, you have to give the cable a half-twist. When the cable lays flat, the key on the connector at one end will face up and the key at the other end will face down.

bobjunga wrote:That https://github.com/adafruit/Adafruit-QT-Py-RP2040-PCB board seems to not have any level shifting circuit nor does it pull up the data lines.

The QT-Py is compatible with Sparkfun's Qwiic protocol, which doesn't allow 5V signals.

bobjunga wrote:its not clear how the 4 resistor, 2 FET level shifter could be used on the controller side which would typically be providing power on pin 2.

The pull-ups on the device sideof the mosfets always connect to the device's supply voltage, not to the STEMMA V+ pin.

STEMMA devices that run at 3.3V have to put a voltage regulator between the connector and the device to make them 5V-tolerant.

bobjunga wrote:but I wonder if it is a problem to leave the drain pins of the FETs floating in the case that nothing is connected to the STEMMA.

The drains aren't a problem, but the gates are.

The level shifter's circuit always puts the mosfet's gate on the 3.3V side. A 5V device with resistors only on the 5V side would leave the gates of the mosfets floating, and they'd turn on and off at random in response to parasitic currents and static electricity.

The pull-up resistors on the device side of the mosfets connect to the device's positive supply to guarantee the correct I2C voltage for that device. The pull-ups on the connector side of the mosfets connect to the V+ pin to guarantee the correct I2C voltage for the device at the other end of the cable.

Since only one board supplies power on the V+ pin, that board sets the default bus voltage.

bobjunga wrote:When the device drives the line low, the 10K pullup and 1K series resistors would make a voltage divider that would result in my controller seeing about 0.3V which should be low enough to read as a low.

That's only true if there are no other pull-up resistors connected to the SDA and SCL lines. If the board at the other end of the cable has a 4.7k pull-up, the parallel pull-up resistance will be about 3.2k. Pulling the SDA or SCL pins low would pull the line voltage down to about 780mV for a 3.3V bus, and 1.2V for a 5V bus. The same general idea would be true for a bus with multiple I2C devices that all have their own pull-ups (three 10k pull-ups have a parallel resistance of 3.3k).

Except for the protection diode, mosfets are symmetrical: if the gate is connected to 3.3V, connecting the drain to 0V will turn it on just as well as connecting the source to 0V. The circuit we use will pull the SDA and SCL lines down to 0V no matter which side of the connection goes low.

adafruit_support_mike
 
Posts: 62799
Joined: Thu Feb 11, 2010 2:51 pm

Re: 3.3V STEMMA Controller level shifting design

by bobjunga on Mon May 10, 2021 9:32 am

Hi Mike, thanks for the detailed response. It was helpful to me yet the larger question is still unclear. How is it possible to build a controller side STEMMA device that supports both 3.3V and 5V signals. Could it be true that controllers are either 3.3V or 5V and provide power and devices (aka sensors) can be made to work with being connected to either a 3.3V or 5V controller?

Can you point me to git hub pages of an Adfruit board with a STEMMA control connection? -- preferably one that provides 5V on the STEMMA and another that provides 3.3V on the STEMMA?

--BobG

bobjunga
 
Posts: 2
Joined: Thu May 06, 2021 7:44 am

Re: 3.3V STEMMA Controller level shifting design

by adafruit_support_mike on Mon May 10, 2021 9:40 pm

First, there's no requirement for STEMMA control devices to supply power. They can, but it's optional.

Second, there's no requirement for STEMMA control devices to supply more than one voltage. A 5V device can supply 5V power on the V+ pin, but isn't required to support 3.3V as well. A 3.3V device can supply 3.3V power on V+, but isn't required to support 5V as well.

3.3V STEMMA devices that take power from V+ are required to have 3.3V regulators so they can accept 5V on the V+ pin. 5V devices aren't required to operate at all if V+ only has 3.3V.

STEMMA control devices, regardless of whether they operate at 3.3V or 5V, are required to have a level shifter so they can talk to 3.3V or 5V peripheral devices. STEMMA peripheral devices, regardless of whether they operate at 3.3V or 5V, are required to have a level shifter so they can accept I2C signals so they can talk to 3.3V or 5V control devices. In both cases, STEMMA devices should be able to talk to 3.3V or 5V non-STEMMA devices without causing or reeiving any damage.

adafruit_support_mike
 
Posts: 62799
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.