Looking for a clever way to use a 74LS125 as a bidirectional level shifter. - Page 1
Forum section: electronics / projects

author: MarkS
author_rank: Unknown
timestamp: April 10, 2023, 08:49:27 pm
content: I ordered a bunch of these chips after doing a quick Google search, but before actually studying the datasheet, as level shifters for I2C buses. It was only after the order was placed that I realized my error. I do know that I can make a simple bidirectional level shifter for this application with a few resistors and two MOSFETs... NOW... but I have the chips and no FETs.MOSFETs are cheap, yes, but I'd like to get started on this rather simple project I'm working on now. It makes me wonder... What would happen if I drive a buffer in reverse?I know this isn't an idea circuit, but would it work? I need to connect some MCP23017 bus expanders to a TinyS3 to test out some suspect SST39SF040 flash chips I bought off of Amazon. The GPIO pins on the S3 are not 5v tolerant and the flash chips will not run at 3.3v.

author: MarkS
author_rank: Unknown
timestamp: April 10, 2023, 08:54:32 pm
content: Nevermind... Of course this wont work. One side of the buffer is at one voltage and the other side is at the other voltage. Reversing them like this negates the level shifter aspect, even if there is nothing otherwise wrong with the circuit.

author: MarkS
author_rank: Unknown
timestamp: April 10, 2023, 09:53:37 pm
content: In an effort to salvage this post, can two 2N3904s work in place of two MOSFETs, at least for a temporary circuit?

author: Peabody
author_rank: Super Contributor
timestamp: April 10, 2023, 10:17:08 pm
content: To be clear, you would normally use one mosfet per line, so two in total for I2C. I don't think a 2N3904 alone would work, but a 2N3904 and a diode might. The collector would connect to the 5V GPIO and the emitter to the 3.3V GPIO. The base would connect to the 3.3V rail through a resistor. Then the diode would would be across the transistor pointing to the 5V GPIO pin.When the 3.3V pin goes low, that would turn on the transistor, which would ground the 5V pin. But the tricky part is when the 5V pin goes low. It would first drag the emitter kinda low through the diode, but that would be enough to turn on the transistor, and then I think current would flow backwards through the transistor and bring the 3.3V pin all the way to ground. But the diode alone might be enough for it to work, particularly if it's a Schottky, but probably even if it's a 1N4148.No guarantees of course.Edit: Pullup resistors of course on both sides.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 10, 2023, 11:41:52 pm
content: Quote from: MarkS on April 10, 2023, 09:53:37 pmYeah. The attached schematic should work up to 100 kHz, don't expect much faster than this. You can further decrease the pull-up resistors' value to get something faster, obviously at the expense of the power consumption. Conversely, increasing it will make it slower.

author: MarkS
author_rank: Unknown
timestamp: April 11, 2023, 12:08:40 am
content: Quote from: SiliconWizard on April 10, 2023, 11:41:52 pmFor this simple test circuit, even half that would be fine. I don't have an 2.2K, but a bunch of 4.7k. I'll live with the speed decrease for the test.

author: SiliconWizard
author_rank: Super Contributor
timestamp: April 11, 2023, 12:17:28 am
content: Quote from: MarkS on April 11, 2023, 12:08:40 amLet me know how that goes. Attached is the LTSpice file if you want to simulate that. (The two MOSFETs and voltage sources in it are for simulating signals on both sides.)

author: Peabody
author_rank: Super Contributor
timestamp: April 11, 2023, 03:33:31 am
content: SiliconWizard, have you actually used this circuit? It seems to me that when one side goes low, both transistors will turn on, with unpredictable results, particularly when the side that went low tries to go back high. Well, I probably don't understand the circuit, and you are after all a Wizard.

author: MarkS
author_rank: Unknown
timestamp: April 11, 2023, 03:59:16 am
content: Quote from: Peabody on April 11, 2023, 03:33:31 amIt works under LTSpice, but that's not fool proof. I'll breadboard it first. If it works, great, if not, I have 10 BS170 MOSFETs arriving later this week.

author: Zero999
author_rank: Super Contributor
timestamp: April 11, 2023, 07:50:59 am
content: I don't know why the MOSFET shifter is so popular. The problem is the MOSFETs which are available are too big and have too much capacitance to work at and decent speed, with the high value pull-ups required. The same circuit will work with a BJT and an additional base resistor. Only one BJT is required and is much faster as it has less capacitance than two. The BJT has more than enough gain in reverse to allow the capacitance of IO1 to discharge.Level shift bi-direc BJT 3.3V 5V.ascQuote from: MarkS on April 11, 2023, 03:59:16 amUse the BJT version. It's much faster than the MOSFET. If you want to use FETs, than you could use a JFET, with a cut-off voltage of >-3V: gate to 0V and pull-ups to +3.3V and +5V at the drain and source: essentially the same as the MOSFET circuit, but with the gate tied to ground.Quote from: Peabody on April 11, 2023, 03:33:31 amIt will work fine. It's only bidirectional if both outputs are open drain/collector.