Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

N-MOSFET to NPN Transistor SPI logic shifter

Status
Not open for further replies.

mheruian

Junior Member level 3
Joined
Jan 18, 2018
Messages
31
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
412
Hi Folks,

I'm newbie to electronics and been trying hard to understand what I don't understand, I have a DIY project in school where I have to integrate arduino to an SPI device, I have arduino nano that is 5v while my SPI device that'll be a slave works on 3v3 volts. I don't have other fancy mosfet or logic level shifter ICs, etc. Only transistors and diodes, resistors. I found this one example that works on SPI they said:

lvlshfter.png

I had swap n-mosfet with my 2n3904 npn transistor here and it works like magic where if on HV1, i input logic high / 5v, LV1 produces 3v3 but when I input logic low / 0v on HV1, LV1 produces 1v9.. why is it high? How can I make it < 0v3 value??

also, i would like to ask some silly but technical question. I know how transistors and mosfet works (maybe??) since I used them where when you input high (voltage/current) on base/gate, the voltage/current on collector/drain will flow on emitter/source right? (like a switch)? so how come the 5v on HV1 doesn't flow fully 4 to 5 volt value on LV1 knowing the mosfet/transistor's base/gate is always high? Current chooses low potential path so 5v input on HV1 wont flow on 10k resistors of HV or LV right? How is the "FLOW" works actually in this logic level shifter?

I hope you could help me out. Been brain dead yesterday. Just self studying electronics, not schooling, etc. I don't have any mentor or adviser or someone that has opinion here.
 

It's not possible with a single BJT. NPN with base resistor plus schottky diode could work.
 
Hi FvM,

Thanks a lot. Been doing the said mosfet replacement on transistor and tried not only one but many of them, so logic level shift made of transistors for SPI comm and actually it was horrible just implementing only a single one, then adding other one made it worse, trying four and its a disaster. I really end up looking and buying mosfet and it works like a charm no matter how many I do. Maybe because Transistors are current driven and all this are in common ground.
 

Even if the BJT solution works, you don't get away with less than three parts per channel. So good old BSS138 is surely preferred.
 

Yup :D Thanks a lot FvM, BSS138 are what I want to use but too bad :-( they only have 2n7000 here which is good since these are just for small signals also, perfect for SPI comm
 

BSS138 is better suited by having lower Vth and lower capacitances, but 2N7000 does apparently work for the application.
 
FvM thanks a lot again :D

what Vth?? and capacitances?? on mosfet?
 

Hi Klaus,

Yup, after posting I tried reading it out (hehe) Uhm.. so capacitance of 27pf in and 13pf out, so are this values need to be considered when it comes to switching? like if it has bigger capacitance, turning the mosfet off from on would take a while before completely being off and vice versa??
 

The discussed level shifter circuit is mostly used for I2C, it's speed fits the respective speed requirements.

Using it for SPI, you should talk about the intended speed first as well as consider that there better solutions for unidirectional level shift as required with SPI.
 
Hi FvM

Thanks a lot again :)

ok? If i have a higher speed SPI, i shouldn't use some simple mosfet for level shifting then, some specialized ICs? what specs should I be looking to consider for me to determine that it could be used for faster SPI? lower capacitance??
 

Hi,

some specialized ICs? what specs should I be looking to consider for me to determine that it could be used for faster SPI?
Level shifting has been discussed many times.
Currently in your other thread, too.
Thus the answer is already given.

Klaus
 

I didn't notice the other thread, I agree that 74HCT for 3.3 -> 5V and "overdrivable" CMOS gates for 5 -> 3.3V direction (e.g. 74AHC or 74LVC) is the preferred solution. For low and medium speed, a simple resistor voltage divider (e.g. 1K/2K) can however work for the former case and the previously discussed MOSFET circuit can be sufficient for MISO line. Advantage with Arduino is that you can slow down the SPI if necessary.
 

Hi,

In my eyes the biggest benefit in the above circuit is, that it can work in both directions (as long as your outputs pull properly to GND).
This can not be achieved with standard logic devices.
You need this both_direction_feature with the SDA line of an I2C interface (for full I2C compliance you need it in the SCL line, too)
But you don't need it with SPI. SPI signals are in one direction only.

Klaus
 

Hi,


Level shifting has been discussed many times.
Currently in your other thread, too.
Thus the answer is already given.

Klaus

Hi Mr.Klaus,

thanks a lot again :) yup. Your a big help on the other thread. I actually want to ask other related questions here that is not now related on solving my current problem (since your ideas solves it already)

I didn't notice the other thread, I agree that 74HCT for 3.3 -> 5V and "overdrivable" CMOS gates for 5 -> 3.3V direction (e.g. 74AHC or 74LVC) is the preferred solution. For low and medium speed, a simple resistor voltage divider (e.g. 1K/2K) can however work for the former case and the previously discussed MOSFET circuit can be sufficient for MISO line. Advantage with Arduino is that you can slow down the SPI if necessary.

Hi,

In my eyes the biggest benefit in the above circuit is, that it can work in both directions (as long as your outputs pull properly to GND).
This can not be achieved with standard logic devices.
You need this both_direction_feature with the SDA line of an I2C interface (for full I2C compliance you need it in the SCL line, too)
But you don't need it with SPI. SPI signals are in one direction only.

Klaus

A Great thanks for these two response. Now I'm cleared. going to try out voltage divider on MOSI, SCK then logic shifter on MISO and using AHC devices on slave selects :D
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top